PictureButton

Posted on  by 



Download PictureButton for Mac to add images to your buttons. PictureButton has had 1 updates within the past 6 months. Using Swing Components In the previous chapter, we discussed a number of concepts, including how Java’s user interface facility is put together and how the larger pieces work. Selection from Learning Java Book. The following XSL examples are for picture button controls, as specified in.section 2.3.2.10 The following is an example of a picture button control with conditional formatting. The src attribute is set to image img1.jpg. This means that the picture button displays image img1.jpg contained in the form template.

Chapter 2: System Object Properties, Events, and Functions

A PictureButton displays a picture and, like a CommandButton,is used to carry out an action. For example, you can use a buttonwith a picture of a file to save a file, or a button with a pictureof a stop sign to cancel a requested deletion.

The picture image can be in the following formats:

  • Bitmaps, with .BMP or .RLE extensions

  • Windows metafiles, with the .WMF extension

  • GIF or animated GIF files, with the .GIF extension

  • JPEG files, with .JPEG or .JPG extensions

Properties

PictureButton property

Datatype

Description

String

A description of the control and/orits purpose for use by accessibility tools such as readers for visuallyimpaired users.

String

A label that briefly describes the control,such as the text in a button or the name of a menu item.

AccessibleRole (enumerated)

Describes what kind of user interfaceelement the control is.

Long

Specifies the numerical value of thebackground color of the window. Values are -2 to 16,777,215. Formore information about color, see the RGB functionin the PowerScript Reference.

Boolean

Specifies whether PowerBuilder movesthe control to the top of the front-to-back order of the window.

Boolean

Specifies whether the control acts asthe Cancel button (the Cancel button receives a Clicked event ifthe user presses Esc). Values are:

  • TRUE – Control acts as Cancelbutton.

  • FALSE – Control doesnot act as Cancel button.

ClassDefinition

PowerObject

An object of type PowerObject containinginformation about the class definition of the object or control.

Boolean

Specifies whether the control is thedefault PictureButton (the default PictureButton has a thick borderand receives a Clicked event if the user presses Enter without selectingan control). Values are:

  • TRUE – Control is default PictureButton.

  • FALSE – Control isnot default PictureButton.

Editable controls Default behavior can be affected by editable controls on thewindow. For more information, see the PowerBuilder UsersGuide.

String

Specifies the name of the picture (bitmapimage) that displays when the control is disabled. If the stringhas no extension, PowerBuilder adds an appropriate extension.

Boolean

Specifies whether PowerBuilder puts thecontrol automatically into Drag mode. Values are:

  • TRUE – When the controlis clicked, the control is automatically in Drag mode.

  • FALSE – When the controlis clicked, the control is not automatically in Drag mode. You haveto manually put the control into Drag mode by using the Drag function.

String

Specifies the name of the stock iconor the file containing the icon you want to display when the userdrags the control (the ICO file). The defaulticon is a box the size of the control.

When the user drags the control, the icon displays when the controlis over an area in which the control can be dropped (a valid droparea). When the control is over an area that is not a valid droparea, the No-Drop icon displays.

Boolean

Specifies whether the control is enabled(can be selected). Values are:

  • TRUE – Control is enabled.

  • FALSE – Control isnot enabled.

String

Specifies the name of the typeface inwhich the text of the control displays (for example, arial or courier).

FlatStyle

Boolean

Specifies that the edge of the buttondisplays only when the mouse hovers over it. This is the buttonstyle used in the Microsoft Rebar (coolbar) control. Values are:

  • TRUE – Buttonhas a flat appearance.

  • FALSE – Button doesnot have a flat appearance.

FontCharSet (enumerated)

Specifies the font character set usedfor the text in the control. For a complete list of possible values,see the list of properties for the FontCharSet variable on the Enumeratedtab page of the Browser.

FontFamily (enumerated)

Specifies the font family (type style)used for the text in the control. Values are:

  • AnyFont!

  • Decorative!

  • Modern!

  • Roman!

  • Script!

  • Swiss!

FontPitch (enumerated)

Specifies the pitch (spacing) of thefont used for the text in the control. Values are:

  • Default!

  • Fixed!

  • Variable!

Integer

Specifies the height of the control,in PowerBuilder units.

Alignment (enumerated)

Specifies how the text in the controlis aligned. Values are:

  • Center!

  • Justify!

  • Left!

  • Right!

Boolean

Specifies whether the text in the controlis italic. Values are:

  • TRUE – Text is italic.

  • FALSE – Text is notitalic.

Boolean

Specifies whether the system 3D colorsare mapped to the control. Values are:

  • TRUE – Colors are mapped.

  • FALSE – Colors arenot mapped.

Boolean

Specifies whether the width and heightproperties of a bitmap image (picture) are set to their originalvalues. Values are:

  • TRUE – Width and height are set to original values.

  • FALSE – Existing widthand height are not changed to original values.

In the Window painter, setting OriginalSize to true overridesthe existing width and height.

String

Specifies the name of the file that containsthe picture.

String

Specifies the name of the stock pointeror the file containing the pointer used for the control.

Long

Specifies a PowerTip for the control.

Integer

Specifies the tab value of the controlwithin the window (0 means the user cannot tab to the control).

String

Specifies the tag value assigned to thecontrol.

String

Specifies the text that displays in thecontrol.

Long

Specifies the numeric value of the textcolor: -2 to 16,777,215. For more information about color, see the RGB functionin the PowerScript Reference.

This property applies only when the UserObject is a tab page.

Integer

Specifies the size of the text in thecontrol, in points. For backward compatibility, the size is storedas a negative number; for example, 10-point text size is storedas -10.

Boolean

Specifies whether the text in the controlis underlined. Values are:

  • TRUE – Text is underlined.

  • FALSE – Text is notunderlined.

Boolean

Specifies whether the control is visible.Values are:

  • TRUE – Control is visible.

  • FALSE – Control isnot visible.

VTextAlign (enumerated)

Specifies how the text in the controlis aligned. Values are:

  • Bottom!

  • MultiLine!

  • Top!

  • VCenter!

All these values except MultiLine! assume there is only oneline of text.

Integer

Specifies the stroke weight of the textin the control; for example, 400 for normal or 700 for bold.

Integer

Specifies the width of the control, inPowerBuilder units.

Integer

Specifies the X position (the distancefrom the left edge of the window), in PowerBuilder units.

Integer

Specifies the Y position (the distancefrom the top of the window), in PowerBuilder units.

Events

PictureButton event

Occurs

When the control is clicked

Immediately before the Open event occursin the window

Immediately after the Close event occursin the window

When a dragged control is dropped onthe control

When a dragged control enters the control

When a dragged control leaves the control

When a dragged control is within thecontrol

Just before the control receives focus(before it is selected and becomes active)

When the user presses the F1 key or dragsthe context help button (question mark) from the title bar to amenu item or control

When the control loses focus (becomesinactive)

When a Windows message occurs that isnot a PowerBuilder event

When the right mouse button is pressedon the control

Functions

PictureButton function

Datatype returned

Description

String

Returns the name assigned to the control.

Integer

Starts or ends the dragging of the control.

Integer

Creates a reference to a context-specificinstance of the specified service.

PowerObject

Returns a reference to the name of theparent object.

Integer

Makes the control invisible.

Integer

Moves the control to a specified location.

Integer

Returns the distance of the pointer fromthe left edge of the control.

Integer

Returns the distance of the pointer fromthe top of the control.

Boolean

Adds an event to the end of the messagequeue for the control.

Integer

Prints the control.

Integer

Changes the size of the control.

Integer

Sets focus to the specified control.

Integer

Specifies the position of the controlin the front-to-back order of the window.

Integer

Controls automatic redrawing of the controlafter each change in its properties.

Integer

Makes the control visible.

Integer

Triggers a specified event in the controland executes the script for the event.

Object

Returns the type of the control.




Copyright © 2008. Sybase Inc. All rights reserved.
Visual C++ Example: MFC Bitmap Button Source Code (CButton)

Introduction

CCustomBitmapButton is MFC control derived from the CWnd class. The button has two parts: a background and a foreground. If the operating system is WinXP and XP Themes are enabled the background is a bitmap loaded from the current active theme resource file (I use similar technique to draw the scroll buttons in the CCustomTabCtrl control); otherwise, the 'DrawFrameControl' function is used to draw the button background. The foreground is a user-defined monochrome bitmap (glyph) drawn transparently on the button background.

Supported features:

  • Standard or XP Themes view

  • 12 predefined background styles

  • User-defined foregrounds (bitmap glyphs)

  • Button states supported: 'NORMAL','HOT','PRESSED', and 'DISABLED'

  • Buttons can be created in the caption bar area

  • Dialog, SDI and MDI support for the caption buttons

  • Ficker-free drawing

  • Built-in tooltips

Using the Code

To integrate the CCustomBitmapButton class into your application as a caption frame, please follow the steps below:

  1. Add ThemeUtil.h, ThemeUtil.cpp, CustomBitmapButton.h, CustomBitmapButton.cpp, Tmschema.h, and Schemadef.h to your project.

  2. Include CustomBitmapButton.h to the appropriate header file—usually the dialog class header where the CCustomBitmapButton class is used.

  3. Declare m_ctrlCaptionFrame object of type CCustomBitmapButton in your dialog header.

  4. Create the caption frame.

    In your dialog's OnInitDialog, add the following code:

  5. After creating the caption frame, add as many buttons as you need.

    To add caption buttons, call AddCaptionButton in your dialog's OnInitDialog:

  6. Process WM_NOTIFY messages from the caption buttons in your dialog class. As users click a button, the button sends notification messages (NM_CLICK, NM_RCLICK, NM_DBLCLK, and NM_RDBLCLK) to its parent window. Handle these messages if you want to do something in response.

  7. Don't forget to destroy the caption frame; otherwise, you will have memory leaks.

CCustomBitmapButton Class Members

Construction/Destruction
Attributes
Operations
Notification Messages
Error Codes

Construction/Destruction

Constructs a CCustomBitmapButton object.

Creates a bitmap button and attaches it to an instance of a CCustomBitmapButton object.

Creates a caption frame.

Destroys a caption frame.


Attributes

Retrieves the pointer to the caption button.

Changes the tooltip text of a button.

Retrieves information about the button control background style.

Changes the background style of a button.

Retrieves the handle of the glyph bitmap previously set with SetGlyphBitmap.

Specifies a glyph bitmap to be displayed on the button.

Enables or disables the button.


Operations

Inserts a new button in a caption bar.


CCustomBitmapButton::CCustomBitmapButton

CCustomBitmapButton();

Remarks

Call this function to construct a CCustomBitmapButton object.

CCustomBitmapButton::Create

BOOLCreate(DWORDdwStyle,constRECT&rect,CWnd*pParentWnd,UINTnID);

Return Value

TRUE if initialization of the object was successful; otherwise, FALSE.

Parameters

dwStyle—Specifies the button style.

rect—Specifies the button size and position. It can be either a CRect object or a RECT structure.

pParentWnd—Specifies the button parent window.

nID—Specifies the button ID.

Remarks

Creates a bitmap button and attaches it to an instance of a CCustomBitmapButton object.

CCustomBitmapButton::CreateCaptionFrame

intCreateCaptionFrame(CWnd*pCaptionWnd,intnIDIcon);

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

pCaptionWnd—Specifies the caption bar owner window.

nIDIcon—Specifies the caption icon resource id.

Picture buttons walgreensPicture buttons definition

Remarks

Creates a caption frame.

CCustomBitmapButton::DestroyCaptionFrame

intDestroyCaptionFrame();

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Remarks

Destroys a caption frame.

CCustomBitmapButton::GetCaptionButtonPtr

CCustomBitmapButton*GetCaptionButtonPtr(intnButtonID) const;

Return Value

Pointer to the CCustomBitmapButton object if successful; otherwise, NULL.

Parameters

nButtonID—The ID of the caption button.

Remarks

Call this function to retrieve the pointer to the caption button.

CCustomBitmapButton::SetTooltipText

intSetTooltipText(CStringsText);

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

sText—Pointer to a string object that contains the new tooltip text.

Remarks

This function changes the tooltip text of a button.

CCustomBitmapButton::GetBkStyle

intGetBkStyle();

Return Value

Returns the button background style for this CCustomBitmapButton object.

Remarks

Call this function to retrieve information about the button control background style.

CCustomBitmapButton::SetBkStyle

intSetBkStyle(intnBkStyle);

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

nBkStyle—Specifies the button background style.

Supported background styles:

  • CBNBKGNDSTYLE_CAPTION—frame buttons

  • CBNBKGNDSTYLE_CLOSE

  • CBNBKGNDSTYLE_MDI

  • CBNBKGNDSTYLE_COMBO—combobox dropdown button

  • CBNBKGNDSTYLE_SPINUP—spin buttons

  • CBNBKGNDSTYLE_SPINDN

  • CBNBKGNDSTYLE_SPINUPHOR

  • CBNBKGNDSTYLE_SPINDNHOR

  • CBNBKGNDSTYLE_SCROLLUP—scrollbar buttons

  • CBNBKGNDSTYLE_SCROLLDOWN

  • CBNBKGNDSTYLE_SCROLLLEFT

  • CBNBKGNDSTYLE_SCROLLRIGHT

Remarks

Picture Button Maker

Changes the background style of a button.

CCustomBitmapButton::GetGlyphBitmap

HBITMAPGetGlyphBitmap();

Return Value

A handle to a bitmap. NULL if no bitmap is previously specified.

Remarks

Call this member function to get the handle of a glyph bitmap that is associated with a button.

CCustomBitmapButton::SetGlyphBitmap

intSetGlyphBitmap(HBITMAPhBmpGlyph);

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

hBmpGlyph—The handle of a bitmap.

Remarks

Call this member function to associate a new glyph bitmap with the button.

CCustomBitmapButton::EnableWindow

intEnableWindow(BOOLbEnable = TRUE);

Return Value

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

bEnable—Specifies whether the given window is to be enabled or disabled. If this parameter is TRUE, the window will be enabled. If this parameter is FALSE, the window will be disabled.

Remarks

Picture

Call this function to enable or disable a button control.

Picture Buttons Definition

CCustomBitmapButton::AddCaptionButton

int AddCaptionButton( LPCRECT lpRect, UINT nID, int nBkStyle, BOOL fUserDefWidth );

Return Value

Picture Button

CBNERRR_NOERROR if successful; otherwise, CBNERRR_ERRORCODE.

Parameters

lpRect—Specifies the button width if fUserDefWidth is true; otherwise, ignored.

nID—Specifies the button ID.

nBkStyle—Specifies the button background style.

PictureButton

fUserDefWidth—If TRUE—user defined button width.

Remarks

Call this function to insert a new button in an existing caption bar.

Notification Messages

The following notification codes are supported by the button control:

  • NM_CLICK—User clicked left mouse button in the control.

  • NM_RCLICK—User clicked right mouse button in the control.

  • NM_DBLCLK—User double clicked left mouse button in the control.

  • NM_RDBLCLK—User double clicked right mouse button in the control.

Error Codes

The following errors can be returned by the button control functions:

  • CBNERRR_NOERROR—Operation succesful.

  • CBNERR_OUTOFMEMORY—Function call failed because there was not enough memory available.

  • CBNERR_INCORRECTPARAMETER—Function call failed because an incorrect function parameter was specified.

  • CBNERR_INCORRECTBUTTONSTYLE—Function call failed because an incorrect button style was specified.

  • CBNERR_INCORRECTFRAMESTYLE—Function call failed because the WS_CAPTION style was not specified.

  • CBNERR_INCORRECTFUNCCALL—Incorrect function call (for example: ob.SetTooltipText(...) where ob is an instance of the caption frame object).

  • CBNERR_CREATEBUTTONFAILED—Function call failed because creation of the button control failed.

  • CBNERR_CREATETOOLTIPCTRLFAILED—Function call failed because creation of the tooltip control failed.

  • CBNERR_COPYIMAGEFAILED—Function call failed because copying of the glyph image failed.

  • CBNERR_SETWINDOWLONGFAILED—Call to the function 'SetWindowLong' failed.

  • CBNERR_FRAMEALREADYCREATED—Function call failed because the caption frame was already created.

  • CBNERR_FRAMENOTCREATED—Function call failed because the caption frame was not created.

Downloads
CustomBitmapButtonDemo.zip - Download source VC++ demo project - 40 Kb
CustomBitmapButtonDemo_exe.zip - Downloadsample demo executable - 26 Kb





Coments are closed