This example shows all 21 of the PowerBASIC supported controls, showing how wm_mousemove, wm_setcursor, buttonup/down (left and right) work with the controls.
As the gbs# at the bottom of the snippet show, this is also found in gbSnippets as well as online at the gbSnippets server.
Edited 17 Sept 2009: Added %WS_Group to the Option control, another option control (to form a group) and %WS_Group to the next control (fixes a freeze to the program when the Option control is clicked) ... Gary Beene
Code:
'Compilable Example: #Compile Exe #Dim All #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 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, 100,"Button", 20,60,100,20 Control Add Label, hDlg, 110,"Label1", 20,90,120,20 Control Add TextBox, hDlg, 120,"TextBox", 20,120,100,20 Control Add ListBox, hDlg, 130,MyArray() , 20,150,100,100 Control Add ComboBox, hDlg, 140,MyArray(), 20,260, 100,20 Control Add Option, hDlg, 150, "Pick Me!", 20,285, 100,20, %WS_Group Control Add Option, hDlg, 155, "Pick Him!", 20,300, 100,20, %WS_Group Control Add Checkbox, hDlg, 160, "No, Pick Me!", 20, 325, 100,20, %WS_Group Control Add Check3State, hDlg, 170, "Forget them, pick Me!", 20, 350, 120,20 Control Add ScrollBar, hDlg, 180, "", 20, 380, 120,20 Control Add Line, hDlg, 190, "", 20, 420, 100,8 ',%SS_Notify Or %WS_Border Control Add ImgButton, hDlg, 300,"cowgirl", 140,60,100,100, %WS_Border Control Add ImgButtonX, hDlg, 310,"cowgirl", 140,180,100,100, %WS_Border Control Add Image, hDlg, 500,"cowgirl", 270,60,100,100, %WS_Border ',%SS_Notify Control Add ImageX, hDlg, 510,"cowgirl", 270,180,100,100, %WS_Border ',%SS_Notify Control Add Graphic, hDlg, 520,"", 270,300,100,100, %WS_Border ',%SS_Notify Graphic Attach hDlg, 520 : Graphic Render "cowgirl", (0,0)-(100,100) Control Add Frame, hDlg, 530,"Frame", 400,300,150,50, %WS_Border ',%SS_Notify Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long Local pt as Point Select Case CB.Msg Case %WM_Command Case %WM_Notify End Select End Function Sub AddToolbar Control Add Toolbar, hDlg, 700,"", 0,0,0,0 ImageList New Icon 16,16,32,3 To hLst1 ImageList Add Icon hLst1, "x" '1 Toolbar Set ImageList hDlg, 700, hLst1, 0 Toolbar Add Button hDlg, 700, 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, 800, "",0,0,0,0 StatusBar Set Parts hDlg, 800, 75,75,99999 StatusBar Set Text hDlg, 800, 1, 0, "one" StatusBar Set Text hDlg, 800, 2, 0, "two" StatusBar Set Text hDlg, 800, 3, 0, "three" End Sub Sub AddListView Control Add ListView, hDlg, 900, "", 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, 900, hLst2, %lvsil_small ListView Insert Column hDlg, 900, 1, "test1", 75, 0 'columns hdlg, id&, col, "test", width, format ListView Insert Item hDlg, 900, 1, 1, "one" 'row 1, col1 'rows hdlg, id&, row, image, "text" ListView Set Text hDlg, 900, 1,2, "12" 'row1 col2 'items hdlg, id&, row, col, "text" ListView Set Mode hDlg, 900, 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, 950, "", 400,180,150,100, Style& TreeView Insert Item hDlg, 950, 0, %TVI_Last, 0,0,"Root" To hItem TreeView Insert Item hDlg, 950, hItem, %TVI_Last, 0,0,"Mother" To hTemp TreeView Insert Item hDlg, 950, hTemp, %TVI_Last, 0,0,"Dan" To hTemp2 TreeView Set Expanded hDlg, 950, hItem, %True TreeView Set Expanded hDlg, 950, hTemp, %True End Sub Sub AddTab Local hPage1 as Dword, hPage2 as Dword Control Add Tab, hDlg, 540, "", 400,370,150,75 Tab Insert Page hDlg, 540, 1,0,"Page1" To hPage1 Control Add Label, hPage1, 550, "Label1", 20,20,60,20 Tab Insert Page hDlg, 540, 2,0,"Page2" To hPage2 Control Add TextBox, hPage2, 560, "Text1", 20,20,60,20 End Sub 'gbs_00082
Edited 17 Sept 2009: Added %WS_Group to the Option control, another option control (to form a group) and %WS_Group to the next control (fixes a freeze to the program when the Option control is clicked) ... Gary Beene
Comment