Author: zhoudb
In VC, standard Windows controls such as Treeview, editbox, ComboBox, and ListBox do not support selecting the properties of the background bitmap, some unconventional methods are required. This section describes how to implement a background bitmap in the cedit class and how to change the background. There are other possible implementation methods. If you are interested, you can discuss them.
This articleProgramRun
The following describes several key variables and functions of the cmyeditctrl class.
The first step is to add several variables to the class;
Public: cbitmap m_bmp; protected: cbrush m_brhollow; cbitmap * m_pbmcurrent;
Step 2 Reload some functions:
Afx_msg hbrush ctlcolor (CDC * PDC, uint nctlcolor); afx_msg void onlbuttonup (uint nflags, cpoint point); afx_msg void onchange (); afx_msg bool convert (CDC * PDC );
Specific functions:
2.1 onchange ();
If this function is not available, you can type a few characters, such as abcdedfg, and then delete two FG, but the editbox is not updated. This is the main reason for adding this function.
Void cmyeditctrl: onchange () {invalidate (); // force update}
2.2 onlbuttonup ();
Similarly, the refresh issue occurs when you select the mouse. If you are interested, you can comment it out first to see how a bug occurs.
Void cmyeditctrl: onlbuttonup (uint nflags, cpoint point) {invalidate (); // force update cedit: onlbuttonup (nflags, point );}
2.3 ctlcolor (CDC * PDC, uint nctlcolor)
The general text is white by default, and the transparent form is selected here, so the basemap can be displayed.
Hbrush cmyeditctrl: ctlcolor (CDC * PDC, uint nctlcolor) {PDC-> setbkmode (transparent); // select transparent background mode PDC-> settextcolor (RGB (0xff, 0xff, 0xff); // set the text color to white return m_brhollow ;}
2.4 onerasebkgnd (CDC * PDC)
Displays the selected background bitmap.
Bool cmyeditctrl: onerasebkgnd (CDC * PDC) {bitmap bm; m_bmp .getbitmap (& BM); m_pbmcurrent = & m_bmp; CDC dcmem; dcmem. createcompatibledc (PDC); cbitmap * poldbitmap = dcmem. selectObject (m_pbmcurrent); // select the bitmap PDC-> bitblt (0, 0, BM. bmwidth, BM. bmheight, & dcmem, 0, 0, srccopy); // draw a bitmap dcmem. selectObject (poldbitmap); Return true ;}
Note: Code is simplified and optimized. For the selection of the base map, here I select a base map of the same size as my editbox. If the two are different sizes, You need to modify some onerasebkgnd (CDC * PDC) code.
basically, the function of this class is implemented in this way.