If image resizing is needed, consider the ImageX control.
Control Add Image, hDlg, id&, image$, x, y, xx, yy, _ style&, extsytle& CALL callback
#Compile Exe #Include "Win32API.inc" #Resource "pb-test.pbr" Global hDlg As Dword Function PBMain() As Long Dialog New Pixels, 0, "Image Test",300,300,200,200, _ %WS_SysMenu, 0 To hDlg Control Add Image, hDlg, 100,"cowgirl", 50,50,100,100, %SS_Notify Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long If Cb.Msg = %WM_Command And Cb.Ctl = 100 And _ Cb.CtlMsg = %STN_Clicked Then MsgBox "Pushed!" End If End Function
In this example, the image "cowgirl" is stored in a resource file, available from here. Also note that the #INCLUDE "Win32API.inc" is required because it contains the %STN_CLICKED message named constant.
An additional example of a callback function is provided further down this page.
There are few options. You can display the image at it's normal size and you can put a border around it. If you make the control smaller or bigger than the image, the control resizes itself to fit the image.
The exception is that if %ss_centerimage is used in style&, the image is centered in the image control and the control does not resize. If the control is smaller than the image, the image is clipped. If the control is larger than the image, the pixel color at 0,0 in the image is used to form a border around the image.
Arguments
The Control Add statement is used to create all new controls. Here are the
statement's arguments and any special significance to the image control.
Since the image control resizes to fit the image the (xx,yy) dimensions are ignored unless %ss_centerimage is used in style&. In that case, the image control does not resize and the image is centered within the control as was discussed above.
Usage Notes
As noted earlier, images must come from PowerBASIC resource files.
Note that the #INCLUDE "Win32API.inc" is required because it contains the %STN_CLICKED message named constant.
The %SS_NOTIFY style must be included to received the %stn_click and %stn_dblclk notifications.
Image Control-Specific PowerBASIC Statements
Although PowerBASIC provides control-specific statements for some controls (Treeview,
Imagelist, ...), there are no IMAGE PowerBASIC statements.
Messages, Notifications, Styles, and ExtSstyles
There are four types of named constants in the following table.
All are pulled from the
MSDN web site.
The first column contains control-specific named constants and the second column contains generic window named constants (image controls are windows).
Also, if the PowerBASIC Help file has an entry on the value, it is highlighted in yellow. If the value was noted in PowerBASIC Help as a default value, it is also shown in bold text.
In the values for notifications, descriptions starting with -n and -c refer to events received through the %wm_notify and %wm_command messages. By default, PowerBASIC controls can receive both of these messages.
And here is a short description of many of the named constants corresponding to notifications, styles, and extstyle - particularly those discussed in the PowerBASIC Help topics.
%ss_bitmap - display only bitmap images %ss_centerimage - center image. fill border with 0,0 pixel color %ss_icon - display only icon images %ss_notify - sends %stn_clicked/%stn_dblclk messages %ss_sunken - draw half-sunken border %stn_clicked -c mouse click %stn_dblclk -c double slick %stn_disable -c when control has been disabled %stn_enable -c when control has been enabled %wm_ctlcolorstatic - about to be drawn %ws_ex_clientedge - apply sunken edge border %ws_ex_left - generic left-aligned properties %ws_ex_right - generic right-aligned properties %ws_ex_staticedge - apply 3D border %ws_ex_transparent - draw controls/windows beneath control first %ws_group - starts/ends group. use %ws_tabstop style.
Callback Function
A control can have its own callback function, or use the parent
dialog callback function.
A control callback function should return TRUE to indicate it has processed the message. This prevents unnecessarily calling the dialog callback function, which will process the message if no control callback function is available, or if the control callback function returns FALSE.
By default, both %WM_COMMAND and %WM_NOTIFY messages are received. However, if the #MESSAGE COMMAND compiler directive is invoked, the %WM_NOTIFY messages will not be available.
In addition, %ss_notify must be included in style& to receive the %stn_clicked and %stn_dblclk messages.
Here's a sample image control callback function.
CallBack Function cbImage() Select Case CB.MSG Case %WM_COMMAND Select Case CB.CTLMSG Case %stn_clicked Case %stn_dblclk Case %stn_disable Case %stn_enable End Select End Select End Function
In each Case section, add the statements the application needs to respond to the event. Also, be sure to add "Function=1" as appropriate to indicate that the event was handled by the callback function.
CONTROL Statement Syntax
The following table lists the various Control statements (except the ADD statements).
Most, but not all, can be used with the image control. A one-line description of
the statement and then its syntax are presented.
CONTROL DISABLE disable
hDlg, id&
CONTROL ENABLE enable
hDlg, id&
CONTROL GET CHECK check state
hDlg, id& TO iResult1&
CONTROL GET CLIENT top/left location
hDlg, id& TO wide&, high&
CONTROL GET LOC top/left location
hDlg, id& TO x&, y&
CONTROL GET SIZE width/height
hDlg, id& TO width&, height&
CONTROL GET TEXT text
hDlg, id& TO txt$
CONTROL GET USER get user data
hDlg, id&, index& TO retvar&
CONTROL HANDLE window handle for control id
hDlg, id& TO hCtl&
CONTROL KILL remove control
hDlg, id&
CONTROL POST put message in queue (non-blocking)
hDlg, id&, Msg&, wParam&, lParam&
CONTROL REDRAW schedule redraw of control
hDlg, id&
CONTROL SEND send message to control, wait for processing
hDlg, id&, Msg&, wParam&, lParam& TO iResult2&
CONTROL SET CHECK set check for 3state or checkbox
hDlg, id&, checkstate&
CONTROL SET CLIENT change size to specific client area size
hDlg, id&, wide&, high&
CONTROL SET COLOR set fg/bg color
hDlg, id&, fgcolor&, bgcolor&
CONTROL SET FOCUS set focus
hDlg, id&
CONTROL SET FONT select font for a control
hDlg, id&, fonthandle&
CONTROL SET LOC relocate control within dialog
hDlg, id&, x&, y&
CONTROL SET OPTION set check state of option control
hDlg, id&, minid&, maxid&
CONTROL SET SIZE change control size
hDlg, id&, width&, height&
CONTROL SET TEXT change control text
hDlg, id&, text$
CONTROL SET USER set user data
hDlg, id&, index&, uservalue&
CONTROL SHOW STATE toggle visibility
hDlg, id&, showstate& TO iResult3&
If you have any suggestions or corrections, please let me know.