VC Custom edit Box context menu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.