News:

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

Main Menu

Static controls, manifests & STM_SETIMAGE quirk

Started by fearless, December 30, 2012, 02:37:27 AM

Previous topic - Next topic

fearless

Hi,

I made a little spinner control recently, just uploaded it here: http://masm32.com/board/index.php?topic=1179.msg11375#msg11375

Whilst developing it i ran into a number of interesting issues.

First was the way in which i developed it originally as a new class. I added all my code, and ran it, nothing showed up. I realised that i would have to handle the painting as STM_SETIMAGE is handled by a static control with the SS_BITMAP style. So i changed the code to superclass it, letting the static control do the default handling of the STM_SETIMAGE for each call. All seemed good, so went ahead and make a 2nd example, and decided to add a manifest to it.

Running it with the manifest showed nothing. Disabling manifest and recompiling showed the spinner image spinning. Odd i thought. So added WM_PAINT handler to draw the bitmap. Recompiled with manifest - all working, happy days.

I thought, ok, so my STM_SETIMAGE code is now redundant, dont need it, so comment it out, leave the increment to next step code in, recompile, and... nothing showed up.

Short version: I needed both STM_SETIMAGE code calls and WM_PAINT handling of bitmaps to allow the example to work with or without a manifest.

I presume there is some change in the way statics are handled with the common controls with a manifest included vs the old way windows handled it?

Ideally i would like the custom control to be independent of sub or super classing, and handling the painting itself, but tbh, i dont know enough about that to do it justice. It does sort of work now - except i havent tested it on winxp - which does have a memory leak issue when using STM_SETIMAGE - only have win7 64bit at the mo.

So if anyone wants to help out fix it up or test it out for me or has some ideas of the above issue (maybe my coding is wrong somewhere) please feel free to add any thoughts, comments, code examples, ideas or whatnot. Otherwise enjoy, hopefully someone will find it useful.

Cheers.

dedndave

the static control may have different hierarchy under different OS's and using different versions of common controls
you can use WinSpy (Spy++) to see how the windows/controls are put together under different conditions

http://mdb-blog.blogspot.com/2010/11/microsoft-spy-or-spyxx-for-download.html

truthfully, if you are handling the "set image" function, and the paint operation,
you will be ahead of the game to just create your own class, rather than subclassing
you are already doing most of the work   :biggrin:
all you need is auto-size, which should be pretty easy

as for the leask issue...
QuoteIn version 6 of the Microsoft Win32 controls, a bitmap passed to a static control using the STM_SETIMAGE message was the same bitmap returned by a subsequent STM_SETIMAGE message. The client is responsible to delete any bitmap sent to a static control.

With Windows XP, if the bitmap passed in the STM_SETIMAGE message contains pixels with nonzero alpha, the static control takes a copy of the bitmap. This copied bitmap is returned by the next STM_SETIMAGE message. The client code may independently track the bitmaps passed to the static control, but if it does not check and release the bitmaps returned from STM_SETIMAGE messages, the bitmaps are leaked.

a function you may find useful...
TransparentBlt
you need to add msimg32.inc/msimg32.lib to the includes
or, you can use
GdiTransparentBlt
although, that seems silly, as it calls TransparentBlt


dedndave


fearless

Cheers dave, ill take a looksee at that Spy thingy. Lol, i was away playing arma2 wasteland tonight, so didnt get a chance to check the forums. Yeh the leak thing i remember, and i havnt put any code in to adjust for someone running the spinner on xp yet, as i dont have xp for the mo to test it, but hopefully soon - just to get the laptop that has xp pro on it back from my bro.