Re: Owner draw repaint

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.

.



Relevant Pages

  • Re: Search for component which makes drag & drop possible
    ... if your doing this with in the same app then you should be able to us ... a window to accept A drag and drop of a name string. ...
    (alt.comp.lang.borland-delphi)
  • Re: Office 2007: wot a pile of shite
    ... or have more than one window. ... Personally when I close an app I want ... if you could drag an app to the Dock without it staying there ...
    (uk.comp.sys.mac)
  • Re: Improving X 2D performance?
    ... > an app in front of a terminal, I can see the text on the terminal ... > the window drag becomes very draggy. ... it scans the window contents for something ... Since X doesn't do font rendering, ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Office 2007: wot a pile of shite
    ... or have more than one window. ... When an app can have more than one window open, ... if you could drag an app to the Dock without it staying there ...
    (uk.comp.sys.mac)
  • Wierd problems with IDropTarget...
    ... writing in Win32 API code, latest Platform SDK etc), but I can't seem to ... but the actual drag and drop operation doesn’t want to work. ... I even have to quit my app to get things rolling again. ... When I worked this out, I thought, maybe the class style or window style ...
    (microsoft.public.win32.programmer.ole)