« on: November 20, 2013, 01:43:06 AM »
Did windows 7 slap your mouse?
Don't let it get you down. This snippet will allow you to enable drag-n-drop in an applications window.
/// @brief Determine if this is running on XP or earlier.
///
/// @returns TRUE if OS is XP or earlier.
static BOOL IsWindowsXPorEarlier(VOID) {
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
return osvi.dwMajorVersion < 6;
}
/// @brief Enable drag-n-drop to a window.
///
/// @par comments:
/// Windows Vista and later versions disable drag-n-drop operations between windows
/// with differing elevaton of priveleges (I guess). This however, can be circumvented
/// if necessary. This method dynamicallys loads the API and changes the permissions
/// for a window (control) if running in Vista or later.
///
/// @param hwnd Handle to the window.
///
/// @returns TRUE if successful otherwise FALSE.
static BOOL EnableDragDrop(HWND hwnd)
{
BOOL fRtn = FALSE;
if(IsWindowsXPorEarlier())
{
fRtn = TRUE; // No need to do anything
}
else// Allow FileDrop (Windows Vista and above)
{
//Dynamic DLL access
typedef BOOL (CALLBACK* PTRFUNC)(HWND,UINT,DWORD,PVOID);
const DWORD WM_COPYGLOBALDATA = 0x0049;
const DWORD MSGFLT_ALLOW = 1;
HMODULE hDll = LoadLibrary(_T("user32.dll"));
if(NULL != hDll)
{
PTRFUNC _ChangeWindowMessageFilterEx;
_ChangeWindowMessageFilterEx = (PTRFUNC)GetProcAddress(hDll,
"ChangeWindowMessageFilterEx");
if(NULL != _ChangeWindowMessageFilterEx)
{
fRtn = _ChangeWindowMessageFilterEx(hwnd, WM_DROPFILES, MSGFLT_ALLOW, NULL);
if(fRtn) fRtn = _ChangeWindowMessageFilterEx(hwnd, WM_COPYDATA , MSGFLT_ALLOW, NULL);
if(fRtn) fRtn = _ChangeWindowMessageFilterEx(hwnd, WM_COPYGLOBALDATA, MSGFLT_ALLOW, NULL);
}
FreeLibrary(hDll);
}
}
return fRtn;
}
« Last Edit: November 20, 2013, 01:44:58 AM by DMac »
Logged
No one cares how much you know,
until they know how much you care.