I have an app with a floating / docking toolbar. This is a pretty big program. Recently I've added a new function that comes off of the toolbar. This involves some screen draws and screen captures. However, when I do a
pDC = GetDC();
and then
pDC->MoveTo(p1.x, p1.y);
pDC->LineTo(p2.x, p2.y);
the drawing is off, on the Y axis by the height of the toolbar! In other words, the offset of the toolbar to the screen is not being calculated. This is only happening in the 'new function'.
Anybody have any ideas (other than adding 60 to the Y of every call)?
Anybody have any ideas (other than adding 60 to the Y of every call)?
What window are you drawing on? What is its relationship with toolbar window?
My guess is - you are drawing on the wrong window.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...
What window are you drawing on? What is its relationship with toolbar window?
My guess is - you are drawing on the wrong window.
I'm pretty sure I'm drawing to the right window. I've also tried
pDC = GetWindowDC();
with the same problems.
How would I know if I'm drawing to the wrong window? It seems to be the same window. I can move it around and stuff. Also, if I move the tool bar from the top of the window to the bottom of the window the drawing matches exactly. All my 'new' draw calls are off by exactly the height of the toolbar.
OnDraw for views, instead of OnPaint for dialogs. The OnDraw function gives you the drawing DC as a parameter of the function, so my question stands, why the GetDC ().
In essence, then, the 'correct' way to draw in MFC is ALWAYS on Invalidate(TRUE), yes?
Yes. A window (or view) has only 1 paint function that is doing all the work. If you draw something in another function the OnPaint/OnDraw function automatically overrules that when the window is refreshed.
Though, my OnDraw just calls UpdateDialog(pDC);
Never draw outside of UpdateDialog?
I don't use view that much so I don't know the UpdateDialog call, but your own drawing stuff can be done in the OnDraw itself.
Last edited by Skizmo; August 29th, 2011 at 12:02 PM.
Bookmarks