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();
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)?
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.