typedef unsigned int UINT;
typedef long LONG;
typedef UINT WPARAM;
typedef LONG LPARAM;
在PostMessage或SendMessage中通过WPARAM或者LPARAM将数组传递给消息处理函数
DWORD或其小于等于DWORD(一般为4字节)长度的变量直接传再强转:
unsigned int a =12345;
unsigned int* b = &a;
SendMessage(DWORD(a), DWORD(b));
OnMessage(DWORD wParam, DWORD lParam)
{
unsigned int a =(unsigned int)wParam;
unsigned int* b = (unsigned int*)lParam;
...
}
复杂数据传指针再强转(或提升):
struct a_t
{
int aa;
char ab;
};
a_t a;
SendMessage(DWORD(&a), DWORD(0));
OnMessage(DWORD wParam, DWORD lParam)
{
a_t* pa =(a_t*)wParam;
...
}
///////////////////////////////////////////////////////////////////
char *aa;
aa = new char[20];
strcpy(aa, "hello");
SendMessage(WM_USER_MSG, 0, (LPARAM)aa);
===============================
char *aa, bb[20];
aa = (char *)lParam;
strcpy(bb, aa);
delete aa;
.....
本文详细介绍了Windows编程中SendMessage函数的使用方法,包括如何通过WPARAM和LPARAM传递不同类型的参数到消息处理函数,以及如何处理复杂的数据类型。同时,文中还讨论了在消息传递过程中可能出现的死锁问题及其解决方案。
1万+

被折叠的 条评论
为什么被折叠?



