|
-
May 2nd, 2001, 03:32 AM
#1
Thread Starter
PowerPoster
SelectObject API function
Juz a stupid Q, and take a look the code shown below:
Code:
Dim hdc As Long
Dim hPen As Long
Dim hOldPen As Long
Dim pt As POINTAPI
hdc = GetDC(Form1.hwnd)
hPen = CreatePen(PS_SOLID, RGB(0, 255, 255))
hOldPen = SelectObject(hdc, hPen)
Polyline hdc, pt(0), 5
SelectObject hdc, hOldPen
DeleteObject hPen
ReleaseDC Form1.hwnd, hdc
Why there is a need to restore the old pen object into the device Context (DC)? What will happen if I does not restore it?
-
May 2nd, 2001, 04:23 AM
#2
A simple test for you:
Take out the restore pen code, then call the sub 1000000 times. Eventually you will run out of GDI handles, and the painting of all windows will go haywire 
Basically, you need to restore the handles to pens and other objects just so your app doens't chew up all the avaialble system handles. It's annoying, but the consequences if you don't are even more annoying.
- gaffa
-
May 2nd, 2001, 04:26 AM
#3
Thread Starter
PowerPoster
Thanks gaffa, I felt that after I change my code to restore the original pen object and now my app doesn't eat up all my memory
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|