利用FindWindow函数,分别查找TApplication、TAlignPalette、TPropertyInspector、TAppBuilder
这四个窗口,当查出这四个窗口,表明在IDE下,否则不在IDE环境下运行。只要在应用程序的适当位
置加入以下函数
(Function DelphiIsRunning: Boolean
即可。
Function DelphiIsRunning: Boolean;
Const
A1: Array[0..12] of char = 'TApplication'#0;
A2: Array[0..15] of char = 'TAlignPalette'#0;
A3: Array[0..18] of char = 'TPropertyInspector'#0;
A4: Array[0..11] of char = 'TAppBuilder'#0;
{$ifdef VER120}
T1: Array[0..8] of char = 'Delphi 4'#0;
{$endif}
{$ifdef VER100}
T1: Array[0..8] of char = 'Delphi 3'#0;
{$endif}
{$ifdef VER90}
T1: Array[0..10] of char = 'Delphi 2.0'#0;
{$endif}
{$ifdef VER80}
T1: Array[0..6] of char = 'Delphi'#0;
{$endif}
begin
result := (FindWindow(A1, T1) <> 0) and (FindWindow(A2, Nil) <> 0) and
(FindWindow(A3, Nil) <> 0) and (FindWindow(A4, Nil) <> 0);
if not result then
{当应用程序不在IDE环境下运行时,显示一段信息。}
Application.MessageBox('不在IDE环境下');
end;
{ DelphiIsRunning }