The graphic button PM window class WC_GRAPHICBUTTON is similar to the window class of a push button. This window class must be registered with the function WinRegisterGraphicButton before you can create a graphic button.
A graphic button can be created by a CONTROL statement in a dialog resource. A graphic button also can be created by specifying the WC_GRAPHICBUTTON window class parameter of the WinCreateWindow call.
The graphic button should be initialized when its owner receives a WM_INITDLG message. By doing the initializations at this time, the owner has the capability to change the graphic button's bitmaps, text positioning, state, animation rate, and so on, before the button is displayed on the screen.
The GBTNCDATA data structure shown below is the data structure that is allocated to initialize graphic button control data. This structure is required when sending the GBM_SETGRAPHICDATA message.
Note: If you create a graphic button with WinCreateWindow and initialize the GBTNCDATA structure; set the usReserved field to GB_STRUCTURE, rather than GB_RESOURCE, to indicate the structure contains a module handle.
typedef struct _GBTNCDATA { USHORT usReserved; /* Reserved */ PSZ pszText; /* Initial graphic button text */ HMODULE hmod; /* Handle of bitmap resource */ USHORT cBitmaps; /* Number of button bitmaps */ USHORT aidBitmap[1]; /* Array of bitmap resource IDs */ } GBTNCDATA;
Graphic button data is set or changed by sending the GBM_SETGRAPHICDATA message with WinSendMsg to the graphic button control window procedure. Using this message to change graphic button data erases any data relating to the button state and sets the button state to the default parameters. The default state of a graphic button is "up." If you want to change only the text of the graphic button without affecting the button state data, use WinSetWindowText.
Mnemonics are supported for graphic button text. As with push buttons, a character in the text is designated as the mnemonic for the button by a preceding tilde (~) character. If the button does not have any text, a null string must be specified.
The number specified for bitmaps associated with the graphic button does not necessarily represent the number of unique bitmaps. A graphic button can have duplicate bitmaps associated with it for animation purposes.
It is assumed that all the bitmaps associated with a particular graphic button are of equal size. The size of a graphic button is determined by the dimensions specified in the CONTROL statement of the dialog resource, as well as the size of the bitmap. If the dimensions in the CONTROL statement are too small to contain the bitmap and the text, the button size is made larger to accommodate the width of the bitmap and the depth of the bitmap plus the text. However, if the width of the text exceeds the width determined by the specified dimensions or the actual bitmap (whichever is greater), the text is truncated.