看VCL源码看呢半天,一个函数跳的另一个,头的发昏,还没找到VCL怎样注册窗口类,创建窗口,显示窗口,还有是Appliation什么时候创建的,VCL里有TAppliation.creat吗?还有TScreen对象是什么时候创建的?注册窗口类的窗口函数是哪个?还有消息循环等等?

解决方案 »

  1.   

    DELPHI和BCB我都找过,不知它的影踪,具体说来它的PROJECT已经完成把它包得象粽子一样了?
      

  2.   

    Appliation,Screen等一些全局变量都是在Controls.pas的initialization
    中创建,如:
    procedure InitControls;
    var
      AtomText: array[0..31] of Char;
    begin
      WindowAtom := GlobalAddAtom(StrFmt(AtomText, 'Delphi%.8X',
        [GetCurrentProcessID]));
      ControlAtom := GlobalAddAtom(
        StrFmt(AtomText, 'ControlOfs%.8X%.8X', [HInstance, GetCurrentThreadID]));
      CanvasList := TThreadList.Create;
      InitIMM32;
      Mouse := TMouse.Create;
      Screen := TScreen.Create(nil);
      Application := TApplication.Create(nil);
      InitCtl3D;
      Application.ShowHint := True;
      RegisterIntegerConsts(TypeInfo(TCursor), IdentToCursor, CursorToIdent);
    end;initialization
      NewStyleControls := Lo(GetVersion) >= 4;
      InitControls;在TWinControl.CreateWnd中注册窗口类和创建窗口,如:
    procedure TWinControl.CreateWnd;
    var
      Params: TCreateParams;
      TempClass: TWndClass;
      ClassRegistered: Boolean;
    begin
      CreateParams(Params);
      with Params do
      begin
        if (WndParent = 0) and (Style and WS_CHILD <> 0) then
          if (Owner <> nil) and (csReading in Owner.ComponentState) and
            (Owner is TWinControl) then
            WndParent := TWinControl(Owner).Handle
          else
            raise EInvalidOperation.CreateFmt(SParentRequired, [Name]);
        FDefWndProc := WindowClass.lpfnWndProc;
        ClassRegistered := GetClassInfo(WindowClass.hInstance, WinClassName, TempClass);
        if not ClassRegistered or (TempClass.lpfnWndProc <> @InitWndProc) then
        begin
          if ClassRegistered then Windows.UnregisterClass(WinClassName,
            WindowClass.hInstance);
          WindowClass.lpfnWndProc := @InitWndProc;
          WindowClass.lpszClassName := WinClassName;
          if Windows.RegisterClass(WindowClass) = 0 then RaiseLastWin32Error;
        end;
        CreationControl := Self;
        CreateWindowHandle(Params);
        if FHandle = 0 then RaiseLastWin32Error;
      end;
      StrDispose(FText);
      FText := nil;
      UpdateBounds;
      Perform(WM_SETFONT, FFont.Handle, 1);
      if AutoSize then AdjustSize;
    end;注册窗口类的窗口函数是InitWndProc,如:
    { Initialization window procedure }function InitWndProc(HWindow: HWnd; Message, WParam,
      LParam: Longint): Longint;
    begin
      CreationControl.FHandle := HWindow;
      SetWindowLong(HWindow, GWL_WNDPROC,
        Longint(CreationControl.FObjectInstance));
      if (GetWindowLong(HWindow, GWL_STYLE) and WS_CHILD <> 0) and
        (GetWindowLong(HWindow, GWL_ID) = 0) then
        SetWindowLong(HWindow, GWL_ID, HWindow);
      SetProp(HWindow, MakeIntAtom(ControlAtom), THandle(CreationControl));
      SetProp(HWindow, MakeIntAtom(WindowAtom), THandle(CreationControl));
      asm
            PUSH    LParam
            PUSH    WParam
            PUSH    Message
            PUSH    HWindow
            MOV     EAX,CreationControl
            MOV     CreationControl,0
            CALL    [EAX].TWinControl.FObjectInstance
            MOV     Result,EAX
      end;
    end;消息循环是从StdWndProc函数开始的,如:
    { Standard window procedure }
    { In    ECX = Address of method pointer }
    { Out   EAX = Result }function StdWndProc(Window: HWND; Message, WParam: Longint;
      LParam: Longint): Longint; stdcall; assembler;
    asm
            XOR     EAX,EAX
            PUSH    EAX
            PUSH    LParam
            PUSH    WParam
            PUSH    Message
            MOV     EDX,ESP
            MOV     EAX,[ECX].Longint[4]
            CALL    [ECX].Pointer
            ADD     ESP,12
            POP     EAX
    end;
      

  3.   

    那么初始化initializat是在那里调用的?是在窗体的creatform函数中调用的吗?
    消息循环呢?
      

  4.   

    应该是application.run开始消息循环
      

  5.   

    建议自己看一下,打开工程文件(确省的是什么什么PROJECT1之类的东西),按住CTRL,鼠标点一下applicaiton,跳到了
      Application: TApplication;同样的方法追踪TAPPLICATION,可以跳到TAPPLICATION的定义处你回看到好多的东西,象:
    WNDPROC,RUN,PROCESSMESSAGE,CREATEFORM等等,你会看出一些门道的。