#include once "windows.bi"
'Declare Function WinMain ( ByVal hInstance As HINSTANCE, _
' ByVal hPrevInstance As HINSTANCE, _
' ByRef szCmdLine As String, _
' ByVal iCmdShow As Integer ) As Integer
'
'
' ''
' '' Entry point
' ''
' WinMain( GetModuleHandle( null ), null, Command$, SW_NORMAL )
'' ::::::::
'' name: WndProc
'' desc: Processes windows messages
''
'' ::::::::
Function WndProc ( ByVal hWnd As HWND, _
ByVal message As UINT, _
ByVal wParam As WPARAM, _
ByVal lParam As LPARAM ) As LRESULT
Function = 0
''
'' Process messages
''
Select Case( message )
''
'' Window was created
''
Case WM_CREATE
Exit Function
'' User clicked the form
Case WM_LBUTTONUP
MessageBox NULL, "Hello world from FreeBasic", "FB Win", MB_OK
''
'' Windows is being repainted
''
Case WM_PAINT
Dim rct As RECT
Dim pnt As PAINTSTRUCT
Dim hDC As HDC
hDC = BeginPaint( hWnd, @pnt )
GetClientRect( hWnd, @rct )
DrawText( hDC, _
"Hello Windows from FreeBasic!", _
-1, _
@rct, _
DT_SINGLELINE Or DT_CENTER Or DT_VCENTER )
EndPaint( hWnd, @pnt )
Exit Function
''
'' Key pressed
''
Case WM_KEYDOWN
'Close if esc key pressed
If( LoByte( wParam ) = 27 ) Then
PostMessage( hWnd, WM_CLOSE, 0, 0 )
End If
''
'' Window was closed
''
Case WM_DESTROY
PostQuitMessage( 0 )
Exit Function
End Select
''
'' Message doesn't concern us, send it to the default handler
'' and get result
''
Function = DefWindowProc( hWnd, message, wParam, lParam )
End Function
'' ::::::::
'' name: WinMain
'' desc: A win2 gui program entry point
''
'' ::::::::
'Function WinMain ( ByVal hInstance As HINSTANCE, _
' ByVal hPrevInstance As HINSTANCE, _
' ByREf szCmdLine As String, _
' ByVal iCmdShow As Integer ) As Integer
Dim wMsg As MSG
Dim wcls As WNDCLASS
Dim szAppName As String
Dim hWnd As HWND
'Function = 0
''
'' Setup window class
''
szAppName = "HelloWin"
With wcls
.style = CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = GetModuleHandle(null) 'hInstance
.hIcon = LoadIcon( NULL, IDI_APPLICATION )
.hCursor = LoadCursor( NULL, IDC_ARROW )
.hbrBackground = GetStockObject( WHITE_BRUSH )
.lpszMenuName = NULL
.lpszClassName = StrPtr( szAppName )
End With
''
'' Register the window class
''
If( RegisterClass( @wcls ) = FALSE ) Then
MessageBox( null, "Failed to register wcls!", szAppName, MB_ICONERROR )
'Exit Function
End If
''
'' Create the window and show it
''
hWnd = CreateWindowEx( 0, _
szAppName, _
"The Hello Program", _
WS_OVERLAPPEDWINDOW, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
NULL, _
NULL, _
GetModuleHandle(null), _ 'hInstance hInstance, _
NULL )
ShowWindow( hWnd, SW_NORMAL) 'iCmdShow )
UpdateWindow( hWnd )
''
'' Process windows messages
''
While( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )
TranslateMessage( @wMsg )
DispatchMessage( @wMsg )
Wend
''
'' Program has ended
''
' Function = wMsg.wParam
'End Function