How to change the background color of the conversation or form window

xiaoxiao2021-03-06  89

Call CWINAPP:: SetDialogBkcolor can change the background color of all applications. The first parameter specifies the background color, and the second parameter specifies the text color. The following example sets the application dialog to a blue background and yellow text.

Bool csampleapp:: initInstance ()

{

...

// Use blue dialog with yellow text.

SetDialogbkcolor (RGB (0, 0, 255), RGB (255, 255, 0));

...

}

When you need to redraw dialog (or dialogue sub-control), Windows sends a message WM_CTLCOLOR to the dialog, usually the user can let Windows select the brush of the painting background, or reset the message to specify the brush. The following example shows the steps to create a red background dialog.

First, add a member variable of a member variable for the dialogue class:

Class CMYFORMVIEW: PUBLIC CFORMVIEW

{

...

Private:

CBRUSH M_ Brush; // Background Brush

...

}

Second, the brush is initialized to the desired background color in the constructor of the class.

CMYFORMVIEW:: CMYFORMVIEW ()

{

// Initialize Background Brush.

M_brush .createsolidbrush (RGB (0, 0, 255)))

}

Finally, use the ClassWizard to process the WM_CTLCOLOR message and return a brush handle for painting the background of dialogue. Note: This function is to be called because it is also called the dialog control, so it is necessary to detect NCTLCOLOR parameters.

Hbrush CMYFORMVIEW:: oncTlcolor (CDC * PDC, CWND * PWND, UINT NCTLCOLOR)

{

// DETERMINE IF Drawing a Dialog Box. If We are, Return Handle To

// OUR OWN Background Brush. OtherWise Let Windows Handle IT.

IF (nctlcolor == ctlcolor _ dlg)

Return (Hbrush) m_brush .getsafehandle ();

Return CFormview:: OnctLcolor (PDC, PWND, NCTLCOLOR);

}

转载请注明原文地址:https://www.9cbs.com/read-96612.html

New Post(0)