I was looking at the source of the file line.asm in m32lib and I found something curious.
At the beginning of the function it is made :
Quoteinvoke GetDC,hndl
I expected to find
QuoteINVOKE ReleaseDC,hndl,hDC
But no!
Is it a bug?
Nope, it gets an existing DC.
This is the bit that matters.
invoke SelectObject,hDC,hPenOld
invoke DeleteObject,hPen
if you want to know whether or not you need to release it, read the Remarks section for the specific function
https://msdn.microsoft.com/en-us/library/dd144871%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/dd144871%28v=vs.85%29.aspx)
QuoteAfter painting with a common DC, the ReleaseDC function must be called to release the DC.
Class and private DCs do not have to be released.
as you can see, it depends on how the DC was defined when the window class was registered
the default type is common, so it is potentially a bug
i have never ran across this problem
the reason is, i have never used the masm32 line function :P
if i want to paint a line that way, i generally do it when handling WM_PAINT
BeginPaint gives you a DC to work with
but, i almost always create a memory DC to draw into, then BitBlt from the memory DC to the display DC
this is one of the steps used to avoid flicker
so - having called CreateCompatibleDC, i always call DeleteDC when i am done with it
Quote from: dedndave on December 11, 2015, 04:27:15 AM
if you want to know whether or not you need to release it, read the Remarks section for the specific function
https://msdn.microsoft.com/en-us/library/dd144871%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/dd144871%28v=vs.85%29.aspx)
QuoteAfter painting with a common DC, the ReleaseDC function must be called to release the DC.
Class and private DCs do not have to be released.
as you can see, it depends on how the DC was defined when the window class was registered
the default type is common, so it is potentially a bug
Ok, so what's a 'DC'? Around here, everyone thinks of it as the capital of this country.
Perhaps you should read what is in the link you have posted.
The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.
Device Context
https://msdn.microsoft.com/en-us/library/dd183553%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/dd183553%28v=vs.85%29.aspx)
(http://vignette3.wikia.nocookie.net/matrix/images/a/ad/Matrix_Wiki_Construct.png/revision/latest?cb=20120808051804)
Quote
Device independence is one of the chief features of Microsoft Windows. Applications can draw and print output on a variety of devices. The software that supports this device independence is contained in two dynamic-link libraries. The first, Gdi.dll, is referred to as the graphics device interface (GDI); the second is referred to as a device driver. The name of the second depends on the device where the application draws output. For example, if the application draws output in the client area of its window on a VGA display, this library is Vga.dll; if the application prints output on an Epson FX-80 printer, this library is Epson9.dll.
Now it's clear
2 main types of DC's:
1) physical DC's - display, printer, etc
2) virtual DC's - memory DC's
performing operations into a memory DC is quite fast
and, it helps to reduce flicker if you draw into a memory DC, then BitBlt the results into the display DC
Quote from: dedndave on December 17, 2015, 06:02:49 AM
2 main types of DC's:
1) physical DC's - display, printer, etc
2) virtual DC's - memory DC's
performing operations into a memory DC is quite fast
and, it helps to reduce flicker if you draw into a memory DC, then BitBlt the results into the display DC
Well, I guess that answers that folks. Thanks.