zoukankan      html  css  js  c++  java
  • 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;
            }
        }
  • 相关阅读:
    浅谈流形学习
    变分例子
    变分
    基于深度学习的目标检测技术演进:R-CNN、Fast R-CNN,Faster R-CNN
    模拟退火
    粒子群算法
    JavaEE Tutorials (24)
    洛谷 P2026 求一次函数解析式
    洛谷 P1598 垂直柱状图
    洛谷 P1781 宇宙总统
  • 原文地址:https://www.cnblogs.com/pugna/p/3790877.html
Copyright © 2011-2022 走看看