Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
#Resource Icon logo "test.ico"
Enum Equates Singular
IDC_Button = 500
End Enum
Global hWndMain,hButton 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, W As WndClassEx, szAppName As WStringZ * 80
Local hAccel As Dword, WndStyle, WndStyleX As Long
'register window class
szAppName = "HelloSDK"
W.cbSize = SizeOf(W)
W.Style = %CS_HREDRAW Or %CS_VREDRAW
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 Main window of that class
WndStyle = %WS_OverlappedWindow
WndStyleX = %WS_Ex_Left
hWndMain = CreateWindowEX(WndStyleX,szAppName,"SDK",WndStyle,500,400,200,100,%Null,%Null,hInst,ByVal %Null)
'create Button
WndStyle = %WS_Visible Or %WS_Child Or %WS_TabStop
WndStyleX = 0
hButton = CreateWindowEX(WndStyleX,"Button","OK",WndStyle,50,20,80,20,hWndMain,%IDC_Button,hInst, ByVal %Null)
'main 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
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_Command
Select Case Lo(Word,wParam)
Case %IDC_Button
Select Case Hi(Word,wParam)
Case %BN_Clicked
? "Clicked"
End Select
End Select
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
http://www.garybeene.com/sw/gbsnippets.htm