Use the cbitmap class to scale and display images in the static control.

Source: Internet
Author: User

Add a cstatic control in the caboutdlg dialog box with the ID idc_static_aboutbox_avatar. Use the following method to display the image. Note that the image display operation must be performed in the onpaint () message processing function, otherwise, the image cannot be displayed normally (for details, see the notes ). However, when a large image is displayed, the image is compressed due to a large degree of scaling, causing serious distortion. I do not know how to solve this problem.

Bool caboutdlg: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); <br/> m_pstcavatar = (cstatic *) getdlgitem (batch ); <br/> m_pstcavatar-> getclientrect (& m_rectstc); <br/> return true; <br/>}</P> <p> void caboutdlg: onpaint () <br/> {<br/> cpaintdc (this); // device context for painting <br/> showimage (); <br/>/* if it is placed in oninitdialog () the function cannot display the image normally, because after the oninitdialog () function shows the image, Windows sends a wm_paint message to draw the caboutdlg dialog box. When the caboutdlg intercepts the message and calls onpaint () this dialog box is re-painted when the message processing function is used, so the image is refreshed. Therefore, you can only call showimage () in the onpaint () function () function display image */<br/>}</P> <p> void caboutdlg: showimage () <br/>{< br/> CDC * PDC = m_pstcavatar-> getdc (); <br/> CDC memdc; <br/> memdc. createcompatibledc (PDC); <br/> cbitmap * avatarbmp = new cbitmap (); <br/> cbitmap * oldbmp; <br/> bitmap bminfo; <br/> avatarbmp-> loadbitmap (idb_avatar); <br/> avatarbmp-> GetObject (sizeof (bminfo), & bminfo); <br/> oldbmp = memdc. selectObject (avatarbmp); <br/> PDC-> stretchblt (, m_rectstc.width (), m_rectstc.height (), & memdc, bminfo. bmwidth, bminfo. bmheight, srccopy); <br/> If (oldbmp) <br/>{< br/> memdc. selectObject (oldbmp); <br/>}< br/> releasedc (PDC); <br/>}

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.