2.实现代码 1: //Define a unique const string to create the broadcast message 2: //We can use the GuidGen tool to make sure this string is a unique one 3: const static LPCTSTR g_AciveMsgName = _T("DBCAAC01-2744-43EE-9FFC-7CD41C672842"); 4: 5: //Generate a broadcast message 6: UINT broadcastMsg = ::RegisterWindowMessage(g_AciveMsgName); 7: 8: //Broadcast message 9: ::PostMessage(HWND_BROADCAST,broadcastMsg,0,0); 10: 11: //Receive and process this message,if the receiver is a different app instance,it need 12: //also to call the ::RegisterWindowMessage(g_AciveMsgName) API to get the message code 13: //NOTE:This message code is assotiated with the global unique string(g_AciveMsgName) 14: //and it's allocated by the windows system 15: BEGIN_MESSAGE_MAP(...) 16: //...... 17: ON_REGISTERED_MESSAGE(s_WM_ACTIVEWND,OnActiveWnd) 18: //...... 19: END_MESSAGE_MAP() 20: 21: void CDlg::OnActiveWnd() 22: { 23: // Do something to response this broadcasted message 24: //...... 25: }