如过另一个程序也定义了WM_USER+100 怎么办?

解决方案 »

  1.   

    VC设个WM_USER,就是为了避免冲突。
      

  2.   

    不会的,
    除非你向系统注册了WM_USER+100,
    而别的程序也注册了WM_USER+100。
      

  3.   

    WM_USER到WM_USER+1024(?具体的数字我记不清了)属于用户消息区,只在进程内有效,不会与其他进程冲突.
      

  4.   

    有限制吗?好像大于WM_USER 的整数都可以吧.RED_spring(光子_r) ,如果你看到确切有限制的,告我一声,我也好注意一下.
      

  5.   

    如果有某个软件不遵守 windows 的约定, 冲突就有可能发生.试做这样一个猜想, 你的程序中定义了一个 WM_USER+100 的消息值, 这个消息值对你的程序来说有特定的意义, 现在, 金山快译启动了, 它注入了一个 DLL 进入你的进程, 这是一个钩子. 金山快译也使用了相同的 WM_SER+100 作为它自己的具有特定意义的消息值.这样就出现问题了,  当你给自己的窗口 PostMessage(hwnd, WM_USER+100 , ..., ... ) 时, 有可能金山的代码截获了这个消息, 并且做自己的处理, 它还可能不会交由你的代码进行处理, 这样一来, 应该处理消息的代码没得到处理, 不该处理消息的代码偏偏无意中处理了, 而这时, 双方都是不知道的.这是一个问题所在.MS 是有约定的, 作为特定的窗口类的消息, 以 WM_USER 开始, 到 0x7fff 结束, 典型地, 这些消息值应用到WINDOWS的各个控件 BUTTON, EDIT and so on; 而特定的应用程序消息, 应该从 WM_APP 开始, 到 0xBFFF 结束.像上一例, 你的程序定义 WM_USER+100 是遵守这个约定的, 而金山也这么定义的话就是违反了约定, 金山应该定义 WM_APP 以上的消息值.当多个像金山快译这样需要在系统全局范围使用消息的应用程序出现时, 难保这些程序不会出现冲突, MS 考虑到了, 它提供了一个 个人意见, 仅供参考.
      

  6.   

    The following are the ranges of message numbers. 
    Range Meaning 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 through 0xBFFF Messages available for use by applications. 0xC000 through 0xFFFF String messages for use by applications. Greater than 0xFFFF Reserved by the system for future use. 
    Message numbers in the first range (0 through WM_USER–1) are defined by the system. Values in this range that are not explicitly defined are reserved for future use by the system. Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers. Message numbers in the third range (0x8000 through 0xBFFF) are available for application to use as private messages. Message in this range do not conflict with system messages. Message numbers in the fourth range (0xC000 through 0xFFFF) are defined at run time when an application calls the RegisterWindowMessage function to retrieve a message number for a string. All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions. Message numbers in the fifth range (greater than 0xFFFF) are reserved for future use by the system. 以上是MSDN上的一篇文章, 可解决你的问题, 并纠正我上面的一个错误.good lucky!