拖放非MFC,c ++ [英] Drag and Drop in non MFC, c++

查看:131
本文介绍了拖放非MFC,c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我研究了关于dra和drop的abit,现在我对

windows的消息过滤器有问题。



基本上我创建了一个MessageProc Callback来处理droped文件,如你所见:

  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)
{
// < span class =code-comment> 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 non e,NULL);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}





但WM_DROPFILES案例永远不会被调用,意味着如果
$ b,消息框永远不会弹出$ ba文件被下载到exe中。



所以我研究了一下,注意到我必须为win7和更新版本添加过滤器。



所以我在main(){}函数中执行以下操作



 < span class =code-comment> //   loc_hwnd由GetActiveWindow()填充 
DragAcceptFiles(loc_hwnd,);

// ChangeWindowMessageFilter(WM_DROPFILES,MSGFLT_ADD);
< span class =code-comment> //
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 );





全球布尔值全部返回1,意味着它应该是成功的。



但是如果我把一些东西放到我的exe上,没有任何反应。

那么我在这里想念的是什么?



,问候Georg

解决方案

你应该学习处理Shell数据传输方案(Windows) [ ^ ]。


我有一个近乎工作的想法:



如果我将它放入我的主要功能:



 DragAcceptFiles(GetActiveWindow(),TRUE); 
MSG消息;
MessageBox(NULL, DragAndDropThread ,NULL);
while (GetMessage(& messages,NULL, 0 0 ))
{
MessageBox(NULL, GetMessage ,NULL);
/ * 将虚拟密钥消息转换为字符消息* /
TranslateMessage( &安培;消息);
/ * 发送消息给WindowProcedure * /
DispatchMessage(& messages) ;
}





它有效,但我的主窗口被阻挡,只涂黑色,因为

它需要以某种方式返回其他线程中的某些东西。



为什么我尝试了以下内容:



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

MSG消息;
MessageBox(NULL, DragAndDropThread ,NULL);
while (GetMessage(& messages,NULL, 0 0 ))
{
MessageBox(NULL, GetMessage ,NULL);
/ * 将虚拟密钥消息转换为字符消息* /
TranslateMessage( &安培;消息);
/ * 发送消息给WindowProcedure * /
DispatchMessage(& messages) ;
}

return TRUE;
}





我已将以下内容放入我的主要功能中:

 CreateThread( 0  0 ,(LPTHREAD_START_ROUTINE)MessageNULLLoopThread,GetActiveWindow(),< span class =code-digit> 0 , 0 ); 





它没有阻止我的主窗口渲染,但在那个线程中

GetActiveWindow()不起作用,所以我需要通过lParam传递它...



并且GetMessage循环在新线程中不起作用,调试消息框

在循环内部不会被调用。



现在这真的很疯狂--.-



为什么GetActiveWindow()无法在另一个线程中运行?为什么循环不工作

如果我把它放入一个帖子?



但最重要的是:我该如何解决这个问题?


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:

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

//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

解决方案

You should study Handling Shell Data Transfer Scenarios (Windows)[^].


I have a idea which is nearly working:

if I put this into my main function:

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:

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:

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 ?


这篇关于拖放非MFC,c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆