News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GDI leak driving me nuts

Started by NoCforMe, October 09, 2023, 03:46:56 PM

Previous topic - Next topic

Greenhorn

Quote from: NoCforMe on October 10, 2023, 05:19:05 AM
Quote from: _japheth on October 09, 2023, 10:37:13 PMAnd b), your dialog proc is supposed to exit by calling EndDialog(), not by calling PostQuitMessage().
No, that's not correct, at least by empirical evidence. Perhaps it's a special case, since my dialog is the main window (i.e., I'm not invoking the dialog from another window but from my WinMain() procedure), but EndDialog() will indeed end the dialog but not the program, which remains stranded until closed by Task Manager. So PostQuitMessage() is indeed the correct thing here. It's what I've been doing in all my programs that are built as dialog-as-main-window since forever.

Japheth's statement is correct. I have several applications which use a Dialog Box as the main window and no problems with exiting the process.
Just call EndDialog, hWin, TRUE and in WinMain return the return value of DialogBox... function.
I trtied it in your application (and removed the useless message pump) and it works properly.  :thumbsup:
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

NoCforMe

Quote from: Greenhorn on October 10, 2023, 07:13:34 AMSometimes one does not see the forest for the trees ...  :greensml:

INVOKE    EndPaint, hWin, ADDR ps

That was it. Bingo.

You, esteemed coder, win the grand debugging prize. (As well as the careful-reading prize.) The GDI object count climbs up just a little bit (47 in my trial) and stays there.

My hat is off to you!
Assembly language programming should be fun. That's why I do it.

NoCforMe

I want to thank the congregation here for helping me and for solving this problem. I learned two things:

1. The message loop I have in all my dialog-as-main-window programs is totally unnecessary. I'll be getting rid of them.

2. Don't miss the forest for the trees.

Thanks again!
Assembly language programming should be fun. That's why I do it.

jj2007

Congrats, Greenhorn - you spotted what nobody else saw :thumbsup:

I had a suspicion that it was the DC - see line 62 of the attached code above: there was no leak with CS_OWNDC (meaning Windows reused it all the time, and didn't mind that it was recreated a hundred times with BeginPaint).