The Linux Page

Recover name of message registered with RegisterWindowMessage()

Today I was confronted with an error in a process that would run in the background and slowly fill up the Windows message queue when it should have been dormant.

I looked at the messages that were being processed once the process woke up and the message number was 0xC10C or so. Nothing in the software has such a number. So I looked around and found out that the message was one of those created using the RegisterWindowMessage() function. (This is wrong in that application since the messages are never used from external applications, but oh well... that does not change the basic problem.)

So, I had a to determine what message 0xC10C represented, It felt like there was no way to convert the number back to the string used to create the message identifier. In fact, there isn't a specialized function for that. However, the RegisterWindowMessage() function is actually doing the exact same thing as RegisterClipboardFormat()... and yes, we can use the opposite to restore the message name: GetClipboardFormatName().

So...

UINT msgid = RegisterWindowMessage("Some_Weird_Name_Here");
...
wchar_t buf[256];
GetClipboardFormatNameW(msgid, buf, sizeof(buf) / sizeof(buf[0]);
// Here buf == "Some_Weird_Name_Here"

That way I could print out the message name and find the culprit in the source code.

Re: Recover name of message registered with ...

This worked perfectly.
Thanks for the post.