MFC: Xinxin Sun Tutorial 5 notes

Source: Internet
Author: User
Tags drawtext

This section is mainly about text programming.

1 //Ctextview Drawing2 3 voidCtextview::ondraw (cdc*PDC)4 {5ctextdoc* PDoc =getdocument ();6 assert_valid (PDOC);7     if(!PDoc)8         return;9 Ten     //TODO: Add drawing code here for native data One     //CString str ("Nanjing Panda Electronic Equipment Co., Ltd."); A CString str; -str ="Nanjing Panda Electronic Equipment Co., Ltd."; -Pdc->textouta ( -, -, str); the  -CSize sz = pdc->gettextextent (str); -  - Str. LoadString (Ids_xiongmao); +Pdc->textouta (0, $, str); -  +Pdc->Beginpath (); APdc->rectangle ( -, -, -+SZ.CX, -+sz.cy); atPdc->Endpath (); -Pdc->Selectclippath (Rgn_diff); -     //Pdc->selectclippath (rgn_and); -      for(inti =0; I < -; i+=Ten) { -Pdc->moveto (0, i); -Pdc->lineto ( -, i); inPdc->moveto (I,0); -Pdc->lineto (I, -); to     } +}
View Code
1 //Ctextview message handlers2 3 intctextview::oncreate (lpcreatestruct lpcreatestruct)4 {5     if(Cview::oncreate (lpcreatestruct) = =-1)6         return-1;7 8     //TODO: Add your own dedicated creation code here9CCLIENTDC DC ( This);Ten Textmetric TM; Onedc. GetTextMetrics (&TM); A //Createsolidcaret (TM.TMAVECHARWIDTH/8, tm.tmheight); -      - bitmap. LoadBitmap (IDB_BITMAP1); theCreateCaret (&bitmap); -  - ShowCaret (); -  +SetTimer (1, -, NULL); -     return 0; +}
View Code
1 voidCtextview::onchar (UINT NChar, uint nrepcnt, uint nflags)2 {3     //TODO: Add Message Handler code and/or call default values here4CCLIENTDC DC ( This);5 CFont font;6Font. CreatePointFont ( -,"XXFarEastFont-Xingkai", NULL);7CFont *poldfont = DC. SelectObject (&font);8 9 Textmetric TM;Tendc. GetTextMetrics (&TM); One     if(0x0d==NChar) { A m_strline.empty (); -M_PTORIGIN.Y + =Tm.tmheight; -     } the     Else if(0x08==NChar) { -COLORREF CLR =DC. SetTextColor (DC. GetBkColor ()); - DC. Textouta (m_ptorigin.x, M_PTORIGIN.Y, m_strline); -M_strline = M_strline.left (M_strline.getlength ()-1); + DC. SetTextColor (CLR); -     } +     Else { AM_strline + =(wchar_t) NChar; at     } -CSize sz =DC. GetTextExtent (m_strline); -  - CPoint pt; -Pt.x = m_ptorigin.x +sz.cx; -Pt.y =M_PTORIGIN.Y; in  - Setcaretpos (PT); to DC. Textouta (m_ptorigin.x, M_PTORIGIN.Y, m_strline); +  - DC. SelectObject (Poldfont); the  * Cview::onchar (NChar, nrepcnt, nflags); $}
View Code
1 void Ctextview::onlbuttondown (UINT nflags, CPoint point) 2 {3     // TODO: Add Message Handler code and/or call default values here 4     Setcaretpos (point); 5     m_strline.empty (); 6     M_ptorigin = Point ; 7     Cview::onlbuttondown (nflags, point); 8 }
View Code
1 voidCtextview::ontimer (uint_ptr nidevent)2 {3     //TODO: Add Message Handler code and/or call default values here4M_nwidth + =5;5     6CCLIENTDC DC ( This);7 Textmetric TM;8dc. GetTextMetrics (&TM);9 CRect rect;TenRect.left =0; OneRect.top = $; ARect.right =M_nwidth; -Rect.bottom = Rect.top +Tm.tmheight; -  thedc. SetTextColor (RGB (255,0,0)); - CString str; - Str. Loadstringa (Ids_xiongmao); - DC. DrawText (str, rect, dt_left); +  -Rect.top = Max; +Rect.bottom = Rect.top +Tm.tmheight; A     //DC. DrawText (str, rect, dt_right); at DC. DrawText (str, rect, dt_center); -  -CSize sz =DC. GetTextExtent (str); -     if(M_nwidth >sz.cx) { -M_nwidth =0; -dc. SetTextColor (RGB (0,255,0)); indc. TextOut (0, $, str); -     } to  + Cview::ontimer (nidevent); -}
View Code

MFC: Xinxin Sun Tutorial 5 notes

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.