我想在两个程序之间通过消息通信,消息的类型是WM_MYMSG = WM_USER+200
程序1中有个按钮发送PostMessage(HWND_BROADCAST,WM_MYMSG,0,0);
程序2中procedure AppMessage(var Msg: TMessage);message WM_MYMSG;
Procedure TForm1.AppMessage(var Msg: TMessage);
begin
    ShowMessage('Receive Message');
end;
但是这样好象没收到WM_MYMSG这个消息,不知道该怎么弄,请教一下

解决方案 »

  1.   

    如果你直接发送消息给你接收窗口这样做没问题。
    如果发送广播消息,需要注册消息才行的。
    看帮助:
    Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
      

  2.   

    RegisterWindowMessage的帮助:
    The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The returned message value can be used when calling the SendMessage or PostMessage function. UINT RegisterWindowMessage(    LPCTSTR lpString  // address of message string
       );
     ParameterslpStringPoints to a null-terminated string that specifies the message to be registered.  Return ValuesIf the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
    If the function fails, the return value is zero. ResThe RegisterWindowMessage function is typically used to register messages for communicating between two cooperating applications. 
    If two different applications register the same message string, the applications return the same message value. The message remains registered until the Windows session ends. 
    Only use RegisterWindowMessage when more than one application must process the same message. For sending private messages within a window class, an application can use any integer in the range WM_USER through 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)