Click here to Skip to main content
16,016,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello There,
I researched abit about dra and drop and now I have a problem with the message filter of
windows.

basicly I created a MessageProc Callback for handling the droped files as you can see:
C++
bool glob_ret_msgdrop  = false;
bool glob_ret_cpydata = false;
bool glob_ret_49 = false;

LRESULT CALLBACK MsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{	
// 	glob_ret_msgdrop = ChangeWindowMessageFilterEx(hwnd, WM_DROPFILES, MSGFLT_ALLOW, nullptr);
// 	glob_ret_cpydata = ChangeWindowMessageFilterEx(hwnd, WM_COPYDATA, MSGFLT_ALLOW, nullptr);
// 	glob_ret_49 = ChangeWindowMessageFilterEx(hwnd, 0x49, MSGFLT_ALLOW, nullptr);

	switch (uMsg)
	{
	case WM_DROPFILES:
		//DDH_main->OnDropFile(uMsg, wParam, lParam);
		MessageBox(NULL, "droped", "none", NULL);
	}
	return DefWindowProc(hwnd, uMsg, wParam, lParam); 
}


but the WM_DROPFILES case never gets called, means the message box never pops up if
a file gets droped into the exe.

So I researched a bit more and noticed that I have to add the filters for win7 and newer versions.

So I do the following in the main(){} function

C++
//loc_hwnd is filled by GetActiveWindow()
		DragAcceptFiles(loc_hwnd, true);		

		//ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
		//ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
		//ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);

		glob_ret_msgdrop = ChangeWindowMessageFilterEx(loc_hwnd, WM_DROPFILES, MSGFLT_ALLOW, nullptr);
		glob_ret_cpydata = ChangeWindowMessageFilterEx(loc_hwnd, WM_COPYDATA, MSGFLT_ALLOW, nullptr);
		glob_ret_49 = ChangeWindowMessageFilterEx(loc_hwnd, 0x49, MSGFLT_ALLOW, nullptr);


the global booleans return all 1, means it should be a success.

But if I drop something onto my exe , nothing happens.
So what did I miss here ?

,greetings Georg
Posted

 
Share this answer
 
Comments
GAFO 30-Dec-15 14:11pm    
ok, i will check it out, thank you.
edit: there are many exambles out, but even full solutions dont work anymore, i tried a few http://www.catch22.net/tuts/drop-target
i assume all projects worked once, but not anymore, also tried the ready .exe's just to be sure :/ everywhere i read that windows changed alot for security, thatswhy it became so hard -.-
I have a idea which is nearly working:

if I put this into my main function:

C++
DragAcceptFiles(GetActiveWindow(), TRUE);
MSG messages;
MessageBox(NULL, "DragAndDropThread", "", NULL);
while (GetMessage(&messages, NULL, 0, 0))
{
    MessageBox(NULL, "GetMessage", "", NULL);
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
}


it works buggy, but my main-window gets blocked and only paints black, since
it needs to return something to work in the other threads somehow.

thatswhy I tried the following:

C++
BOOL WINAPI MessageNULLLoopThread(LPVOID lpParameter)
{
	HWND curWindow = (HWND)lpParameter;
	DragAcceptFiles(curWindow, TRUE);

	MSG messages;
	MessageBox(NULL, "DragAndDropThread", "", NULL);
	while (GetMessage(&messages, NULL, 0, 0))
	{
	 	MessageBox(NULL, "GetMessage", "", NULL);
	 	/* Translate virtual-key messages into character messages */
	 	TranslateMessage(&messages);
	 	/* Send message to WindowProcedure */
	 	DispatchMessage(&messages);
	}
	
	return TRUE;
}


And I've put the following into my main function:
C++
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MessageNULLLoopThread, GetActiveWindow(), 0, 0);


Its not blocking my main window from rendering then, but in that thread
GetActiveWindow() does not work, so i need to pass it down by lParam...

And the GetMessage loop does not work in the new thread, the debug-messagebox
does not get called once inside the loop.

This is getting realy crazy right now -.-

Why does GetActiveWindow() not work in another thread ? Why is the loop not working
if i put it into a thread ?

But most important: how do I fix this ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900