Simulate Delphi running  

Send By: Christian Engstfeld
Web : www.PlanetSoftware.8k.com
Email: Christian.Engstfeld@inworx.com.ar
Date: 27/02/03

Tip accessed 2616 times

 


Will you wonder and for what reason does this serve?. Good, is an unit that it simulates the windows that Delphi makes simply when it is being executed. The mission is the one of tricking to those components that only work with the IDE of started up Delphi (good, it will only tricks some...)
A possible detection function of the Delphi's IDE could be something like that:


 function IsDelphiRunning : boolean;
 begin
   Result := (FindWindow('TAppBuilder',nil) > 0) and
             (FindWindow('TPropertyInspector',nil) > 0) and
             (FindWindow('TAlignPalette',nil) > 0);
 end;



Of course... it could not also be this way and not to work the invention...

For use it, simply add the following unit in your 'uses' line


 {
 ***************************************************************************
 DSim 1.2  Simulacion de la ejecucion de Delphi
 Copyright (C) 2001 Antarlac Software
 ****************************************************************************
 }

 unit DSim;

 interface


 implementation

 uses Windows;

 const

   AppBuilderWindowClass :TWndClass =
   (
     style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TAppBuilder'
   );

   PropertyInspectorWindowClass :TWndClass =
   (
     style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TPropertyInspector'
   );

   AlignPaletteWindowClass :TWndClass =
   (
     style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TAlignPalette'
   );

 var
   AppBuilderHWND :HWND;
   PropertyInspectorHWND :HWND;
   AlignPaletteHWND :HWND;


 initialization

   { TAppBuilder }
   if FindWindow(AppBuilderWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(AppBuilderWindowClass);
     AppBuilderHWND := CreateWindowEx(0, AppBuilderWindowClass.lpszClassName,

                                      '', 0, 0, 0, 0, 0, 0, 0, HInstance,
 NIL);
   end;
   { TPropertyInspector }
   if FindWindow(PropertyInspectorWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(PropertyInspectorWindowClass);
     PropertyInspectorHWND := CreateWindowEx(0,
 PropertyInspectorWindowClass.lpszClassName,
                                             '', 0, 0, 0, 0, 0, 0, 0,
 HInstance, NIL);
   end;
   { TAlignPalette }
   if FindWindow(AlignPaletteWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(AlignPaletteWindowClass);
     AlignPaletteHWND := CreateWindowEx(0,
 AlignPaletteWindowClass.lpszClassName,
                                        '', 0, 0, 0, 0, 0, 0, 0, HInstance,
 NIL);
   end;


 finalization

   { TAppBuilder }
   UnregisterClass(AppBuilderWindowClass.lpszClassName, HInstance);
   if AppBuilderHWND <> 0 then
     DestroyWindow(AppBuilderHWND);
   { TPropertyInspector }
   UnregisterClass(PropertyInspectorWindowClass.lpszClassName, HInstance);
   if PropertyInspectorHWND <> 0 then
     DestroyWindow(PropertyInspectorHWND);
   { TAlignPalette }
   UnregisterClass(AlignPaletteWindowClass.lpszClassName, HInstance);
   if AlignPaletteHWND <> 0 then
     DestroyWindow(AlignPaletteHWND);

 end.




Sent by: René Lemus Morales (rlemus@esimtz.co.cu)



 unit DSim;

 interface


 implementation

 uses Windows;

 const

   AppBuilderWindowClass :TWndClass =
   ( style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TAppBuilder'  );

   PropertyInspectorWindowClass :TWndClass =
   ( style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TPropertyInspector'  );

   AlignPaletteWindowClass :TWndClass =
   ( style :0;
     lpfnWndProc :@DefWindowProc;
     cbClsExtra :0;
     cbWndExtra :0;
     hInstance :0;
     hIcon :0;
     hCursor :0;
     hbrBackground :0;
     lpszMenuName :NIL;
     lpszClassName :'TAlignPalette'  );

 var
   AppBuilderHWND :HWND;
   PropertyInspectorHWND :HWND;
   AlignPaletteHWND :HWND;


 initialization

   { TAppBuilder }
   if FindWindow(AppBuilderWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(AppBuilderWindowClass);
     AppBuilderHWND := CreateWindowEx(0, AppBuilderWindowClass.lpszClassName,PChar('Delphi 5'), 0, 0, 0, 0, 0, 0, 0, HInstance,NIL);
   end;

   { TPropertyInspector }
   if FindWindow(PropertyInspectorWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(PropertyInspectorWindowClass);
     PropertyInspectorHWND := CreateWindowEx(0,PropertyInspectorWindowClass.lpszClassName,PChar('Object Inspector'), 0, 0, 0, 0, 0, 0, 0,HInstance, NIL);
   end;

 { TAlignPalette }
   if FindWindow(AlignPaletteWindowClass.lpszClassName,NIL) = 0 then
   begin
     RegisterClass(AlignPaletteWindowClass);
     AlignPaletteHWND := CreateWindowEx(0,AlignPaletteWindowClass.lpszClassName,PChar('Align'), 0, 0, 0, 0, 0, 0, 0, HInstance,NIL);
   end;


 finalization

   { TAppBuilder }
   UnregisterClass(AppBuilderWindowClass.lpszClassName, HInstance);
   if AppBuilderHWND <> 0 then
     DestroyWindow(AppBuilderHWND);
   { TPropertyInspector }
   UnregisterClass(PropertyInspectorWindowClass.lpszClassName, HInstance);
   if PropertyInspectorHWND <> 0 then
     DestroyWindow(PropertyInspectorHWND);
   { TAlignPalette }
   UnregisterClass(AlignPaletteWindowClass.lpszClassName, HInstance);
   if AlignPaletteHWND <> 0 then
     DestroyWindow(AlignPaletteHWND);

 end.





Sent by Arturo Garcia (27/02/2003)
*EEn primer lugar creamos una ventana cuya clase se llamara igual a la del IDE para ello solo usaremos la API de windows.


 program IDE;
 uses  messages,windows;

 var
   wclass1: twndclass;
   Hinst,handle:HWND;
   msg: tmsg;

 // procedimiento de salida equivalente al tipico OnClose de TForm.

 procedure ShutDown;
 begin
   Windows.UnRegisterClass(wclass1.lpszClassName,hInst);
   ExitProcess(hInst);
 end;

 // el procedimiento de ventana en el entran los mensajes y se procesan

 function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
 begin
   Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
   case Msg of
         WM_DESTROY: ShutDown;
   end;
 end;

 // comienzo

 begin
  hInst:=GetModuleHandle(nil);
  with wClass1 do
   begin
     Style:=CS_PARENTDC;
     hIcon:=LoadIcon(hInst,'MAINICON');
     lpfnWndProc:=@WindowProc;
     hInstance:= hInst;
     hbrBackground:=COLOR_BTNFACE+1;
     lpszClassName:='TAppBuilder';
     hCursor:=LoadCursor(0,IDC_ARROW);
   end;
    windows.RegisterClass(wClass1);
    Handle:=CreateWindow('TAppBuilder','Simulando el IDE de Delphi',
                       WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or
 WS_MINIMIZEBOX or WS_VISIBLE,
                       10,10,350,124,0,0,hInst,nil);

 // ciclo de mensajes

  while (GetMessage(Msg,Handle,0,0)) do
   begin
     TranslateMessage(Msg);
     DispatchMessage(Msg);
   end;
 end.




 unit Skeleton;

 interface

 uses
   Windows, Messages, Dialogs,Classes;

 type
   TSkeleton = class(TComponent)
   private

   protected
     procedure loaded;Override;
   public

   published

   end;

 procedure Register;

 implementation

 var
  FPID:WORD;

 procedure Register;
 begin
   RegisterComponents('Samples', [TSkeleton]);
 end;

 procedure TSKeleton.loaded;
 begin
  inherited;
  if  (csDesigning in ComponentState) then exit;
  If FPID=0 Then begin
                   ShowMessage('Lo siento pero solo funciono con el IDE
 de Delphi!');
                   HALT;
 end;             end;

 Initialization
 begin
  GetWindowThreadProcessId(FindWindow('TAppBuilder', nil),@FPID);
 end;

 end.