我怎么能创建自定义窗口消息?

[英]How could I create a custom windows message?


Our project is running on Windows CE 6.0 and is written in C++ . We have some problems with the code , and we are unable to debug . We also found out that if in our application we create threads and try to printf from them , the output won't appear . The only output that will appear is the one from the main thread . I would like to do the following :

我们的项目在Windows CE 6.0上运行,并且是用C ++编写的。我们的代码有些问题,我们无法调试。我们还发现,如果在我们的应用程序中我们创建线程并尝试从它们printf,输出将不会出现。将出现的唯一输出是主线程中的输出。我想做以下事情:

  • create a custom windows message

    创建自定义Windows消息

  • use as it's WPARAM the address of a char* I want to show on the screen

    使用它作为WPARAM我要在屏幕上显示的char *的地址

  • use as it's LPARAM the length of the char* I want to show on the screen

    使用它作为LPARAM我要在屏幕上显示的char *的长度

  • send the message

    发送消息

  • process it when it comes , so that it prints the char*

    当它到来时处理它,以便它打印char *

How could I create the custom windows message ? What are the types of WPARAM and LPARAM ? Is it possible to do what I just wrote ?

我怎么能创建自定义窗口消息? WPARAM和LPARAM有哪些类型?有可能做我刚刚写的东西吗?

Thanks

1 个解决方案

#1


5  

It's certainly possible to do what you describe. You don't need to actually do anything to create a custom message for communication within your application: just make sure that the code that sends the message and the code that receives the message agree on what the message number actually is, and use a message number that doesn't overlap with any of the numbers Windows uses. There is a RegisterWindowMessage() function, but that's only needed to get a message number that's unique across the entire operating system, so used for inter-process communication.

你可以做你所描述的事情。您无需在应用程序中为通信创建自定义消息实际执行任何操作:只需确保发送消息的代码和接收消息的代码就消息编号的实际内容达成一致,并使用消息与Windows使用的任何数字都不重叠的数字。有一个RegisterWindowMessage()函数,但只需要获取整个操作系统中唯一的消息号,因此用于进程间通信。

The simplest way to achieve this is to just have a header file somewhere containing your custom message numbers, starting with WM_USER and numbering upwards, like so:

实现这一目标的最简单方法是在某处包含自定义消息编号的头文件,从WM_USER开始并向​​上编号,如下所示:

#define WM_FIRST_CUSTOM_MSG (WM_USER+0)
#define WM_SECOND_CUSTOM_MSG (WM_USER+1)

The WPARAM and LPARAM types are defined when you include "windows.h", so can have different types on different systems. For 32-bit operating systems, they are both usually 32-bit integers. If you're just using the message for testing purposes, that's usually good enough, and you can stick whatever you want in there. For production code, though, you should be more careful: WPARAM is really for "integer-like" data, and LPARAM for "pointer-like" data. In Win64, for example, LPARAM is long enough to hold a 64-bit pointer, but WPARAM only holds a 32-bit integer. For passing more data than just an integer and a pointer, I'd use lParam to pass a pointer to some sort of structure containing all my arguments.

当您包含“windows.h”时,会定义WPARAM和LPARAM类型,因此可以在不同的系统上使用不同的类型。对于32位操作系统,它们通常都是32位整数。如果您只是将消息用于测试目的,那通常就足够了,您可以在那里坚持任何想要的东西。但是,对于生产代码,您应该更加小心:WPARAM实际上是“类似整数”的数据,LPARAM是“指针式”数据。例如,在Win64中,LPARAM足以容纳64位指针,但WPARAM只保存32位整数。为了传递更多的数据而不仅仅是一个整数和一个指针,我会使用lParam将指针传递给包含我所有参数的某种结构。

Having said all that, it sounds like a complicated way of getting debugging output. Have you tried using the OutputDebugString() API call? Or debugging the thread's printf() call?

说了这么多,这听起来像是获取调试输出的复杂方法。您是否尝试过使用OutputDebugString()API调用?或调试线程的printf()调用?

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2008/11/16/66fccc4542d4712b0150b6d6b359b8d6.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告