Search code examples
.netwinformsmessage-loop

Unknown Windows Message 0xC052


I'm working on a problem (How to Detect a form open inside the application) and stumbled over a Windows Message I can't understand: 0xC052.

This is the first Message I receive in a MessageFilter when a form opens. But since I didn't found any reference I don't want to rely on the assumption, that the message tells me reliable that a form was opened.

EDIT: Added code

Application.AddMessageFilter(new MessageFilterImpl());

class MessageFilterImpl : IMessageFilter
{
    public bool PreFilterMessage(ref Message m)
    {
        Control wnd = Form.FromHandle(m.HWnd);
        if (wnd is Form)
            knownForms.Add((Form)wnd); //m.Msg is 0xC052

        return false;
    }
}

Solution

  • Assuming this is a well-formed windows message, it's a dynamically allocated ID returned from the RegisterWindowMessage function (note the range 0xC000-0xFFFF). The function is used when you need to define a new windows message that's supposed to be system-unique. In other words, you can't rely on the ID - it will be different the next time you reboot.

    .NET Winforms uses it internally plenty of times - it's a well behaving windows application framework. So the exact number you found might conceivably correspond to something like:

    • A thread callback (Invoke and friends)
    • Mouse enter message
    • Get control name (Name)

    And of course, it doesn't even have to be a .NET message - there might be some application on your system that broadcasts messages to all forms, for example. It's a common way of handling RPC (in my case, the form received e.g. MSUIM.Msg.RpcSendReceive).