Date: 02-16-2022
Return to Index
created by gbSnippets
'It's common for programmers to handle all messages within the main dialog callback function.
'However, sometimes it's either convenient, or more easily maintained, to handle message to
'a control within a callback function dedicated to only that control. PowerBASIC supports
'this by allowing a callback function to be declared for each control.
'Primary Code:
'The callback function is named as part of the Control Add statements.
'Syntax: Control Add ImageX, hDlg, id&, image$, x, y, xx, yy [, [style&] [, [exstyle&]]] [[,] Call CallBack]
Control Add ImageX, hDlg, 100,"cowgirl", 50,50,100,100, %SS_Notify Call ImageProc
'Compilable Example: (Jose Includes)
'The following compilable code demonstrates a dialog with a single
'image control which has it's own callback function defined.. The
'displayed image comes from a resource file. Note that when the control
'callback function returns a non-zero value, that the control messages are NOT
'sent on to the dialog callback function.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "ImageX Test",300,300,200,200, %WS_SysMenu, 0 To hDlg
Control Add ImageX, hDlg, 100,"cowgirl", 50,50,100,100, %SS_Notify Call ImageProc
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
'this is received only if the control callback does not handle the message
MsgBox "Clicked - main callback!"
End If
End Function
CallBack Function ImageProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %STN_Clicked Then
MsgBox "Clicked - control callback!"
Function = %True 'any non-zero value says that no further processing is required
End If
End Function
'gbs_00511
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm