Application USES custom BMP image as a background, by modifying the OnPaint () function implementation, by modifying the OnCtlColor () function makes the static text box for transparent background, static text box refresh rate of 100 ms refresh time,
Minimization and maximize the program, all display controls start according to the refresh rate of flashing, as long as the program does not minimize will not flicker, a great god is what causes excuse me? How to change?
void CRTSDlg: : OnPaint ()
{
CPaintDC dc (this);//device context for painting
If (IsIconic ())
{
The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);
//Center icon in the client rectangle
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect rect;
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;
//Draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
The CDC dcMem.
BITMAP bm.
CRect rect;
M_Background. GetBitmap (& amp; Bm);
GetClientRect (& amp; The rect);
DcMem. CreateCompatibleDC (& amp; Dc);
CBitmap * oldbitmap=dcMem. SelectObject (& amp; M_Background);
Dc. BitBlt (0, 0, bm. BmWidth, bm. BmHeight, & amp; DcMem, 0, 0, SRCCOPY);
DcMem. SelectObject (oldbitmap);
CDialogEx: : OnPaint ();
}
}
HBRUSH CRTSDlg: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH gets=CDialogEx: : OnCtlColor (pDC, pWnd, nCtlColor);
If (CTLCOLOR_STATIC==nCtlColor)
{
The switch (pWnd - & gt; GetDlgCtrlID ())
{
Default:
PDC - & gt; SetTextColor (RGB (0, 0, 0));
PDC - & gt; SetBkMode (TRANSPARENT);
Gets=(HBRUSH) GetStockObject (NULL_BRUSH);
Return gets;
}
}
Else if (nCtlColor==CTLCOLOR_DLG)
Return m_brush;
//TODO: if the default brush is not required, it returns another brush
Return gets;
}
Minimize button code (in a variety of methods, are unable to solve the problem of flicker) :
WINDOWPLACEMENT LWNDPL;
The WINDOWPLACEMENT * LPWNDPL;
LPWNDPL=& amp; LWNDPL;
GetWindowPlacement (LPWNDPL);
LPWNDPL - & gt; ShowCmd=SW_SHOWMINIMIZED;
SetWindowPlacement (LPWNDPL);
CodePudding user response:
BOOL CxxxxDlg: : OnEraseBkgnd (pDC) CDC *{
//TODO: Add your message handler code here and/or call the default
return TRUE;//CDialog: : OnEraseBkgnd (pDC);
}
CodePudding user response:
OnPaint block in calls to the parent class function//CDialogEx: : OnPaint ();
CodePudding user response: