In VC ++ 6.0, I changed the background color of the window and the background color of the control, CDC, and my feeling.

Source: Internet
Author: User

In VC ++ 6.0, the background color of the window and the background color of the control are changed.

 

1. Change the background color of the dialog box.
In C... Add initinstance () in the app class
Setdialogbkcolor (RGB (0,192, 0), RGB (, 0 ));
2. If you want to change the background color of static text or single-choice buttons, you can use the one you mentioned to get the control ID and then set the background color. steps:
(1) The onctlcolor function is generated for the wm_ctlcolor message in the response dialog box class.
(2) Add the member variable cbrush m_brush for the dialog box class;
Initialize m_brush.createsolidbrush (RGB (0,255, 0) in the initialization function ));
(3) Add code to the onctlcolor function to change the text color and background color of the control.
Switch (pwnd-> getdlgctrlid ())
{
Case (idc_input ):
PDC-> settextcolor (RGB (192 ));
PDC-> setbkmode (transparent );
Return m_brush;
Break;
Case (idc_edit1 ):
PDC-> settextcolor (RGB (255, 0, 0 ));
PDC-> setbkmode (transparent );
Return m_brush;
Break;
Case (idc_choice ):
PDC-> settextcolor (RGB (255,128, 0 ));
PDC-> setbkmode (transparent );
Return m_brush;
Break;
Case (idc_radio1 ):
PDC-> settextcolor (RGB (255, 0, 20 ));
PDC-> setbkmode (transparent );
Return m_brush;
Break;
Default:
Break;
}
3. if you want to change the background color of a button, it's too difficult. You need to rewrite the two classes. You also need to go online and briefly introduce this in Sun Xin's video tutorial, it can only change the text color of the button.

 

Int setbkmode (
HDC, // handle to DC
Int ibkmode // background Mode
);

TheSetbkmodeFunction sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.

Settextcolor
The settextcolor function sets the text color for the specified device context to the specified color.

Colorref settextcolor (
HDC, // handle to DC
Colorref crcolor // text color
);

Reprinted statement: This article from http://wmnmtm.blog.163.com/blog/static/3824571420097223040181/

========================================================== ======================================

 

CDC, my feelings

 

Dialog Box-based program:

Void ctestdlg: onpaint ()

{

If (isiconic ())

{

Cpaintdc DC (this); // device context for painting

Sendmessage (wm_iconerasebkgnd, (wparam) DC. getsafehdc (), 0 );

// Center icon in client rectangle

Int cxicon = getsystemmetrics (sm_cxicon );

Int cyicon = getsystemmetrics (sm_cyicon );

Crect rect;

Getclientrect (& rect );

Int x = (rect. Width ()-cxicon + 1)/2;

Int y = (rect. Height ()-cyicon + 1)/2;

 

// Draw the icon

DC. drawicon (X, Y, m_hicon );

 

Afxmessagebox ("DD"); // It is not displayed here

}

Else

{

Cdialog: onpaint ();

// Afxmessagebox ("DD"); // This will pop up continuously, indicating that the call is not stopping.

If (null = getdc ())

{

Afxmessagebox ("");

}

Else

{

Afxmessagebox ("B ");

}

}

}

 

Create a dialog box to add the wm_paint message

Void cmydlg: onpaint ()

{

Cpaintdc DC (this); // device context for painting

// Todo: add your message handler code here

// Do not call cdialog: onpaint () for painting messages

}

 

Drawing through DC

Void cmydlg: onpaint ()

{

Cpaintdc DC (this); // device context for painting

DC. moveTo (0, 0 );

DC. lineto (10, 10 );

DC. ARC (50, 80, 80, 100,100,200,200 );

// Todo: add your message handler code here

// Do not call cdialog: onpaint () for painting messages

}

For a single-document program, the ondraw function is automatically generated in the View class.

Void ctestaview: ondraw (CDC * PDC)

{

Ctestadoc * pdoc = getdocument ();

Assert_valid (pdoc );

// Todo: Add draw code for native data here

}

 

You can use PDC for plotting:

 

Void ctestaview: ondraw (CDC * PDC)

{

Ctestadoc * pdoc = getdocument ();

Assert_valid (pdoc );

// Todo: Add draw code for native data here

 

PDC-> moveTo (0, 0 );

PDC-> lineto (100,100 );

}

 

!! By the way, the ondraw function automatically adds the following sentence: ctestadoc * pdoc = getdocument ();

Pdoc can be used to obtain the pointer of the document associated with this view. This allows you to call the member functions of the document.

As follows:

Void ctestaview: ondraw (CDC * PDC)

{

Ctestadoc * pdoc = getdocument ();

Assert_valid (pdoc );

// Todo: Add draw code for native data here

 

PDC-> moveTo (0, 0 );

PDC-> lineto (100,100 );

 

PDC-> arc (100., 100,200,200,300,300,400,400 );

PDC-> textout (100,100, "ABC ");

 

// Set the document name

Maid;

Lpctstr = "My Documents ";

Pdoc-> settitle (lpctstr );

Cstring STR = pdoc-> gettitle ();

Afxmessagebox (STR );

}

 

Reprinted statement: This article from http://wmnmtm.blog.163.com/blog/static/3824571420096319566302/

========================================================== ======================================

 

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.