Date: 02-16-2022
Return to Index
created by gbSnippets
'Covers PowerBASIC controls: Button Class (Button, Option, Checkbox, Check3State, Frame, ImgButton
'Primary Code:
hTemp = CreateWindow("Button","Ok",%WS_TABSTOP Or %WS_VISIBLE Or %WS_CHILD Or %BS_DEFPUSHBUTTON, _
10,10,20,20,hMainWnd,%Null,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
Syntax: 'CreateWindow (Class, Text, Style, x,y,w,h,hParent,hMenu,hInstance,creation_parameters)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim ALL
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
%IDC_Btn01 = 501 :%IDC_Btn02 = 502 :%IDC_Btn03 = 503 :%IDC_Btn04 = 504
%IDC_Btn05 = 505 :%IDC_Btn06 = 506 :%IDC_Btn07 = 507 :%IDC_Btn08 = 508
Global hMainWnd As DWord, hTemp As DWord, hBMP As DWord
Function WinMain (ByVal hInst As DWord, ByVal hPrevInstance As DWord, ByVal lpCmdLine As Asciiz Ptr, ByVal iCmdShow As Long) As Long
Local Msg As tagMsg, myWin As WndClassEx, szAppName As Asciiz * 80, hwndButton As DWord
szAppName = "HelloSDK" : myWin.cbSize = SizeOf(myWin)
myWin.hIcon = LoadIcon(hInst, "aainfo") : myWin.Style = %CS_HREDRAW Or %CS_VREDRAW
myWin.hCursor = LoadCursor(%NULL, ByVal %IDC_ARROW) : myWin.lpfnWndProc = CodePTR(WndProc)
myWin.hbrBackground = %Color_BtnFace+1 : myWin.cbClsExtra = 0
myWin.lpszMenuName = %NULL : myWin.cbWndExtra = 0
myWin.lpszClassName = VarPTR(szAppName) : myWin.hInstance = hInst
myWin.hIconSm = LoadIcon(hInst, ByVal %IDI_APPLICATION) : RegisterClassEx myWin
hMainWnd = CreateWindow(szAppName, "SDK", %WS_OverlappedWindow, 500,400,300,400,%Null, %Null, hInst, ByVal %Null)
hTemp = CreateWindow("Button","Ok1",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_PushButton, _
10,10,80,20,hMainWnd,%IDC_Btn01,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok2",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_DefPushButton, _
10,40,80,20,hMainWnd,%IDC_Btn02,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok3 (3State)",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_Auto3State, _
10,70,120,20,hMainWnd,%IDC_Btn03,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok4",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_AutoCheckbox, _
10,100,80,20,hMainWnd,%IDC_Btn04,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok5a",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_AutoRadioButton, _
10,130,60,20,hMainWnd,%IDC_Btn05,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok5b",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_AutoRadioButton, _
89,130,60,20,hMainWnd,%IDC_Btn06,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok6",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_Groupbox, _
180,10,80,60,hMainWnd,%IDC_Btn07,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hTemp = CreateWindow("Button","Ok7",%WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_Bitmap, _
180,80,100,100,hMainWnd,%IDC_Btn08,GetWindowLong(hMainWnd, %GWL_HINSTANCE), %Null)
hBmp = LoadImage(GetModuleHandle(""), "cowgirl", %IMAGE_BITMAP, 0, 0, 0)
SendMessage hTemp, %BM_SetImage, %Image_Bitmap, hBMP
ShowWindow hMainWnd, iCmdShow : UpdateWindow hMainWnd
Do While GetMessage(Msg, %NULL, 0, 0) : TranslateMessage Msg : DispatchMessage Msg : Loop
End Function
Function WndProc (ByVal hWnd AS DWord, ByVal wMsg AS DWord, ByVal wParam AS DWord, ByVal lParam As Long) EXPORT As Long
' WndProc is the message handler for all windows creating using the HelloWin class name.
Local hDC As DWord, pPaint AS PAINTSTRUCT, tRect AS RECT
Select Case wMsg
Case %WM_CREATE
Case %WM_PAINT
Case %WM_ERASEBKGND
Case %WM_DESTROY
PostQuitMessage 0
Exit Function
End Select
Function = DefWindowProc(hWnd, wMsg, wParam, lParam) 'if not handled above, pass to Windows default message handler.
End Function
'gbs_00385
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm