Application.handle是应用程序的句柄,Application.MainForm.Handle是窗体的句柄,当然不同了。

解决方案 »

  1.   

    对,你可以观察oicq的句柄,每个窗口不同的,但是application的句柄是唯一的。
      

  2.   

    push again!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  3.   

    1.对
    2.看RegisterClass的声明
    function RegisterClass(const lpWndClass: TWndClass): ATOM; stdcall;
    这种参数传的其实就是lpWndClass的地址
    并且不允许改变
    也就相当于CONST WNDCLASS *lpWndClass;
    传变量就行了,而你传@WndClass
    相当于
    function RegisterClass(lpWndClass: ^TWndClass): ATOM; stdcall;
    与windows中的RegisterClass的参数类型不符
    3.应该好使吧
    回家试试
      

  4.   

    我回答第一个问题:首先 TApplication = class(TComponent)分析Source可以看到:
    procedure TApplication.CreateHandle;
    var
      TempClass: TWndClass;
      SysMenu: HMenu;
    begin
     ....FHandle就是Application.Handle
       FHandle := CreateWindow(WindowClass.lpszClassName, PChar(FTitle),
          WS_POPUP or WS_CAPTION or WS_CLIPSIBLINGS or WS_SYSMENU
          or WS_MINIMIZEBOX,
          GetSystemMetrics(SM_CXSCREEN) div 2,
          GetSystemMetrics(SM_CYSCREEN) div 2,
          0, 0, 0, 0, HInstance, nil); //呵呵,都为0,你看不到了吧!!!
     。。
    end;
    Delphi帮助对Application的说明为:
    ///////////////////////////////////
    Provides access to the window handle of the main form (window) of the application.
      property Handle: HWND;
    /////////////////////////////
    我想它所说的Window就是上面的那个窗体!
      

  5.   

    3.
    这样吧,不用with, 什么原因我不知道
        wc.style := 0;
        wc.lpfnwndproc := @wndproc;
        wc.cbclsextra := 0;
        wc.cbwndextra := 0;
        wc.hicon := 0;
        wc.hcursor := 0;
        wc.hbrbackground :=COLOR_BACKGROUND;//di2001.jpg;
        wc.lpszmenuname := nil;
        wc.lpszclassname := 'mytrayiconclass';
        wc.hinstance := {system.}Hinstance;
    另外同意lixiaolei,Application.Handle是一隐藏窗口的句柄
    用  SetWindowPos(Application.Handle, 0, 20, 20, 200, 200, SWP_SHOWWINDOW);
    可以看到
      

  6.   

    谢谢lixiaolei(快乐)的仔细分析。
    这么说Application另有一个隐藏的窗体,可能是用来设置消息循环的的吧?而且它与应用程序的主窗体不是同一个,是不是这样呢?应用程序的消息循环不是那个我们第一个创建的窗体Form1,或者那个在project|option里设置的主窗体,而是这个隐藏的窗体,你说对吗?
    也非常感谢xzgyb(老达摩),我这就去试试。对了,我用getlasterror看到出错信息号是1407,就是“找不到窗口类”,怎么回事?
      

  7.   

    对了,还要请教一下xzgyb(老达摩) 
    你说,看RegisterClass的声明
    function RegisterClass(const lpWndClass: TWndClass): ATOM; stdcall;
    这种参数传的其实就是lpWndClass的地址。
    可参数说明里没有var关键字啊,书上也没看到过啊,你在哪里看到的呢?另外,我在delphi的IDE里调用API函数时,写完函数名再写一个左括弧,IDE会自动提示函数参数信息,这本来挺好的,可是如果我用一个结构(记录)类型的变量作参数的话,IDE就只是显示函数的参数信息,而不会在我的记录型变量的“.”符号右边把记录的域列表显示出来(类类型的变量也是如此),除非我在屏幕别的地方点击一下鼠标,使函数参数信息消失,这时才会显示那个列表,可函数的参数信息又没了,这可怎么办?可以再显示出来吗?VC++里是可以再显示的,不知delphi也可以吗? 
      

  8.   

    GetLastError好像就是with 的那个事,注册类就没注册上
    看一下帮助,const与var类似,只是const参数不允许改
    A constant (const) parameter is like a local constant or read-only variable. Constant parameters are similar to value parameters, except that you can抰 assign a value to a constant parameter within the body of a procedure or function, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object抯 properties.)
    Using const allows the compiler to optimize code for structured- and string-type parameters. It also provides a safeguard against unintentionally passing a parameter by reference to another routine.Here, for example, is the header for the CompareStr function in the SysUtils unit:function CompareStr(const S1, S2: string): Integer;Because S1 and S2 are not modified in the body of CompareStr, they can be declared as constant parameters.Ctrl+Shift+空格可以在显示出来
      

  9.   

    谢谢xzgyb(老达摩)   :)
      

  10.   

    请问xzgyb(老达摩),你的E_MAIL可以告诉我吗?希望以后可以继续请教。谢谢!
      

  11.   

    [email protected]
    一起学习吧
    呵呵
      

  12.   

    hinstance := SysInit.Hinstance;
      

  13.   

    xzgyb(老达摩) 
    我的E_MAIL    [email protected],以后请多多指教。
    lixiaolei(快乐)
    对,但是省去前缀也行。