Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

WM_CTLCOLORBTN GDI Leak

Hello,
In the last couple of days i have been testing my application for GDI Leaks, and i have a strange problem. When i return my brush to the system from the WM_CTLCOLORBTN message, all the buttons to which is call is associated show leaks, when i draw the mouse over them, here how i call it

[color=Purple]case WM_CTLCOLORBTN :
bgColor = RGB(061, 067, 113);
return (LRESULT) CreateSolidBrush (bgColor) ;
[/color]
if i call it
[color=Purple]
case WM_CTLCOLORBTN :
hBrush = CreateSolidBrush (RGB(61, 67, 113)) ;
return (LRESULT) hBrush ;
[/color]
its still the same, i called function DeleteBrush() before returning the brush just to test it, and sure enough the leaks stopped, i cannot delete the brush after it is returned. i read somewhere that you can avoid it by setting up the GDI Objects in the WM_CREATE or WM_INITDIALOG call, then releasing them on WM_DESTROY, but this just makes my application crash on startup. i would appreciate any help on this truly weird matter. If there is any more information i can offer, please let me know.
Thankyou
James


Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hello,
    : In the last couple of days i have been testing my application for
    : GDI Leaks, and i have a strange problem. When i return my brush to
    : the system from the WM_CTLCOLORBTN message, all the buttons to which
    : is call is associated show leaks, when i draw the mouse over them,
    : here how i call it
    :
    : [color=Purple]case WM_CTLCOLORBTN :
    : bgColor = RGB(061, 067, 113);
    : return (LRESULT) CreateSolidBrush (bgColor) ;
    : [/color]
    : if i call it
    : [color=Purple]
    : case WM_CTLCOLORBTN :
    : hBrush = CreateSolidBrush (RGB(61, 67, 113)) ;
    : return (LRESULT) hBrush ;
    : [/color]
    : its still the same, i called function DeleteBrush() before returning
    : the brush just to test it, and sure enough the leaks stopped, i
    : cannot delete the brush after it is returned. i read somewhere that
    : you can avoid it by setting up the GDI Objects in the WM_CREATE or
    : WM_INITDIALOG call, then releasing them on WM_DESTROY, but this just
    : makes my application crash on startup. i would appreciate any help
    : on this truly weird matter. If there is any more information i can
    : offer, please let me know.
    : Thankyou
    : James
    :
    :
    :
    [color=Blue]The code you posted is basically a leak. The proper way to do it is create your brushes in WM_CREATE or WM_INITDIALOG just like you describing. You should investigate the crashes happening if you do that. Can you post your code for WM_CREATE message? I do it always in this manner - no crashes.[/color]
  • SlipstreamSlipstream Member Posts: 3
    Hi, Thanks for your help, i've attached the WM_CREATE message as it would of been abit too long to post here, your'll have to excuse its very messy
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi, Thanks for your help, i've attached the WM_CREATE message as it
    : would of been abit too long to post here, your'll have to excuse its
    : very messy
    :
    [color=Blue]I can't open this RAR - it says: "unexpected end of archive...".

    You can send it to me to 'asmguru62@hotmail.com' - I'll take a look.[/color]
  • SlipstreamSlipstream Member Posts: 3
    Hello AsmGuru62,
    I emailed the WM_CREATE message to you yesterday, though some of my email settings may have been incorrect so im not sure if you got it, If you haven't got it give me a nudge, and ill resend it
    Best Regards
    James
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    I responded just now.
    So, where is the actual code creating brushes?
Sign In or Register to comment.