For a dialog box, you just need to overload the default message-handler function:
Overloads the default message handler, mainly handling Wm_move wm_paint wm_ncpaint wm_ncactivate wm_notify this//a few messages on it
LRESULT CMyDialog::D efwindowproc (UINT message, WPARAM WPARAM, LPARAM LPARAM) {LRESULT Lrst=CDialog::D efwindowproc (Message, WParam, LParam); if(!:: IsWindow (m_hwnd))returnLrst; if(message==wm_move| | message==wm_paint| | message==wm_ncpaint| | Message==wm_ncactivate | | Message = =wm_notify) {CDC* PWINDC =GETWINDOWDC (); if(PWINDC) drawborder (PWINDC); ReleaseDC (PWINDC); } returnLrst; //return CDialog::D efwindowproc (Message, WParam, lParam);}
//specific code for redrawing a bordervoidCMyDialog::D rawborder (CDC *PDC) { if(m_hwnd) {CBrush Brush (RGB (255,0,0)); CBrush* Poldbrush = Pdc->selectobject (&Brush); CRect Rtwnd; GetWindowRect (&Rtwnd); CPoint Point; //Fill Top FramePoint.x =rtwnd.width (); Point.y= GetSystemMetrics (sm_cyframe) +1; PDC->patblt (0,0, Point.x, Point.y, patcopy); //Fill left framePoint.x =GetSystemMetrics (sm_cxframe); Point.y=rtwnd.height (); PDC->patblt (0,0, Point.x, Point.y, patcopy); //Fill Bottom FramePoint.x =rtwnd.width (); Point.y= GetSystemMetrics (sm_cyframe) +1; PDC->patblt (0, Rtwnd.height ()-Point.y, Point.x, Point.y, patcopy); //fill the right framePoint.x =GetSystemMetrics (sm_cxframe); Point.y=rtwnd.height (); PDC->patblt (Rtwnd.width ()-point.x,0, Point.x, Point.y, patcopy); }}
< Span style= "COLOR: #cc3333" > < Span style= "COLOR: #cc3333" > < Span style= "COLOR: #cc3333" > The above code is for a dialog box, though, For the general window, a slight modification, it is also possible to estimate.
If the border color of the dialog box is not modified, you can use:
InvalidateRect (NULL); //
< Span style= "COLOR: #01ff" > < Span style= "COLOR: #cc3333" > < Span style= "COLOR: #cc3333" > < Span style= "COLOR: #cc3333" >
RedrawWindow (null, NULL, Rdw_frame | Rdw_invalidate | Rdw_erase | Rdw_updatenow | Rdw_allchildren);
< Span style= "COLOR: #cc3333" > < Span style= "COLOR: #cc3333" > < Span style= "COLOR: #01ff" > < Span style= "COLOR: #cc3333" > This should be pretty much the case.
--------------------------------------------------------------------------------------------------------------- ------
Here's how to modify the background color of the dialog box :
Overload OnPaint (), which is the WM_PAINT message. The code is as follows (the above example works):
void cexampledlgdlg::onpaint () if Else {CRect rect; CPaintDC DC (this); GetClientRect (rect); dc. Fillsolidrect (Rect,rgb (0,255,0)); //
Or call in the OnInitDialog function.
SetBackgroundColor (RGB (0,255,0));
MFC Settings dialog box background and border color