Friday, 15 July 2011

c++ - CPaneDialog control backgroung (text control) -


In my application I have CPaneDialog with control (eg text control) I try to set the background color for this CPanelDialog for this purpose, I overwrite OnEraseBkgnd

  BOOL CBgPaneDialog :: OnEraseBkgnd {CDC * PDC} {CBrush backBrush (RGB (255, 128, 128)); CBbrush * pOldBrush = pDC- & gt; Selection object (and backbrush); Kurt Rect; Pdc-> GetClipBox (& amp; Rect); PatBlt (rect.left, rect.top, rect.Width (), rect.Height (), PATCOPY); // need to erase pDC- & gt; Pdc-> SelectObject (pOldBrush); Return TRUE; Unfortunately, this is the other background on the control of CPaneDialog  

I overwrote the next method: OnCtlColor caontrol where to set one

  HBRUSH CBgPaneDialog :: OnCtlColor (CDC * PDC, CWnd * PWND, uint nCtlColor) {CBrush br.; Br.CreateSolidBrush (RGB (255, 255, 255)); HBR's HBR = (HBRUSH) BR; CWnd * pCheckBox = GetDlgItem (IDC_STATIC); // put id of your checkbox here. Int a; If (* pCheckbox == * pWnd) {br.DeleteObject (); Br.CreateSolidBrush (a = pDC- & gt; SetBkColor (rgb (255, 128, 128))); HRR = (HBRUSH) BR; } Other hbr = CPaneDialog :: OnCtlColor (PDC, PWND, NCTL roller); Returns HBR;  

}

The control background has changed, but not completely. Please see in the picture:

I can completely change the background for text control

After

Do not return the temporary brush Your code is ok for OnEraseBkgnd () because it is using the brush, it is not returning it, but OnCtlColor Instead use:

  class CMyDialog ... {COLORREF BkColor; CBRash BKbrush; // ...}; CMyDialog :: CMyDialog ... {BkColor = RGB (0, 255, 255); BkBrush.CreateSolidBrush (BkColor); } HBRSH CMIDiolog: :: OnCatLoler (CDC * PDC, CWND * PWND, UINT NCTL Roller) {// AD SCHEDU ... PDC- & gt; Setback Collar (BK Collar); Return BKbrush; }  

By the way, you can add mfc tag to your question to get a faster answer in the future.


No comments:

Post a Comment