Re: Owner draw repaint
- From: Tage Korsdal Nielsen <tkn@xxxxxxxxxx>
- Date: Wed, 16 Jan 2008 09:22:40 +0100
I'm drawing in response to WM_PAINT and WM_SIZE. See code below.
It works all well, as long as I do not drag another window over my app.
I just found something strange: If I drag "Windows Live Messenger" over my app it never fails to update correctly. With another Mfc app of mine it _can_ fail at rare occasions. With "Skype" however, the phenomenen reveals itself more often!!??
void CTankToolDlg::OnPaint()
{
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
{
CPaintDC dc( this );
DrawCoord( &dc );
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTankToolDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CTankToolDlg::DrawCoord(CPaintDC *dc)
{
COLORREF bkColor( 0xf0f0f0 );
CBrush coordBrush( bkColor );
CBrush *pOldBrush = dc->SelectObject( &coordBrush );
CRect rect;
COLORREF oldColor = dc->GetBkColor();
dc->SetBkColor( bkColor );
GetClientRect( &rect );
mCoordLeft = rect.left + 60;
mCoordRight = rect.right - 10;
mCoordTop = rect.top + 90;
mCoordBottom = rect.bottom - 30;
mCoordHeight = mCoordBottom - mCoordTop;
mCoordWidth = mCoordRight - mCoordLeft;
dc->Rectangle( mCoordLeft, mCoordTop, mCoordRight, mCoordBottom );
CPen pen( PS_DOT, 1, ( COLORREF ) 0 );
CPen *pOldPen = dc->SelectObject( &pen );
for( int n = 1; n < 10; n++ )
{
dc->MoveTo( mCoordLeft, mCoordBottom - ( mCoordHeight / 10 ) * n );
dc->LineTo( mCoordRight, mCoordBottom - ( mCoordHeight / 10 ) * n );
}
dc->SetBkColor( oldColor );
dc->SelectObject( pOldPen );
dc->SelectObject( pOldBrush );
}
void CTankToolDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CPaintDC dc( this );
DrawCoord( &dc );
RedrawWindow();
}
Jonathan Wood skrev:
It's owner-draw if you are calling the graphic methods/functions from your code..
You need to ensure you are drawing in response to WM_PAINT, such as in OnPaint(). You've said nothing about when or where you are drawing so it's not possible to determine what the problem is. Perhaps you can provide more information.
- Follow-Ups:
- Re: Owner draw repaint
- From: Scott McPhillips [MVP]
- Re: Owner draw repaint
- From: David Webber
- Re: Owner draw repaint
- References:
- Owner draw repaint
- From: Tage Korsdal Nielsen
- Re: Owner draw repaint
- From: Jonathan Wood
- Owner draw repaint
- Prev by Date: Re: Can I Increase size of nNoMansLandSize?
- Next by Date: Re: Linker cannot find CFrameWnd::_GetBaseMessageMap
- Previous by thread: Re: Owner draw repaint
- Next by thread: Re: Owner draw repaint
- Index(es):
Relevant Pages
|