Implement simple image functions in the dialog box

Source: Internet
Author: User

Dialog Box to display device-independent Images

 Void cmydlg: onpaint () <br/>{< br/> ................ </P> <p> else <br/> {<br/> cdialog: onpaint (); <br/> cwnd * pwnd = getdlgitem (idc_bmp ); <br/> // <br/> /// pointer <br/> CDC * PDC = pwnd-> getdc (); <br/> If (State = 1) <br/>{< br/>/omitted/<br/>}</P> <p>

The display device-independent bitmap is added to the DIB class and the color palette.

Adjust the space position and size

Getdlgitem (idc_zx)-> getwindowrect (& rect_ B [0]); <br/> // obtain the display reference coordinate <br/> screentoclient (& rect_ B [0]); // convert to the client interface coordinates <br/> getdlgitem (idc_zx)-> movewindow (rect_ B [0]. topleft (). x-(rect. width ()-scaledwidth), rect_ B [0]. topleft (). y, rect_ B [0]. width (), rect_ B [0]. height (); // adjust

Movewindow has four parameters: X and Y coordinates in the upper left corner, and controls the bandwidth and height. You need to change the size and location of the four parameters.

Adjust the dialog box size and position

Getwindowrect (& rectw); <br/> afxgetapp ()-> m_pmainwnd-> movewindow (Pt. X, Pt. Y, CX, CY );

The size and position of the adjusted dialog box are the same as that of the space, but must be implemented in afxgetapp)

Dialog Box display menu

Void cmydlg: oncontextmenu (cwnd * pwnd, cpoint point) <br/>{< br/> // todo: add your message handler code here <br/> cmenu menu; <br/> menu. loadmenu (idr_menu1); <br/> cmenu * mu = menu. getsubmenu (0); <br/> Mu-> trackpopupmenu (tpm_leftbutton | tpm_leftalign, point. x, point. y, this); <br/> menu. destroymenu (); <br/>}

Insert the oncontextmenu message in the DLG. Note that the message conflicts with the right message under certain conditions.

Display menu in cview

Void cmenuview: onrbuttondown (uint nflags, cpoint point) <br/>{< br/> // todo: add your message handler code here and/or call default <br/> cmenu menu; <br/> menu. loadmenu (idr_menu1); <br/> cmenu * ppopup = menu. getsubmenu (0); </P> <p> clienttoscreen (& Point); <br/> ppopup-> trackpopupmenu (tpm_leftalign | tpm_rightbutton, point. x, point. y, getparent (); </P> <p> cview: onrbuttondown (nflags, point); <br/>}

Add a pop-up menu to form both. Add the mode VC ++ in components and controls of the add project in the project

Load the pop-up menu in the components folder to create a pop-up menu. In chapter 6 of Sun Xin vc6.0 ++, we will provide a detailed introduction to this chapter. If necessary, review the content of this chapter.

Load controls in cmainfram

  • Create a subclass Based on the ctoolbar class. Add the required controls to this class, as shown in figure

Class ccombotoolbar: Public ctoolbar <br/>{< br/> Public: <br/> cstatic m_name; <br/> cedit m_button_engine; <br/> ccombotoolbar (); <br/> virtual ~ Ccombotoolbar (); </P> <p> };

It can also be a Class Based on the status bar, basically similar.

  • Ccombotoolbar m_newtoolbar; add private variables to cmainframe
  • Display the toolbar in oncreat and create the required controls

If (! M_newtoolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_top <br/> | cbrs_gripper | cbrs_tooltips | cbrs_flyby | required) | <br/>! M_newtoolbar.loadtoolbar (idr_toolbar1) <br/>{< br/> trace0 ("failed to create toolbar/N"); <br/> return-1; // fail to create <br/>}< br/> m_newtoolbar.enabledocking (cbrs_align_any); <br/> enabledocking (cbrs_align_any); <br/> dockcontrolbar (& m_newtoolbar ); <br/> // The toolbar shown above <br/> int nitemidx; <br/> rect; <br/> nitemidx = m_newtoolbar.commandtoindex (id_searcheng ); <br/> m_newtoolbar.setbuttoninfo (nitem Idx, id_searcheng, tbbs_separator, 40); <br/> m_newtoolbar.getitemrect (nitemidx, & rect); <br/> // the size of the control set above <br/> If (! M_newtoolbar.m_name.create ("dot coordinate", ws_child | ws_visible | ss_center/* ws_child | ws_visible | bs_defpushbutton */, rect1, & m_newtoolbar, 100 )) <br/>{< br/> trace0 ("failed to create combo box/N"); <br/> return-1; <br/>}// create a control </P> <p> m_newtoolbar.m_button_engine.showwindow (sw_showna); <br/> // Display Control <br/>

According to the specific meanings of some functions above, you can find msdn. msdn has a detailed introduction.

Change the sctatic font

Methods: font changes of various spaces

  1. Create a global variable for cfont m_font;
  2. M_font.createpointfont (, ""); or createfont (, ""); in the required function, set the font. For specific parameters of the function, you can find the msdn
  3. Getdlgitem (id_charikshow)-> setfont (& m_font, true); set the control font to be changed.
  4. You cannot use getdlgitem to get the control pointer in the displayed dialog box, but you can use the control entity such as m_newtoolbar.m_name.setfont (& m_font, true). (In this way, you can change the control font in the toolbar, but it is not clear if there is any problem ).

I am a newbie for VC. I wrote a blog for review and future reference for a small item in this week. I am very happy to help you. If there is an error, please point it out.

So that I can improve my corrections. I hope to share my studies with you.

 

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.