- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am drawing lines in different colours and text in different sizes on the screen in Windows NT using CreateFont, CreatePen, SelectObject & DeleteObject. The lines and text are drawn correctly.
On Windows 95, the colours start correct then are all drawn in the same colour, and the text is either not drawn or is drawn in the wrong size.
Does anyone know what could be causing this?
I think it could be to do with handles, I am sure I match the Create/Select with a Delete, is there any way I can check on the number of handles used/available?
Thanks.
David
On Windows 95, the colours start correct then are all drawn in the same colour, and the text is either not drawn or is drawn in the wrong size.
Does anyone know what could be causing this?
I think it could be to do with handles, I am sure I match the Create/Select with a Delete, is there any way I can check on the number of handles used/available?
Thanks.
David
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's hard to tell without deeper investigation. Windows 95 tend to have
problems with resource leak due to (quote someone from comp.os.ms-windows.programmer.win32) "brain-dead design". Here are a few
clues:
a) Have in mind that each object first has to be deselected from
DC (using SelectObject(), preferrably with handle of default object)
before DeleteObject. The docs on DeleteObject says
If the function succeeds, the return value is nonzero.
If the specified handle is not valid or is currently selected into a device context, the return value is zero.
So, it might be a good idea to test return value of DeleteObject.
b) Try to put a GetLastError after some Create and set a
breakpoint if it returns something other than 0. Value of
error code may give you an idea why the function failed.
c) Try to run a GDI resource monitor and see the occupation
of GDI memory during program execution (I used System Monitor
from Norton Utilities). You can generate WM_PAINT messages
by simply "Alt-Tabbing" between your application and another.
d) Last but not the least -- Visual Studio 5 (don't know if 6)
causes GDI memory leak under Win9x. Try it using method c. Maybe
it doesn't happen when your application is run stand-alone?
HTH
Jugoslav
problems with resource leak due to (quote someone from comp.os.ms-windows.programmer.win32) "brain-dead design". Here are a few
clues:
a) Have in mind that each object first has to be deselected from
DC (using SelectObject(), preferrably with handle of default object)
before DeleteObject. The docs on DeleteObject says
If the function succeeds, the return value is nonzero.
If the specified handle is not valid or is currently selected into a device context, the return value is zero.
So, it might be a good idea to test return value of DeleteObject.
b) Try to put a GetLastError after some Create and set a
breakpoint if it returns something other than 0. Value of
error code may give you an idea why the function failed.
c) Try to run a GDI resource monitor and see the occupation
of GDI memory during program execution (I used System Monitor
from Norton Utilities). You can generate WM_PAINT messages
by simply "Alt-Tabbing" between your application and another.
d) Last but not the least -- Visual Studio 5 (don't know if 6)
causes GDI memory leak under Win9x. Try it using method c. Maybe
it doesn't happen when your application is run stand-alone?
HTH
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
Thanks for the help, I had been making the calls Create - Select - - - - Delete, but not making another Select Call before the Delete, see your code below.
hPen=CreatePen(xP%iStyle,xP%iWidth,xP%iColor)
hDefPen=SelectObject(xDC%hDC,hPen)
CALL XView2Client(xDC,iX,iY,jX,jY)
XLineTo=MSFWIN$LineTo(xDC%hDC,jX,jY)
iSt=SelectObject(xDC%hDC,hDefPen) ! I missed out this call !!
bSt=DeleteObject(hPen)
Thanks again,
David
Thanks for the help, I had been making the calls Create - Select - - - - Delete, but not making another Select Call before the Delete, see your code below.
hPen=CreatePen(xP%iStyle,xP%iWidth,xP%iColor)
hDefPen=SelectObject(xDC%hDC,hPen)
CALL XView2Client(xDC,iX,iY,jX,jY)
XLineTo=MSFWIN$LineTo(xDC%hDC,jX,jY)
iSt=SelectObject(xDC%hDC,hDefPen) ! I missed out this call !!
bSt=DeleteObject(hPen)
Thanks again,
David

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page