当用户自定义消息时,消息处理函数也定义好了,可是windows怎么知道什么时候触发该消息,调用该函数呢?怎么知道的呢,它又不是系统自带的?怎么知道的呢?

解决方案 »

  1.   

    The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. LRESULT SendMessage(    HWND hWnd, // handle of destination window
        UINT Msg, // message to send
        WPARAM wParam, // first message parameter
        LPARAM lParam  // second message parameter
       );
     ParametershWndIdentifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows. MsgSpecifies the message to be sent. wParamSpecifies additional message-specific information. lParamSpecifies additional message-specific information.  Return ValuesThe return value specifies the result of the message processing and depends on the message sent.
      

  2.   

    给一个例子吧:
      private
        { Private declarations }
        procedure MouseMessage(var Message: tMessage); message MouseMsg;//MouseMsg为你要处理的消息类型procedure TForm1.MouseMessage(var Message: TMessage);
    begin
    //处理代码
    end;
      

  3.   

    private
    procedure mousemessage(var message: tmessage); message MouseMsg;
        //Message 后添加你要处理的消息类型procedure mousemessage(var message: tmessage); message MouseMsg;
    begin
    //你要处理的代码
    end;
      

  4.   

    每个Application有一个消息队列的,可以分发消息给具体的窗口,不同的message触发不同事件。
    具体可以看看开发人员指南上,专门有一章讲消息的~
      

  5.   

    当用户自定义消息时,消息处理函数也定义好了,可是windows怎么知道什么时候触发该消息,调用该函数呢?怎么知道的呢,它又不是系统自带的?怎么知道的呢?
    使用SendMessage PostMessage等 自己给他发送消息
      

  6.   

    sendmessage由 user.dll模块调用窗口处理函数,postmessage只是简单的把消息扔到应用程序消息队列里,再由dispatchmessage传给user.dll,由 user.dll模块调用窗口处理函数,这就称为回调函数。即自己编函数,由系统调用。
    原因是系统还有些消息要发给窗口处理函数。可参见windows程序设计方面的书。
      

  7.   

    自己定义好用户自定义消息
    需要处理消息时,通过SendMessage或PostMessage触发消息
    如:CONST WM_OVER=WM_USER+$1000
    SendMessage(frmmain.Handle,WM_OVER,0,0)