PowerBuilder picturebutton masking under windows 32

what we have what we want

In PowerBuilder version 7.0.3 build 10135 and higher this problem can be solved by transparent GIF pictures.
But if you still interested in it, here it is.

Idea:

The style of picture button in powerbuilder is BS_OWNERDRAW. The owner window or userobject receives a WM_MEASUREITEM message when the button is created and a WM_DRAWITEM message when a visual aspect of the button has changed.

We can trigger WM_DRAWITEM event for the owner window (or userobject) to draw a picture button into our bitmap (not to the screen).

Now we can convert a bitmap to an icon, then change the style of the picturebutton from BS_OWNERDRAW to BS_ICON, and set this icon to be displayed in our picturebutton.

We need an Icon to be sure that disabled icon will be shown in a right way.

I found some limitation. It depends on operation system, video card, etc. The creation of large size icons will fail. I found this limitation for windows 98. The maximum size of the icon ~ 30000 points. 300 x 100 pixels.


Here is realization of this algorithm (not the best one, but workable).

n_picture_masker.sru
This object is autoinstantiated so you don't need to create and destroy it. It have only two public methods:

boolean f_SetMask(pictureObject) //converts usual picturebutton to icon button
boolean f_Reset(pictureObject) //converts icon button back to picturebutton
where pictureObject can be Picture or PictureButton

I think for better performance just declare it as shared variable in your custom picturebutton and call f_SetMask(this) on constructor event and f_Reset(this) on destructor.

Copyright by Dmitry Lukyanov


top | control panel