导航

WTL在Win8.1系统WM_DROPFILES无法响应的解决办法

Posted on 2014-07-11 10:55  ggzone  阅读(187)  评论(0编辑  收藏  举报

由于UAC的限制,WM_DROPFILES只能由权限较低的APP拖拽到权限较高的APP,反之如果从权限较高的APP拖拽到低权限的APP上,WM_DROPFILES不会被发送到低权限的APP消息队列。所以,WM_DROPFILES会有时候变得不能响应。

解决的办法,使用ChangeWindowMessageFilter注册WM_DROPFILES这个MEESSAGE。

 

ChangeWindowMessageFilter是Vista以后的一个API,WinXP下并没有。

这个API在User32.dll中,使用时LoadLibrary,GetProcAddress得到函数地址就能使用。

1、在你的程序中添加以下函数:

//register global messages for vista win7 win8.1
typedef BOOL(WINAPI *_ChangeWindowMessageFilter)(UINT message, DWORD dwFlag);.
BOOL AllowMeesageForVistaAbove(UINT uMessageID, BOOL bAllow)
{
    BOOL bResult = FALSE;
    HMODULE hUserMod = NULL;
    //vista and later
    hUserMod = LoadLibrary(_T("user32.dll"));
    if( NULL == hUserMod )
    {
        return FALSE;
    }
   
    _ChangeWindowMessageFilter pChangeWindowMessageFilter =
        (_ChangeWindowMessageFilter)GetProcAddress( hUserMod, "ChangeWindowMessageFilter");
    if( NULL == pChangeWindowMessageFilter )
    {
        return FALSE;
    }
    bResult = pChangeWindowMessageFilter( uMessageID, bAllow ? 1 : 2 );//MSGFLT_ADD: 1, MSGFLT_REMOVE: 2
   
    if( NULL != hUserMod )
    {
        FreeLibrary( hUserMod );
    }

    return bResult;
} 
2、头文件定义以下宏 :

#define MSGFLT_ADD 1

#define MSGFLT_REMOVE 2

3、在OnInitDialog中添加函数调用:

AllowMeesageForVistaAbove(SPI_SETANIMATION, MSGFLT_ADD);

//allow drop files
AllowMeesageForVistaAbove(WM_DROPFILES, MSGFLT_ADD);