image is not redrawed sometimes when I bring my window to foregrou
I use the following Repaint function to redraw my image
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
HWND hWnd;
GetDlgItem(IDC_PREVIEW_WINDOW, &hWnd);
PAINTSTRUCT ps;
HDC hdc;
RECT rcClient;
::GetClientRect(hWnd, &rcClient);
hdc = ::BeginPaint(hWnd, &ps);
if(m_pWC)
m_pWC->RepaintVideo(hWnd, hdc);
::EndPaint(hWnd, &ps);
CDialog::OnPaint();
}
m_pWC is non zero after initialization.
for safety, I added OnActivate function
CDialog::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
if(nState != WA_INACTIVE)
UpdateWindow();
It doesn't seem UpdateWindow repaints window immediately.
Any better solution?