如何创建自定义的Windows消息? [英] How could I create a custom windows message?

查看:199
本文介绍了如何创建自定义的Windows消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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




  • 创建自定义Windows消息


  • 使用它作为它的WPARAM字符的地址*我想在屏幕上显示


  • 使用它的LPARAM字符的长度*我想在屏幕上显示


  • 发送消息

  • 它来,以便它打印的字符




如何创建自定义Windows消息? WPARAM和LPARAM的类型是什么?



感谢

解决方案

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



最简单方式来实现这是只有一个头文件包含您的自定义消息编号,从WM_USER和向上编号,如此:

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

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



,它听起来像一个复杂的调试输出的方式。您是否尝试使用OutputDebugString()API调用?或者调试线程的printf()调用?


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 :

  • create a custom windows message

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

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

  • send the message

  • process it when it comes , so that it prints the 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 ?

Thanks

解决方案

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.

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:

#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.

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?

这篇关于如何创建自定义的Windows消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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