Date: 02-16-2022
Return to Index
created by gbSnippets
'This example include of all 21 controls directly supported by PowerBASIC. With it, you can see
'which controls block (or not) the mouse movement messages from reaching the CallBack function.
'Primary Code:
'Because of length, all the code is listed in the compilable code below.
'But, here is summary information about the events and how various controls respond to those events.
'Here are events covered in the compilable code:
'SetCursor: 'message available while mouse over ALL controls. dialog client area coordinates.
'These mouse events reach the Callback ONLY for label, line, image, imagex, graphic frame controls:
'MouseMove: 'message only available while mouse over Label, Line, Image, ImageX, Graphic, Frame
'MouseUp/Down: 'message only available while mouse over Label, Line, Image, ImageX, Graphic, Frame
'Mouse DblClk 'dblclick happens after 2nd mouse down, before 2nd mouse up
'message only available while mouse over Label, Line, Image, ImageX, Graphic, Frame
'By using %SS_Notify style, 5 of the controls - label, line, image, imagex, graphics - will get the
'%STN_CLicked and %STN_DblClk event messages via %WM_Command messages, but will also lose
'the ability to response to all other mouse events.
'Mouse Click 'Windows has up/down/move/dblclick - but has no WM_MouseClick event.
'When %SS_Notify is used, Line, Label, Image, ImageX, and Graphic controls
'will receive WM_COMMAND messages with %STN_Clicked and %STN_DblClk.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
#Resource "gbsnippets.pbr"
Global hDlg As DWord, hLst1 as DWord, hLst2 as DWord, hMenu as DWord, hMenuHelp as DWord
%IDC_Button = 100 : %IDC_LabelA = 110 : %IDC_LabelB = 120 : %IDC_LabelC = 130
%IDC_TextBox = 140 : %IDC_ListBox = 150 : %IDC_ComboBox = 160 : %IDC_Option = 170
%IDC_Checkbox = 180 : %IDC_Check3State = 190 : %IDC_ScrollBar = 200 : %IDC_Line = 210
%IDC_ImgButton = 220 : %IDC_ImgButtonX = 230 : %IDC_Image = 240 : %IDC_ImageX = 250
%IDC_Graphic = 260 : %IDC_Toolbar = 270 : %IDC_StatusBar = 280 : %IDC_ListView = 290
%IDC_TreeView = 300 : %IDC_Tab = 310 : %IDC_Frame = 320
Function PBMain() As Long
Dim MyArray(1) as String
MyArray(0) = "Items" : MyArray(1)= "ListBox"
Dialog New Pixels, 0, "Test Code",300,300,600,500, %WS_OverlappedWindow To hDlg
AddToolbar : AddMenu : AddStatusBar
AddListView : AddTreeView : AddTAB
Control Add Button, hDlg, %IDC_Button,"Button", 20,60,100,20
Control Add Label, hDlg, %IDC_LabelA,"Label1", 20,90,120,17, %WS_Border 'Or %SS_Notify
Control Add Label, hDlg, %IDC_LabelB,"Label2", 20,110,120,17, %WS_Border 'Or %SS_Notify
Control Add Label, hDlg, %IDC_LabelC,"Label3", 20,130,100,17, %WS_Border 'Or %SS_Notify
Control Add TextBox, hDlg, %IDC_TextBox,"TextBox", 20,160,100,20
Control Add ListBox, hDlg, %IDC_ListBox,MyArray() , 20,190,100,100
Control Add ComboBox, hDlg, %IDC_ComboBox,MyArray(), 20,295, 100,20
Control Add Option, hDlg, %IDC_Option, "Pick Me!", 20,320, 100,20
Control Add Checkbox, hDlg, %IDC_CheckBox, "No, Pick Me!", 20, 350, 100,20
Control Add Check3State, hDlg, %IDC_Check3State, "Forget them, pick Me!", 20, 380, 120,20
Control Add ScrollBar, hDlg, %IDC_ScrollBar, "", 20, 410, 120,20
Control Add Line, hDlg, %IDC_Line, "", 20, 445, 120,8, %WS_Border 'Or %SS_Notify
Control Add ImgButton, hDlg, %IDC_ImgButton,"cowgirl", 150,60,100,100, %WS_Border
Control Add ImgButtonX, hDlg, %IDC_ImgButtonX,"cowgirl", 150,180,100,100, %WS_Border
Control Add Image, hDlg, %IDC_Image,"cowgirl", 270,60,100,100, %WS_Border 'Or %SS_Notify
Control Add ImageX, hDlg, %IDC_ImageX,"cowgirl", 270,180,100,100, %WS_Border 'Or %SS_Notify
Control Add Graphic, hDlg, %IDC_Graphic,"cowgirl", 270,300,100,100, %WS_Border 'Or %SS_Notify
Control Add Frame, hDlg, %IDC_Frame,"Frame", 400,300,150,50, %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local pt as Point
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IDC_LabelA, %IDC_LabelB, %IDC_LabelC
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "Label STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "Label STN Double Click"
End Select
Case %IDC_Line
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "Line STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "Line STN Double Click"
End Select
Case %IDC_Image
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "Image STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "Image STN Double Click"
End Select
Case %IDC_ImageX
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "ImageX STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "ImageX STN Double Click"
End Select
Case %IDC_Graphic
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "Graphic STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "Graphic STN Double Click"
End Select
Case %IDC_Frame
Select Case CB.Ctlmsg
Case %STN_Clicked : Control Set Text hDlg, %IDC_LabelC, "Frame STN Click"
Case %STN_DblClk : Control Set Text hDlg, %IDC_LabelC, "Frame STN Double Click"
End Select
End Select
Case %WM_Notify
Case %WM_SetCursor
GetCursorPos pt 'pt has xy screen coordinates
ScreenToClient hDlg, pt 'pt now has dialog client coordinates
Control Set Text hDlg, %IDC_LabelA, "SetCursor: " + Str$(pt.x) + ":" + Str$(pt.y)
Case %WM_MouseMove
GetCursorPos pt 'pt has xy screen coordinates
ScreenToClient hDlg, pt 'pt now has dialog client coordinates
Control Set Text hDlg, %IDC_LabelB, "MouseMove: " + Str$(pt.x) + ":" + Str$(pt.y)
Case %WM_LButtonUp : Control Set Text hDlg, %IDC_LabelC, "Left Mouse Up"
Case %WM_MButtonUp : Control Set Text hDlg, %IDC_LabelC, "Middle Mouse Up"
Case %WM_RButtonUp : Control Set Text hDlg, %IDC_LabelC, "Right Mouse Up"
Case %WM_XButtonUp : Control Set Text hDlg, %IDC_LabelC, "X Mouse Up"
Case %WM_LButtonDown : Control Set Text hDlg, %IDC_LabelC, "Left Mouse Down"
Case %WM_MButtonDown : Control Set Text hDlg, %IDC_LabelC, "Middle Mouse Down"
Case %WM_RButtonDown : Control Set Text hDlg, %IDC_LabelC, "Right Mouse Down"
Case %WM_XButtonDown : Control Set Text hDlg, %IDC_LabelC, "X Mouse Down"
Case %WM_LButtonDblClk : Control Set Text hDlg, %IDC_LabelC, "Left Dbl Click"
Case %WM_MButtonDblClk : Control Set Text hDlg, %IDC_LabelC, "Middle Dbl Click"
Case %WM_RButtonDblClk : Control Set Text hDlg, %IDC_LabelC, "Right Dbl Click"
Case %WM_XButtonDblClk : Control Set Text hDlg, %IDC_LabelC, "X Dbl Click"
End Select
End Function
Sub AddToolbar
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0
ImageList New Icon 16,16,32,3 To hLst1
ImageList Add Icon hLst1, "x" '1
Toolbar Set ImageList hDlg, %IDC_Toolbar, hLst1, 0
Toolbar Add Button hDlg, %IDC_Toolbar, 1, 200, %TbStyle_Button, "x"
End Sub
Sub AddMenu()
Menu New Bar To hMenu
Menu New Popup To hMenuHelp
Menu Add Popup, hMenu, "&Help", hMenuHelp, %MF_Enabled
Menu Add String, hMenuHelp, "&About", 1000, %MF_Enabled
Menu Attach hMenu, hDlg
End Sub
Sub AddStatusBar
Control Add StatusBar, hDlg, %IDC_StatusBar, "",0,0,0,0
StatusBar Set Parts hDlg, %IDC_StatusBar, 75,75,99999
StatusBar Set Text hDlg, %IDC_StatusBar, 1, 0, "one"
StatusBar Set Text hDlg, %IDC_StatusBar, 2, 0, "two"
StatusBar Set Text hDlg, %IDC_StatusBar, 3, 0, "three"
End Sub
Sub AddListView
Control Add ListView, hDlg, %IDC_ListView, "", 400,60,150,100, %WS_Border
ImageList New Icon 16,16,32,3 To hLst2 'create SMALL imagelist w,h,depth,size
ImageList Add Icon hLst2, "x"
ListView Set ImageList hDlg, %IDC_ListView, hLst2, %lvsil_small
ListView Insert Column hDlg, %IDC_ListView, 1, "test1", 75, 0 'columns hdlg, id&, col, "test", width, format
ListView Insert Item hDlg, %IDC_ListView, 1, 1, "one" 'row 1, col1 'rows hdlg, id&, row, image, "text"
ListView Set Text hDlg, %IDC_ListView, 1,2, "12" 'row1 col2 'items hdlg, id&, row, col, "text"
ListView Set Mode hDlg, %IDC_ListView, 1 '0-icon 1-report 2-small 3-list
End Sub
Sub AddTreeView
Local hItem as DWord, hTemp as DWord, hTemp2 as DWord, Style&
style& = %TVS_HASBUTTONS Or %TVS_LINESATROOT Or %TVS_HASLINES Or %WS_Border
Control Add TreeView, hDlg, %IDC_TreeView, "", 400,180,150,100, Style&
TreeView Insert Item hDlg, %IDC_TreeView, 0, %TVI_Last, 0,0,"Root" To hItem
TreeView Insert Item hDlg, %IDC_TreeView, hItem, %TVI_Last, 0,0,"Mother" To hTemp
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Dan" To hTemp2
TreeView Set Expanded hDlg, %IDC_TreeView, hItem, %True
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp, %True
End Sub
Sub AddTab
Local hPage1 as DWord, hPage2 as DWord
Control Add Tab, hDlg, %IDC_Tab, "", 400,370,150,75
Tab Insert Page hDlg, %IDC_Tab, 1,0,"Page1" To hPage1
Control Add Label, hPage1, 550, "Label1", 20,20,60,20
Tab Insert Page hDlg, %IDC_Tab, 2,0,"Page2" To hPage2
Control Add TextBox, hPage2, 560, "Text1", 20,20,60,20
End Sub
'gbs_00206
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm