How to define private base Application messages?

前端 未结 1 570
生来不讨喜
生来不讨喜 2021-02-05 11:49

I\'m was using private messages in my application for year like this:

UM_APP_BASE = WM_APP; // WM_APP is declared as WM_APP = $8000; in \"Controls\" unit.


        
相关标签:
1条回答
  • 2021-02-05 12:39

    I'm not sure where your information comes from. The MSDN documentation says:

    0 through WM_USER –1
    Messages reserved for use by the system.

    WM_USER through 0x7FFF
    Integer messages for use by private window classes.

    WM_APP (0x8000) through 0xBFFF
    Messages available for use by applications.

    0xC000 through 0xFFFF
    String messages for use by applications.

    Greater than 0xFFFF
    Reserved by the system.


    Now, what is the difference between the WM_USER range, and the WM_APP range? This has been covered in many places. For instance, here is what Raymond Chen has to say.

    0x400 .. 0x7FFF (WM_USER .. WM_APP-1): Class-defined messages.

    The meanings of these messages is determined by the implementor of the window class. (Informally: By the person who calls RegisterClass for that window class.) For example, the WM_USER+1 message means TB_ENABLEBUTTON if the window is a toolbar control, but it means TTM_ACTIVATE if it is a tooltip control, and it means DM_SETDEFID if it is a dialog box. If you created your own control, it would mean something else completely different. Since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

    0x8000 .. 0xBFFF (WM_APP ... MAXINTATOM-1): Application-defined messages.

    The meanings of these messages is determined by the application that created the window. (Informally: By the person who calls CreateWindow.) This message region was created in Windows 95 to ensure that applications which subclass a window and generate custom messages will not interfere with new messages created by the window class in future versions. Again, since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling.

    The main thing to take from all this is that if you define messages in the WM_USER range, then be prepared for other controls in your application to have their own use for those same messages. For instance, you must not broadcast messages in the WM_USER range.

    On the other hand, messages in the WM_APP range are intended to have the same meaning for all different window classes in an application.

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