zoukankan      html  css  js  c++  java
  • RegisterWindowMessage

    RegisterWindowMessage function

     

    Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.

    Syntax

     
    UINT WINAPI RegisterWindowMessage(
      _In_  LPCTSTR lpString
    );
    
    

    Parameters

    lpString [in]

    Type: LPCTSTR

    The message to be registered.

    Return value

    Type:

    Type: UINT

    If 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. To get extended error information, call GetLastError.

    Remarks

    The 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 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_USERthrough 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTONEDITLISTBOX, and COMBOBOX may use values in this range.)

    Samples:

    1.sender

    static UINT sBroadcastCommand = ::RegisterWindowMessage( _T("BroadcastCommand"));
    
    int _tmain(int argc, _TCHAR* argv[])
    {    
    
        ::PostMessage( (HWND)HWND_BROADCAST, sBroadcastCommand, 111 ,    233 );
        
        return 0;
    }

    2.receiver

    static UINT UM_BROADCAST_CMD = ::RegisterWindowMessage( _T("BroadcastCommand")); 
    
    BEGIN_MESSAGE_MAP(Ctest_receive_broadcastmsgDlg, CDialog)
        ON_WM_SYSCOMMAND()
        ON_REGISTERED_MESSAGE(UM_BROADCAST_CMD, OnBroadcastCommand)
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    // Ctest_receive_broadcastmsgDlg message handlers
    
    LRESULT Ctest_receive_broadcastmsgDlg::OnBroadcastCommand(WPARAM wParam, LPARAM lParam)
    {
        printf("OnBroadcastCommand: %d  , %d  
    ", wParam, lParam);
    
        return S_OK;
    }

    3.console application receiver test failed.

    int _tmain(int argc, _TCHAR* argv[])
    {
    
        DWORD pid = GetCurrentProcessId();   
        DWORD tid = GetCurrentThreadId();   
    
    UINT UM_BROADCAST_CMD = ::RegisterWindowMessage( _T("BroadcastCommand"));  UINT msgSigInt
    = RegisterWindowMessage((LPCWSTR)"SIGINT"); UINT msgSigTerm = RegisterWindowMessage((LPCWSTR)"SIGTERM"); MSG msg;/* Make a message queue -- this is the method suggested by MS */ //PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); printf("My process id: %d ", pid); printf("My thread id: %d ", tid); printf("SIGINT message id: %d ", msgSigInt); printf("SIGTERM message id: %d ", msgSigTerm); printf("Entering loop... "); fflush(stdout); while (GetMessage(&msg, NULL, 0, 0)) { printf("Received message: %d ", msg.message); if (msg.message == msgSigInt) { printf("SIGINT received, continuing. "); } else if (msg.message == msgSigTerm) { printf("SIGTERM received, continuing. "); } else if (msg.message == UM_BROADCAST_CMD) { ////////////////////////////////////////////////////////////////////////// //HWND_BROADCAST:消息被寄送到系统的所有顶层窗口,包括无效或不可见的非自身拥有的窗口、 被覆盖的窗口和弹出式窗口。消息不被寄送到子窗口 //导致失败。。。。。。。。。。。。。。。。。控制台接收不到。 printf("sBroadcastCommand received, continuing %d:%d. ", msg.wParam, msg.lParam); } fflush(stdout); } printf("Exiting. "); fflush(stdout); return 0; }

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms644947(v=vs.85).aspx

  • 相关阅读:
    语言精粹【摘要】
    【转】一个Java程序员应该掌握的10项技能
    比较有用的网址
    推荐一些国内的Jquery CDN免费服务
    CSS3动画【归纳总结】
    scrollTo与border结合使用的小玩意
    aria-label及aria-labelledby应用//////////[信息无障碍产品联盟]
    aria初探(一)
    没有this的JavaScript
    Front-end Job Interview Questions
  • 原文地址:https://www.cnblogs.com/iclk/p/3560049.html
Copyright © 2011-2022 走看看