-
August 29th, 2011, 09:49 AM
#1
GetDC not calculating toolbar offset
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)?
Thanks!
-
August 29th, 2011, 10:11 AM
#2
Re: GetDC not calculating toolbar offset
Originally Posted by zetar
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
August 29th, 2011, 10:25 AM
#3
Re: GetDC not calculating toolbar offset
Originally Posted by VladimirF
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.
-
August 29th, 2011, 11:31 AM
#4
Re: GetDC not calculating toolbar offset
Why do you need to get a DC ? You can only draw in the OnPaint, and in it you need to declare
to create a DC. Drawing outside the OnPaint is simply the wrong way to do it.
-
August 29th, 2011, 11:43 AM
#5
Re: GetDC not calculating toolbar offset
Originally Posted by Skizmo
Why do you need to get a DC ? You can only draw in the OnPaint, and in it you need to declare
to create a DC. Drawing outside the OnPaint is simply the wrong way to do it.
That seems to be the case.
In essence, then, the 'correct' way to draw in MFC is ALWAYS on Invalidate(TRUE), yes?
Though, my OnDraw just calls UpdateDialog(pDC);
Never draw outside of UpdateDialog?
-
August 29th, 2011, 11:59 AM
#6
Re: GetDC not calculating toolbar offset
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.
-
August 29th, 2011, 12:05 PM
#7
Re: GetDC not calculating toolbar offset
Originally Posted by Skizmo
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 ().
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 by refreshing the window.
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.
Okay, so I'm beginning to get this. I was drawing outside of OnDraw / UpdateDialog. It just seemed like I was creating (and setting) a ton of global flags for what should be drawn in UpdateDialog. But, that's the only way to do it.
Thanks for setting me straight!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|