PostMessage WPARAM和LPARAM [英] PostMessage WPARAM and LPARAM

查看:267
本文介绍了PostMessage WPARAM和LPARAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我有一个MFC GUI和C ++中的dll. GUI具有编辑控件,其中向用户提供了有关当前正在进行的操作的信息.我想到了从dll调用"PostMessage"以将该信息传递给GUI.即,从dll:-

PostMessage(hWnd,WM_USER,0,0); //hWnd-Windows句柄

如何在WPARAM和LPARAM的帮助下嵌入要在GUI中显示的消息?
假设文件操作失败"是要在GUI中显示的消息,如何在PostMessage调用中添加它?

在对话框类中,给出以下消息映射:-
ON_MESSAGE(WM_USER,&CMainDlg :: OnMessage)

为此还添加了一个事件处理程序:-

LRESULT CMainDlg :: OnMessage(WPARAM wParam,LPARAM lParam)
{
//我必须添加从此处获得的消息以编辑控件.

返回0;
}

Hi.
i have a MFC GUI and a dll in C++. The GUI has a edit control, where the user is provided with information regarding what operation is currently carried out. i thought of calling "PostMessage" from the dll to pass that information to the GUI. ie, from the dll:-

PostMessage(hWnd, WM_USER, 0,0); // hWnd - windows handle

How can i embed the message to be displayed in the GUI with the help of WPARAM and LPARAM?
Suppose "File operation failed" is the message to be displayed in the GUI, how can i add it in the PostMessage call?

In the dialog class, following message map is given:-
ON_MESSAGE(WM_USER, &CMainDlg::OnMessage)

an event handler for this is also added:-

LRESULT CMainDlg::OnMessage(WPARAM wParam,LPARAM lParam)
{
// i have to add the message obtained here to edit control.

return 0;
}

推荐答案

一个 DLL 被映射到加载它的进程的地址空间中,然后您可以在其中为字符串分配缓冲区 DLL 并通过LPARAM传递指向它的指针:这是许多预制的Windows消息的作用.
A DLL is mapped in the address space of the process that load it, then you can allocate a buffer for your string in the DLL and pass a pointer to it through the LPARAM: this is what a lot of pre-made Windows messages do.


1)尝试声明您的str as
static LPCTSTR仅用于测试:)

2)如果可以使用
并且您将需要使用PostMessage(..)(而不是SendMessage(..))-

由发送方分配字符串内存(例如new CString(..))
并在需要处理后由接收方(例如delete)释放它:)
1) Try to declare your str as
static LPCTSTR for a test only :)

2) If it will work
and you will need to use PostMessage(..) (not SendMessage(..)) -

allocate the string memory by the sender (for example new CString(..))
and release it by the receiver (for example delete) after your wanted processing :)


是的,我们必须删除指针... :)


在Debug配置中编译这两部分,
将调试器配置为在任何异常时停止,
通过F5启动它,并在删除时遇到异常.

然后-发布异常的功能,
它的堆栈以及最后失败的断言列表.

谢谢:)
Yes, we have to delete the pointer... :)

Please
compile the both parts in Debug configuration,
configure the debugger to stop at any exception,
start it by F5 and arrive your exception at the deleting.

Then - post hier the function of the exception,
its stack and maybe the list of the last failed assertions.

Thank you :)


这篇关于PostMessage WPARAM和LPARAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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