A couple of questions...
-
Hi there, I posted previously about GDI objects and how I should be dealing with them. Well someone said something (which I have implemented thereafter) about deselecting the objects used in a
DC
"session". In order to understand what I mean byDC
session, we'll have to consider the following:void CClass::MyPaintProc(...)
{
CDC *pDC;pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); **pOldPen** = pDC -> SelectObject(myPen); **pOldBrush** = pDC -> SelectObject(myBrush); . : . **pDC -> SelectObject(pOldPen);** // does one need to do this? **pDC -> SelectObject(pOldBrush);** // ReleaseDC(pDC); delete pDC;
}
What is the purpose of de-selecting the GDI objects? I really would like to know the reason behind it... Now as for the second question. Is there any way of making the main thread (the app) receive and translate the keyboard accelerators which activate the menus regardless of the window that has the focus? I've tried using
TranslateAccelerator
but couldn't solve it. And the third and final question... hope you're not bored just as yet :). How can I get aCRegion
(or something similar that Windows understands) of the visible area of the client area of a window? Imagine a dialog box hovering partially over a control. How can I know the visible area of the control? For just being brave enough to take the time to read through all this, I thank you. David -
Hi there, I posted previously about GDI objects and how I should be dealing with them. Well someone said something (which I have implemented thereafter) about deselecting the objects used in a
DC
"session". In order to understand what I mean byDC
session, we'll have to consider the following:void CClass::MyPaintProc(...)
{
CDC *pDC;pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); **pOldPen** = pDC -> SelectObject(myPen); **pOldBrush** = pDC -> SelectObject(myBrush); . : . **pDC -> SelectObject(pOldPen);** // does one need to do this? **pDC -> SelectObject(pOldBrush);** // ReleaseDC(pDC); delete pDC;
}
What is the purpose of de-selecting the GDI objects? I really would like to know the reason behind it... Now as for the second question. Is there any way of making the main thread (the app) receive and translate the keyboard accelerators which activate the menus regardless of the window that has the focus? I've tried using
TranslateAccelerator
but couldn't solve it. And the third and final question... hope you're not bored just as yet :). How can I get aCRegion
(or something similar that Windows understands) of the visible area of the client area of a window? Imagine a dialog box hovering partially over a control. How can I know the visible area of the control? For just being brave enough to take the time to read through all this, I thank you. DaviddNimrod#X wrote: What is the purpose of de-selecting the GDI objects? The Windows docs state that you should release the DC in the same state as it was when you got it, ie. it should have all the same GDI objects selected, ideally the same mapping mode, background colour etc. Most of the time, Windows can handle any changes, but sometimes it falls over in a giant steaming heap :) dNimrod#X wrote: CDC *pDC; pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); What is the reason for doing this? Why not just do
CDC *pDC = GetDC();
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
dNimrod#X wrote: What is the purpose of de-selecting the GDI objects? The Windows docs state that you should release the DC in the same state as it was when you got it, ie. it should have all the same GDI objects selected, ideally the same mapping mode, background colour etc. Most of the time, Windows can handle any changes, but sometimes it falls over in a giant steaming heap :) dNimrod#X wrote: CDC *pDC; pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); What is the reason for doing this? Why not just do
CDC *pDC = GetDC();
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Ryan Binns wrote: CDC *pDC = GetDC(); So this should be enough, do you think? Hmmm... I've always liked to complicate what's simple by nature... Thanks for the tip! :-D What about the other questions? Can you think of anything?
-
Ryan Binns wrote: CDC *pDC = GetDC(); So this should be enough, do you think? Hmmm... I've always liked to complicate what's simple by nature... Thanks for the tip! :-D What about the other questions? Can you think of anything?
Actually, you should use CClientDC instead of manual GetDC/ReleaseDC calls. It will call these functions for you in its constructor and destructor. Similarly, you can use CPaintDC in WM_PAINT-handling code. Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!