cout << "Hello World!" << endl; // 张鲁夺 :: 个人博客,幸福着你的幸福!


关于Vista/Windows 7/Windows 8系统中WM_DROPFILES消息的处理

作者:鲁夺,2015年9月28日,原创文章,转载请注明出处!

原文:http://zhangluduo.com/article/c7efb269/



BOOL Is_Vista_Win7_Win8()
{
    OSVERSIONINFOEX verinfo;
    ZeroMemory(&verinfo, sizeof(OSVERSIONINFOEX));
    verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

    if (!GetVersionEx((LPOSVERSIONINFO)(&verinfo)))
        return FALSE;

    if (
        (verinfo.dwMajorVersion ==6 && verinfo.dwMinorVersion == 0) || // Vista
        (verinfo.dwMajorVersion ==6 && verinfo.dwMinorVersion == 1) || // Windows 7
        (verinfo.dwMajorVersion ==6 && verinfo.dwMinorVersion == 2) || // Windows 8
        (verinfo.dwMajorVersion ==6 && verinfo.dwMinorVersion == 3)    // Windows 8.1
    )
        return TRUE;

    return FALSE;
}


if (Is_Vista_Win7_Win8())
{
    HMODULE hModule = LoadLibrary("user32.dll");

    typedef BOOL (WINAPI* PFN_ChangeWindowMessageFilter)(UINT message, DWORD dwFlag);

    if (hModule)
    {
        PFN_ChangeWindowMessageFilter pfnChangeWindowMessageFilter = 
            (PFN_ChangeWindowMessageFilter)GetProcAddress(hModule, "ChangeWindowMessageFilter");

        #define MSGFLT_ADD 1
        #define MSGFLT_REMOVE 2
        #define WM_COPYGLOBALDATA 0x0049

        if (pfnChangeWindowMessageFilter)
        {
            // 只加一条WM_DROPFILES是不行的, 后面两个消息也要加上
            pfnChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
            pfnChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
            pfnChangeWindowMessageFilter(WM_COPYGLOBALDATA , MSGFLT_ADD);
        }

        FreeLibrary(hModule);
    }
}

Copyright © 2015 Zhang Luduo.

All rights reserved.