Re: image is not redrawed sometimes when I bring my window to foregrou
I doubt that your call to UpdateWindow is even necessary, but if you use it
you must call Invalidate first. UpdateWindow does nothing if the invalidate
region is empty.
Also, you are calling UpdateWindow on the dialog, not the control. But it
looks like your problem is actually with the control (i.e. the image). So
you may be updating the wrong window.
Finally, the whole concept of repainting the control using the dialog DC is
wrong. The control should be repainted in the control's OnPaint, not the
dialog's OnPaint. Furthermore, by calling BeginPaint/EndPaint in the
dialog, and then calling CDialog::OnPaint, what you have done is validate
the dialog, so the subsequent CDialog::OnPaint is not going to do anything
since you emptied its update region.
If you don't understand the concepts of invalidating and validating the
update region then study the BeginPaint/EndPaint documentation. Then
redesign your whole approach. The standard wizard-provided code should work
fine in the dialog, and then you need to either Invalidate and UpdateWindow
the control and/or improve its OnPaint code.
"Kai" <Kai@discussions.microsoft.com> wrote in message
news:4FD7716D-2975-45B6-8B20-DC7574DB9BF7@microsoft.com...
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?
--
Scott McPhillips [VC++ MVP]