Programming with Microsoft Visual C++.NET 6ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming with Microsoft Visual C++.NET 6ed [Electronic resources] - نسخه متنی

George Shepherd, David Kruglinski

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید








Setting the Dialog Box Background Color or a Control Color


You can change the background color of individual dialog boxes or specific controls in a dialog box, but you have to do some extra work. The parent dialog is sent a WM_CTLCOLOR message for each control immediately before the control is displayed. A WM_CTLCOLOR message is also sent on behalf of the dialog box itself. If you map this message in your derived dialog class, you can set the foreground and background text colors and select a brush for the control or dialog nontext area.

Following is a sample OnCtlColor function that sets all edit control backgrounds to yellow and the dialog box background to red. The m_hYellowBrush and m_hRedBrush variables are data members of type HBRUSH, which are initialized in the dialog box's OnInitDialog function. The nCtlColor parameter indicates the type of control, and the pWnd parameter identifies the specific control. If you wanted to set the color for an individual edit control, you can convert pWnd to a child window ID and test it.

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT) {
pDC->SetBkColor(RGB(255, 255, 0)); // yellow
return m_hYellowBrush;
}
if (nCtlColor == CTLCOLOR_DLG) {
pDC->SetBkColor(RGB(255, 0, 0)); // red
return m_hRedBrush;
}
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}





Note

The dialog box does not post the WM_CTLCOLOR message in the message queue; instead, it calls the Win32 SendMessage function to send the message immediately. The message handler can then return a parameter, in this case a handle to a brush. This is not an MFC CBrush object but rather a Win32 HBRUSH. You can create the brush by calling the Win32 functions CreateSolidBrush, CreateHatchBrush, and so forth.



/ 319