How could I create a custom windows message?

后端 未结 1 899
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 01:49

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 applicat

相关标签:
1条回答
  • 2020-12-17 01:59

    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?

    0 讨论(0)
提交回复
热议问题