tom@mims-iris.waterloo.edu (Tom Haapanen) (06/22/89)
Here's another question from a Windows beginner: I'm using SetMapMode(hDC, MM_ANISOTROPIC) along with SetWindowExt() and SetViewPortExt() to transform window coordinates into constant units (I want 1000, 1000 to always be the bottom right corner). This works fine if I do a SetMapMode() etc. every time I redraw a window. However, if I only do it when the window is created (WM_CREATE message) it seems that the window extent information disappears after I do something. I've been narrowing it down, but I haven't quite found it: I have no other calls to these functions; the only other thing I can think of is GetDC() and ReleaseDC() doing something to this info. Does anyone have any ideas? If anybody is willing to look at the code, I can mail it to you (it's less than 500 lines). Thanks in advance! \tom haapanen "now, you didn't really expect tom@mims-iris.waterloo.edu my views to have anything to do watmims research group with my employer's, did you?" university of waterloo
brent@well.UUCP (Brent Southard) (06/23/89)
In article <3196@watale.waterloo.edu> tom@mims-iris.waterloo.edu (Tom Haapanen) writes: >I'm using SetMapMode(hDC, MM_ANISOTROPIC) along with SetWindowExt() and >SetViewPortExt() to transform window coordinates into constant units >(I want 1000, 1000 to always be the bottom right corner). This works >fine if I do a SetMapMode() etc. every time I redraw a window. However, >if I only do it when the window is created (WM_CREATE message) it seems >that the window extent information disappears after I do something. When you are setting non-default values for your DC, such as with SetMapMode(), SetWindowExt(), etc., they are set only during the lifetime of the DC. That is, when you release the DC, your changes are gone. I've found that it's usually easiest to put all my DC Set... calls in a function which I call immediately after each GetDC() for the window. In any case, don't try to solve the problem by keeping a DC to yourself for long periods of time, as they are system resources. brent -- brent southard (313) 656-8349 | oh mona mona ImageTech Corp (313) 362-3141 | you can close your eyes | i've got a twelve gauge surprise usenet: ...!well!brent | waiting for you -- James Taylor
marco@hpmcaa.mcm.hp.com (Marco Dalla-Gasperina) (06/23/89)
>I'm using SetMapMode(hDC, MM_ANISOTROPIC) along with SetWindowExt() and >SetViewPortExt() to transform window coordinates into constant units >(I want 1000, 1000 to always be the bottom right corner). This works >fine if I do a SetMapMode() etc. every time I redraw a window. However, >if I only do it when the window is created (WM_CREATE message) it seems >that the window extent information disappears after I do something. I've >been narrowing it down, but I haven't quite found it: I have no other >calls to these functions; the only other thing I can think of is GetDC() >and ReleaseDC() doing something to this info. > >Thanks in advance! > \tom haapanen >"now, you didn't really expect tom@mims-iris.waterloo.edu > my views to have anything to do watmims research group > with my employer's, did you?" university of waterloo >---------- Every time you do a GetDC (or BeginPaint) windows provides you with a DEFAULT DC. This is done because there is only a total of 5 DCs for the entire system. (if you do 6 GetDCs without intervening ReleaseDCs your system will appear to hang!) That means that you have to reload a DC EVERY time you get it and that includes mapping modes, extents, pens, brushes etc. There is a way around this and that is to specify CS_CLASSDC or CS_OWNDC when you register the window class. These will specify that all windows of that class will share a DC or that every window of that class wll have it's own DC, respectively. (These DCs are not counted toward the 5 of the system). Each DC takes 800 bytes (I think) so use this feature sparingly. No Bugs, marco
bturner@hpcvlx.HP.COM (Bill Turner) (06/23/89)
> I'm using SetMapMode(hDC, MM_ANISOTROPIC) along with SetWindowExt() and > SetViewPortExt() to transform window coordinates into constant units > (I want 1000, 1000 to always be the bottom right corner). This works > fine if I do a SetMapMode() etc. every time I redraw a window. Damn right. When you call GetDC (or BeginPaint, which does the same), the DC you get is initialized to the default values. (Read ANY of the Windows programming books for this.) The only exception is if you have CS_OWNDC or CS_CLASSDC in the class registration. --Bill Turner (bturner@hp-pcd.hp.com) HP Corvallis Information Systems
bturner@hpcvlx.HP.COM (Bill Turner) (06/27/89)
> Every time you do a GetDC (or BeginPaint) windows provides you with a DEFAULT > DC. This is done because there is only a total of 5 DCs for the entire system. > (if you do 6 GetDCs without intervening ReleaseDCs your system will appear to > hang!) That means that you have to reload a DC EVERY time you get it and that > includes mapping modes, extents, pens, brushes etc. Actually, it's worse than that, the system shows no effects. What happens is that, after the 5th GetDC, GetDC returns the *SAME* hDC! It doesn't crash the system, but behavior is most strange... --Bill Turner (bturner@hp-pcd.hp.com)