首页 > 代码库 > win7下万能跨进程PostMessage/SendMessage
win7下万能跨进程PostMessage/SendMessage
typedef BOOL (WINAPI *_ChangeWindowMessageFilter)( UINT , DWORD); BOOL AllowMeesageForWin7(UINT uMessageID, BOOL bAllow)//注册Win7全局消息 { BOOL bResult = FALSE; HMODULE hUserMod = NULL; hUserMod = LoadLibrary( _T("user32.dll") ); if( NULL == hUserMod ) { return FALSE; } do { _ChangeWindowMessageFilter pChangeWindowMessageFilter = (_ChangeWindowMessageFilter)GetProcAddress( hUserMod, "ChangeWindowMessageFilter" ); if( NULL == pChangeWindowMessageFilter ) { AfxMessageBox(_T("create windowmessage filter failed")); break; } bResult = pChangeWindowMessageFilter( uMessageID, bAllow ? 1 : 2 );//MSGFLT_ADD: 1, MSGFLT_REMOVE: 2 }while (0); if( NULL != hUserMod ) { FreeLibrary( hUserMod ); } return bResult; }BOOL IsVistaOrLater(){ OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); if( osvi.dwMajorVersion >= 6 ) return TRUE; return FALSE;}
简单使用:
if (IsVistaOrLater()) { if ( !AllowMeesageForWin7(0xAAA,TRUE) || !AllowMeesageForWin7(0xBBB,TRUE) ) { MessageBox("注册消息失败.","发生错误!",0); return FALSE; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。