The following code fragment is a sample definition for creating an animated graphic button with a CONTROL statement in a dialog resource.
CONTROL "", IDD_TESTPLAY1, 120, 70, 45, 35, WC_GRAPHICBUTTON, GBS_AUTOANIMATION | GBS_3D_TEXTRAISED | WS_VISIBLE | WS_TABSTOP CTLDATA GB_RESOURCE, "PLAY", 16, ID_PLAY1, ID_PLAY 2, ID_PLAY3, ID_PLAY4, ID_PLAY5, ID_PLAY6, ID_PLAY7, ID_PLAY8, ID_PLAY9, ID_PLAY10, ID_PLAY11, ID_PLAY12, ID_PLAY13, ID_PLAY14, ID_PLAY15, ID_PLAY16, 0
The control data for the graphic button provides the text "PLAY" (with no mnemonic) for the button face and associates the names of 16 bitmaps with the button. The bitmaps are assigned indexes 1 through 16, according to the order they appear in the control data.
The list of bitmap IDs is preceded by a number and ends with a zero. The number indicates the total of defined bitmaps. The zero indicates the end of the bitmap array. The number of bitmaps that actually are displayed is determined by the bitmap total or the zero-terminated array, whichever is less. If the number of bitmap IDs is greater than the bitmap total, the extraneous bitmap IDs are ignored. A bitmap cannot have an ID of zero.
Because the style of this graphic button includes GBS_AUTOANIMATION, when the user clicks on this button, it automatically toggles the animation on or off without intervention from the owner window of the graphic button.
An animated graphic button can also be created by specifying the WS_GRAPHICBUTTON window class name as a parameter of the WinCreateWindow call. The following code fragment shows an example of setting up the GBTNCDATA structure with the graphic button data and using the WinCreateWindow call.
HWND hwndGB; /* Graphic button window handle */ PGBTNCDATA pgbtn; /* Pointer to graphic button data */ LONG lSize; /* Size of graphic data */ #define NUMBITMAPS 4 /* Number of bitmaps for button */ lSize = sizeof(GBTNCDATA) + sizeof(USHORT) * (NUMBITMAPS - 1); pgbtn = (PGBTNCDATA)malloc(lSize); if (pgbtn) { memset(pgbtn, 0, lSize); pgbtnpszText = "Text"; pgbtncBitmaps = NUMBITMAPS; pgbtnaidBitmap[0] = BMP0; pgbtnaidBitmap[1] = BMP1; pgbtnaidBitmap[2] = BMP2; pgbtnaidBitmap[3] = BMP3; WinRegisterGraphicButton(); /* Create the graphic button. hwnd is the window handle * of the owning window (for example, client window) */ hwndGB = WinCreateWindow (hwnd, WC_GRAPHICBUTTON, "", /* No text here; see pgbtnpszText */ WS_VISIBLE | WS_TABSTOP | WS_POINTSELECT | GBS_AUTOANIMATION | GBS_3D_TEXTRECESSED, 0,0,80,40, hwnd, HWND_TOP, ID_GB, /* Graphic button identifier */ MPFROMP(pgbtn), NULL); WinSendMsg( hwndGB, GBM_SETGRAPHICDATA, MPFROMP(pgbtn), 0); }