Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Colours & Text with Windows NT & 95

davidgraham
Beginner
612 Views
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
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
612 Views
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
0 Kudos
davidgraham
Beginner
612 Views
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
0 Kudos
Reply