Fixing Window Region Memory Leak



The code below is used to create a transparent window region around some
controls on a form -- it works just fine.

Everytime I execute the code below however, I'm eating some serious GDI
resources due to an apparent memory leak. My guess is that it's because I'm
creating a number of separate instances of TmpRegn through repeated use of
CreateRectRgn in the for loop, and my cleanup code only removes the most
recent one???

What's a better way to handle this? Make an array of TmpRegn??

Evan



Dim Regn As Long
Dim TmpRegn As Long
Dim TmpControl As Control

'makes everything invisible
Regn = CreateRectRgn(0, 0, 0, 0)

'A loop to check every control in the form
For Each TmpControl In Me
'Create a rectangular region with its parameters
If TmpControl.Visible = True And TmpControl.Width <> 0 Then
TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top,
TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height)
'Combines the regions
CombineRgn Regn, Regn, TmpRegn, RGN_XOR
End If
Next TmpControl

'Make the regions
SetWindowRgn Me.hWnd, Regn, True
DeleteObject (Regn)
DeleteObject (TmpRegn)


.



Relevant Pages

  • Re: Fixing Window Region Memory Leak
    ... Just cleaning up the TmpRegn in the scope of the for loop fixed it up. ... Dim TmpRegn As Long ... Dim TmpControl As Control ...
    (microsoft.public.vb.winapi.graphics)
  • Re: IE sequencing and cookie notification popups
    ... ' 10Apr04: accept cookies from hotmail. ... Dim SetWindowLong ' as object ... Const sDlgCaption = " Kookie Kruncher, ... ' notifications associated with that type of control. ...
    (microsoft.public.scripting.vbscript)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.win2000.termserv.clients)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.windows.terminal_services)
  • Re: Concatenated text and Lebans Rich Text Control
    ... know of any way to simulate one using your control? ... PlainText and RTFtext. ... Dim strColor As String ... Set rtfAdd = Me!rtf_Add.Object 'Set object for rtf add control ...
    (microsoft.public.access.forms)