Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Include "Win32API.inc"
#Resource Icon logo "test.ico"
Enum Equates Singular
IDC_Button = 500
IDC_ComboBox
IDC_Edit
IDC_ListBox
IDC_RichEdit
IDC_ScrollBar
IDC_Static
End Enum
Global hWndMain As Dword
Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword, ByVal lpCmdLine As AsciiZ Ptr, ByVal iCmdShow As Long) As Long
'arguments to WinMain are provided by Windows - not defined by the programmer
'hInstance current instance of the application
'hPrevInstance previous instance (not used - returns %Null in Win32)
'lpCmdLine pointer to command line (whatever the user types in after MyApp.EXE). A null terminated string.
'iCmdShow used the first time ShowWindow is called to display the application main window
Local Msg As tagMsg
Local W As WndClassEx
Local szAppName As AsciiZ * 80
Local hWndButton As Dword
Local hInstance As Dword
Local hAccel As Dword
Local WndStyle As Long
Local WndStyleX As Long
'register window class
szAppName = "HelloSDK"
W.cbSize = SizeOf(W)
W.Style = %CS_HREDRAW Or %CS_VREDRAW '%WS_OverlappedWindow Or %WS_HScroll Or %WS_VScroll '
W.lpfnWndProc = CodePtr(WndProc)
W.cbClsExtra = 0
W.cbWndExtra = 0
W.hInstance = hInst
W.hIcon = LoadIcon(hInst, "logo")
W.hCursor = LoadCursor(%NULL, ByVal %IDC_ARROW)
W.hbrBackground = %Color_BtnFace+1
W.lpszMenuName = %NULL
W.lpszClassName = VarPtr(szAppName)
W.hIconSm = LoadIcon(hInst, ByVal %IDI_APPLICATION) 'why not %NULL
RegisterClassEx W
'create window of that class
WndStyle = %WS_OverlappedWindow
WndStyleX = %WS_Ex_Left
hWndMain = CreateWindowEX( _
WndStyleX, _ 'dwStyle extended style of window
szAppName, _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"SDK", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
500, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
400, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
300, _ 'nWidth width in device units
400, _ 'nHeight height in device units
%Null, _ 'hWndParent handle to parent window (optional for a pop-up window)
%Null, _ 'hMenu handle to a menu or child window control ID
hInst, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
CreateButton
CreateComboBox
CreateEdit
CreateListBox
CreateRichEdit
CreateScrollbar
CreateStatic
'predefined lpClassName values: Button, ComboBox, Edit, ListBox, MDIClient, RichEdit, RichEdit_Class, Scrollbar, Static
'window not shown automatically. must show it manually
ShowWindow hWndMain, iCmdShow 'controls how window is to be shown. 1st must use iCmdShow
UpdateWindow hWndMain 'sends the window it's first WM_Create to display the window on the screen
'message pump - calls WndProc whenever an application-specific message is received
'WndProc can process the message, or pass it on to a the default window procedure that is built into Windows.
While GetMessage(Msg, %NULL, 0, 0) > 0
If IsFalse TranslateAccelerator (hWndMain, hAccel, Msg) Then
If IsFalse ISDialogMessage (hWndMain, Msg) Then
TranslateMessage Msg
DispatchMessage Msg
End If
End If
Wend
End Function
Function WndProc (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal wParam As Dword, ByVal lParam As Long) Export As Long
Local hDC As Dword, pPaint As PAINTSTRUCT, tRect As RECT
Local pnmhdr As NmHdr Ptr
Select Case wMsg
Case %WM_Destroy : PostQuitMessage 0 : Exit Function
Case %WM_Command
Select Case Lo(Word,wParam)
Case %IDC_Button
Select Case Hi(Word,wParam)
Case %BN_Clicked
? "Clicked"
End Select
End Select
End Select
Case %WM_Notify
pnmhdr = lParam
Select Case @pnmhdr.idFrom 'Control ID
Case %IDC_Button
Select Case @pnmhdr.code 'Notification code
Case %NM_Click
End Select
End Select
Case %WM_ERASEBKGND 'sent when the window background must be erased (such as resizing)
hDC = wParam
DrawGradient hDC ' Pass the DC of the region to repaint
Function = 1 : Exit Function
Case %WM_Paint 'set when request is made to paint a portion of an application's window.
hDC = BeginPaint(hWnd, pPaint)
GetClientRect hWnd, tRect
SetBkMode hDC, %TRANSPARENT
SetTextColor hDC, %White
DrawText hDC, "SDK is the Way!", -1, tRect, %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
EndPaint hWnd, pPaint
Function = 1 : Exit Function
End Select
Function = DefWindowProc(hWnd, wMsg, wParam, lParam) 'if not handled above, pass to Windows default message handler.
End Function
Sub DrawGradient (ByVal hDC As Dword)
Local rectFill As RECT, rectClient As RECT, fStep As Single, hBrush As Dword, lOnBand As Long
GetClientRect WindowFromDC(hDC), rectClient
fStep = rectClient.nbottom / 200
For lOnBand = 0 To 199
SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
hBrush = CreateSolidBrush(RGB(0, 0, 255 - lOnBand))
Fillrect hDC, rectFill, hBrush
DeleteObject hBrush
Next
End Sub
Sub CreateButton
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child Or %BS_DefPushButton
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
'Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20, Style, XStyle Call ButtonProc
hWnd= CreateWindow( _
"Button", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"Button", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
10, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_Button, _ 'hMenu handle to a menu
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateComboBox
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"ComboBox", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"ComboBox", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
40, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_ComboBox, _ 'hMenu handle to a menu or child window control ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateEdit
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"Edit", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"Edit", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
70, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_Edit, _ 'hMenu handle to a menu or child window control ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateListBox
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"ListBox", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"ListBox", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
100, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_ListBox, _ 'hMenu handle to a menu or child window control ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateRichEdit
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"RichEdit_Class", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"RichEdit", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
130, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_RichEdit, _ 'hMenu handle to a menu or child window control ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateScrollbar
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"Scrollbar", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"Scrollbar", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
160, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_Scrollbar, _ 'hMenu handle to a menu or child window control ID or child ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
Sub CreateStatic
Local WndStyle As Long, hWnd,hInstance As Dword
'create window of existing class "Button"
WndStyle = %WS_TabStop Or %WS_Visible Or %WS_Child Or %SS_WhiteRect
hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
hWnd= CreateWindow( _
"Static", _ 'lpClassName pointer to a null-terminated string (any registered name, including predefined system class names).
"Static", _ 'lpWindowName pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
WndStyle, _ 'dwStyle style of window
10, _ 'x initial horizontal position (upper left screen, except for child is relative to parent window's client area)
190, _ 'y initial vertical position (upper left screen, except for child is relative to parent window's client area)
80, _ 'nWidth width in device units
20, _ 'nHeight height in device units
hWndMain, _ 'hWndParent handle to parent window (optional for a pop-up window)
%IDC_Static, _ 'hMenu handle to a menu or child window control ID
hInstance, _ 'handle to instance of the module to be associated with the window
ByVal %Null _ 'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
)
End Sub
http://www.garybeene.com/sw/gbsnippets.htm