Sunday, 8 May 2011

Drag and Drop been blocked / not working in Vista and Windows 7 C++ fix in VS6 (Visual studio 6)

This is a problem with permissions in Vista and Win7 that was introduced with UAC control, there is a workaround but most are using VS2005, 2010 to get around it - to get around it in VS6 call the .dll routine directly by doing below in the startup of your app

Change the startup of your app:-

BOOL C<yourappname>App::InitInstance()
{
 AfxEnableControlContainer();

------------------------------------------------------------------------------
To:-


#define MSGFLT_ADD 1
extern "C" BOOL ( STDAPICALLTYPE *pChangeWindowMessageFilter )( UINT,DWORD ) = NULL;
BOOL C<yourappname>App::InitInstance()
{
 AfxEnableControlContainer();

 // fix drag and drop issue in Windows Vista and Windows 7
HMODULE hMod = 0;

if ( ( hMod = ::LoadLibrary( _T( "user32.dll" ) ) ) != 0 )
{
 pChangeWindowMessageFilter = (BOOL (__stdcall *)( UINT,DWORD ) )::GetProcAddress( hMod, "ChangeWindowMessageFilter" );
}

if ( pChangeWindowMessageFilter )
{
 pChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
 pChangeWindowMessageFilter (WM_COPYDATA, MSGFLT_ADD);
 pChangeWindowMessageFilter (0x0049, MSGFLT_ADD);
}

No comments:

Post a Comment