首页 > Windows开发 > 详细

win7下万能跨进程PostMessage/SendMessage

时间:2014-06-18 18:10:17      阅读:883      评论:0      收藏:0      [点我收藏+]
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;
        }
    }

 

win7下万能跨进程PostMessage/SendMessage,布布扣,bubuko.com

win7下万能跨进程PostMessage/SendMessage

原文:http://www.cnblogs.com/pugna/p/3790877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!