The combination of SelectObject() and DeleteObject() are done for a reason, behind the GDI functions...
Hutch,
There are no contradictions to what you are writing:
All you need to reset is the stuff returned from SelectObject (except regions), for the reasons outlined above. At least, all these GDI docs were written at the same time, and the only one that mentions it is SelectObject.
We all agree on that, and it's also pretty obvious that e.g. SetTextColor and SetBkColor don't fall into this category. Interesting adeyblue's point on regions btw.
What is less obvious is the habit of carefully destroying objects before throwing them into the dustbin of ExitProcess. The documentation is somewhat vague on this point, unfortunately. It would be in the good tradition of the Masm32 Forum to test it empirically, by launching a Million little apps and testing if
- fonts
- bitmaps
- system strings
- GlobalAllocs
- VirtualAllocs
- ...
all belong to the same category "gone once the process is gone", or whether some belong to the category "global resources, to be treated differently". This is badly documented by Microsoft, and my own experience tells me that, in contrast to the rule "process dead means all memory is released", it's not that simple. For example, badly crashing an app that has hundreds of megabytes heapalloc'ed may result in slowing down the system - which is illogical because Windows
should clean up the mess but... ::)
And again, the question is whether this is limited to processes that are ended "exceptionally" (pun intended), and whether the same can happen with ExitProcess, too (which I doubt, but damn, where is the documentation that treats this in non-ambiguous language??).
The same doubts I have on fonts, because I have seen occasionally that after heavy testing the whole system had difficulties with fonts. If Notepad uses SYSTEM_FIXED_FONT in menus, then something has gone wrong. It shouldn't, with an OS that claims to safely separate all applications since the days of NT, but it does happen.