Programming with Picture Button Controls
This topic describes how to complete the following tasks programmatically.
- Copying the bitmap from the picture button
- Creating a picture command button versus a picture toggle button
- Displaying an image
- Setting and getting the state of a picture toggle button
- Specifying the placement and sizing of the image
- Using a subimage
Creating a Picture Command Button Versus a Picture Toggle Button
There are two styles of picture button controls: picture command buttons (CTRL_PICTURE_COMMAND_BUTTON) and picture toggle buttons (CTRL_PICTURE_TOGGLE_BUTTON).
int picToggle, picCommand;
picToggle = NewCtrl (panelHandle, CTRL_PICTURE_TOGGLE_BUTTON_LS, "Picture Toggle", 35, 45);
picCommand = NewCtrl (panelHandle, CTRL_PICTURE_COMMAND_BUTTON_LS, "Picture Command", 85, 45);
Displaying an Image
You can display images from image files or from bitmaps.
/* Display from an image file */
SetCtrlAttribute (panelHandle, picCommand, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
/* Displaying from a bitmap */
int cviBmp;
GetBitmapFromFile ("c:\\temp\\closedfoldericon.ico", &cviBmp);
SetCtrlBitmap (panelHandle, picToggle, 0, cviBmp);
DiscardBitmap (cviBmp);
Copying the Bitmap from the Picture Button
Copy the bitmap from the picture control into memory.
int bitmapID;
GetCtrlBitmap (panelHandle, picToggle, 0, &bitmapID);
Setting and Getting the State of a Picture Toggle Button
// Setting the state
int val;
GetCtrlVal (panelHandle, PANEL_BINARYSWITCH, &val);
SetCtrlVal (panelHandle, picToggle, val);
// Getting the state
int toggleState;
GetCtrlVal (panelHandle, picToggle, &toggleState);
SetCtrlVal (panelHandle, PANEL_NUMERIC, toggleState);
Using a Subimage
Use a subimage if you want to display only a cropped part of an image on the picture button.
SetCtrlAttribute (panelHandle, PANEL_PICSUB, ATTR_IMAGE_FILE, "c:\\temp\\cvi.ico");
SetCtrlAttribute(panelHandle, PANEL_PICSUB, ATTR_USE_SUBIMAGE, 1);
SetCtrlAttribute(panelHandle, PANEL_PICSUB, ATTR_SUBIMAGE_HEIGHT, 15);
SetCtrlAttribute(panelHandle, PANEL_PICSUB, ATTR_SUBIMAGE_LEFT, 5);
SetCtrlAttribute(panelHandle, PANEL_PICSUB, ATTR_SUBIMAGE_TOP, 9);
SetCtrlAttribute(panelHandle, PANEL_PICSUB, ATTR_SUBIMAGE_WIDTH, 18);
Specifying the Placement and Sizing of the Image
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON, ATTR_FIT_MODE, VAL_SIZE_TO_PICTURE);
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_2, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_2, ATTR_FIT_MODE, VAL_SIZE_TO_IMAGE);
bitmap in memory. Use
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_3, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_3, ATTR_FIT_MODE, VAL_PICT_CORNER);
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_4, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_4, ATTR_FIT_MODE, VAL_PICT_CENTER);
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_5, ATTR_IMAGE_FILE, "c:\\temp\\file_save.ico");
SetCtrlAttribute (panelHandle, PANEL_PICTUREBUTTON_5, ATTR_FIT_MODE, VAL_PICT_TILE);