Implementation of the image background editing box

Source: Internet
Author: User

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.

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.