VC video tutorial notes (Lesson 5)

Source: Internet
Author: User

1. cwnd: createsolidcaret: Create an insert operator. showcaret () displays the insert operator. Gettextmetrics () to obtain information about the current font. Cwnd: createcaret ()
Bitmap. loadbitmap (idb_bitmap1); // here, bitmap is a member variable!
Createcaret (& Bitmap );
Showcaret ();
Textmetric TM; // font Structure
DC. gettextmetrics (& TM );//
M_ptorigin.y + = TM. tmheight; // obtain the font height.
2. cstring: loadstring (ID) in VC, which is convenient.
3. Concept of path layer: There are two ways to create a path layer:
(1)
PDC-> beginpath ();
PDC-> rectangle (50, 50, 50 + Sz. CX, 50 + Sz. Cy );
PDC-> endpath ();
PDC-> selectclippath (rgn_diff );
(2)
Csize SZ = PDC-> gettextextent (STR );
Crgn rn;
Rn. createrectrgn (0, 50, Sz. CX, Sz. Cy );
PDC-> selectcliprgn (& RN, rgn_diff );
What is the role of the path layer? It can protect our previous text or images from being overwritten by subsequent paintings.
4. Enter text on The View.
Cfont font; // create a font object
Font. createpointfont (300, "文 ", null); // set
Cfont * poldfont = Dc. SelectObject (& font); // select the font to DC.
Textmetric TM; // create a font information object
DC. gettextmetrics (& TM); // obtain the current font information
If (0x0d = nchar) // process the return key
{
M_strline.empty ();
M_ptorigin.y + = TM. tmheight;
}
Else if (0x08 = nchar) // process the return key
{
Colorref CLR = Dc. settextcolor (DC. getbkcolor ());
DC. textout (m_ptorigin.x, m_ptorigin.y, m_strline );
M_strline = m_strline.left (m_strline.getlength ()-1 );
DC. settextcolor (CLR );
}
Else
{
M_strline + = nchar;
}
Csize SZ = Dc. gettextextent (m_strline );

Cpoint pt; // process the cursor position
PT. x = m_ptorigin.x + Sz. CX;
PT. Y = m_ptorigin.y;

Setcaretpos (PT );
DC. textout (m_ptorigin.x, m_ptorigin.y, m_strline); // output font

DC. SelectObject (poldfont); // select the original font.
5. simulate the process of changing the color of the karaoke bar.
(1) set the timer
(2) Add the following code to the Timer:
// Del m_nwidth + = 5; // This is the member variable of the view and the initial value is 0.
// Del
// Del
// Del cclientdc DC (this );
// Del textmetric TM;
// Del DC. gettextmetrics (& TM );
// Del crect rect;
// Del rect. Left = 0;
// Del rect. Top = 200;
// Del rect. Right = m_nwidth;
// Del rect. Bottom = rect. Top + TM. tmheight; // the length of this rectangle increases with the timer triggering.
// Del
// Del DC. settextcolor (RGB (255, 0, 0 ));
// Del cstring STR;
// Del Str. loadstring (ids_weixin );
// Del DC. drawtext (STR, rect, dt_left); this function is used to output a string to a rectangle. However, if the length of a string exceeds the length of a rectangle, extra characters are truncated.
// Del
// Del rect. Top = 150;
// Del rect. Bottom = rect. Top + TM. tmheight;
// Del DC. drawtext (STR, rect, dt_right );
// Del
// Del csize SZ = Dc. gettextextent (STR); get the string length
// Del if (m_nwidth> Sz. CX) when the length of a rectangle is greater than the length of a string, return it to 0.
// Del {
// Del m_nwidth = 0;
// Del DC. settextcolor (RGB (0,255, 0 ));
// Del DC. textout (0,200, STR );
// Del}
// Del
// Del cview: ontimer (nidevent );
6. settimer can also be operated using the callback function, but it is not convenient. The procedure is as follows:
(1) In the oncreate message response function of view: settimer (, timer2proc );
(2) Implementation of callback functions:
Void callback export timer2proc (
Hwnd, // handle of cwnd that called settimer
Uint nmsg, // wm_timer
Uint nidevent, // timer Identification
DWORD dwtime // system time
)
{
// MessageBox (cmainframe *) afxgetmainwnd ()-> m_hwnd), "ddfaf", "Weixin", 0 );
;
Cmainframe * pmain = (cmainframe *) afxgetapp ()-> m_pmainwnd; // obtain the mainframe pointer
Ctextview * pview = (ctextview *) pmain-> getactiveview (); // get the view pointer
Cclientdc DC (pview); // construct a DC
DC. textout (333,222, "Hello World ");

} // We can see that the pointer to the window or app needs to be obtained when using the callback function, which brings us trouble in our operations. Not convenient.

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.