Context menu applications are becoming more widely used in windows-based applications. This article discusses how to add your own menu items to the context menu controlled by the edit box for the processing mechanism of the WM_INITMENUPOPUP message.
At the beginning of the time often encountered a problem, is the right mouse button in the edit box, the program does not produce wm_initmenupopup message, cause I also said not clear, also did not find a specific document to explain this problem. Whenever I subclass the edit box to control the addition of my own menu items to the standard context menu (figure II),
Figure II
Always have to run into problems like these. So how exactly do you use the WM_INITMENUPOPUP processing mechanism to implement your own context menu?
The usual approach is to control the implementation of WM_INITMENUPOPUP message processing for the edit box, but as mentioned earlier, the edit box controls not sending Wm_initmenupopup. Edit control must be an empty HWND handle or Tpm_nonotify call Trackpopupmenu,tpm_nonotify to have the menu do not send notifications. It's also possible-just guessing--windows (R) improves performance by reducing the amount of message traffic. It's hard to recall the case of Windows1.0 and Windows 2.0 running on 640kb/8mhz machines! (Does the edit box have a context menu at that time?) Who remembers it? )。
Anyway, if you want to add your own menu items to the context menu controlled by the edit box. How to do it? Alas, is not besides own invention to have no choice? Despair, this article will provide you with a small class: Ceitmenuhandler, with it, everything is OK. All you have to do is just use it. To show the use of this class, I used an example of the previous program, the control of the compiler to modify a bit, in its context menu, wrote three types of File menu items, see Figure three.
Figure Three