PowerBASIC PbWin 9 SDK version.
Exe Size: 25,600
'======================================================================
' Declares
'----------------------------------------------------------------------
#COMPILE EXE
'----------------------------------------------------------------------
#IF %PB_REVISION < &H1000 ' if compiler PBWIN9 or earlier
%USEMACROS = 1
#ENDIF
#INCLUDE "WIN32API.INC"
'----------------------------------------------------------------------
%IDC_EDIT100 = 100
GLOBAL UserName AS STRING
'======================================================================
FUNCTION WINMAIN (BYVAL hInst AS DWORD, BYVAL hPrevInstance AS DWORD, _
BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
'----------------------------------------------------------------------
' Program entrance
'----------------------------------------------------------------------
LOCAL hDlg AS DWORD, hCtl AS DWORD, hEdit As DWORD ,hFont AS DWORD, _
sBuf AS STRING, wc AS WndClassEx, szClassName AS ASCIIZ * 80
hFont = GetStockObject(%DEFAULT_GUI_FONT)
szClassName = "MyClassName"
wc.cbSize = SIZEOF(wc)
wc.style = %CS_HREDRAW OR %CS_VREDRAW
wc.lpfnWndProc = CODEPTR(WndProc)
wc.cbClsExtra = 0
wc.cbWndExtra = 0
wc.hInstance = hInst
wc.hIcon = LoadIcon (%NULL, BYVAL %IDI_APPLICATION)
wc.hCursor = LoadCursor(%NULL, BYVAL %IDC_ARROW)
wc.hbrBackground = %COLOR_3DFACE + 1
wc.lpszMenuName = %NULL
wc.lpszClassName = VARPTR(szClassName)
wc.hIconSm = LoadIcon (%NULL, BYVAL %IDI_APPLICATION)
CALL RegisterClassEx (wc)
hDlg = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szClassName, "What is your name?", _
%WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR _
%DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT OR %DS_MODALFRAME OR _
%DS_CENTER, _
(GetSystemMetrics(%SM_CXSCREEN) - 246) / 2, _
(GetSystemMetrics(%SM_CYSCREEN) - 110) / 2, _
246, 110, 0, 0, GetModuleHandle(""), BYVAL %NULL)
hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL, _
21, 20, 201, 19, _
hDlg, %IDC_EDIT100, GetModuleHandle(""), BYVAL %NULL)
IF hFont THEN SendMessage hEdit, %WM_SETFONT, hFont, 0
hCtl = CreateWindowEx(0, "Button", "OK", _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
51, 52, 60, 23, _
hDlg, %IDOK, GetModuleHandle(""), BYVAL %NULL)
IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
hCtl = CreateWindowEx(0, "Button", "Cancel", _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
126, 52, 60, 23, _
hDlg, %IDCANCEL, GetModuleHandle(""), BYVAL %NULL)
IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
ShowWindow hDlg, nCmdShow
SetFocus(hEdit)
UpdateWindow hDlg
LOCAL Msg AS tagMsg
WHILE GetMessage(Msg, %NULL, 0, 0)
IF IsDialogMessage(hDlg,Msg) = 0 Then
TranslateMessage Msg
DispatchMessage Msg
END IF
WEND
If msg.wParam Then
MSGBOX "Hello " + UserName
End If
FUNCTION = msg.wParam
END FUNCTION
'======================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
'----------------------------------------------------------------------
' Main Window procedure
'----------------------------------------------------------------------
STATIC RetVal AS LONG
SELECT CASE wMsg
CASE %WM_CREATE
'A good place to initiate things, declare variables,
'create controls and read/set settings from a file, etc.
'-------------------------------------------------------
CASE %WM_COMMAND
'Messages from controls and menu items are handled here.
'-------------------------------------------------------
SELECT CASE LOWRD(wParam)
CASE %IDCANCEL ' <- Esc key also triggers %IDCANCEL
IF HIWRD(wParam) = %BN_CLICKED OR HIWRD(wParam) = 1 THEN
SendMessage hWnd, %WM_DESTROY, wParam, lParam
RetVal = 0
FUNCTION = 0 : EXIT FUNCTION
END IF
CASE %IDOK ' <- Enter key usually triggers %IDOK
IF HIWRD(wParam) = %BN_CLICKED OR HIWRD(wParam) = 1 THEN
CONTROL GET TEXT hWnd,%IDC_EDIT100 To UserName
RetVal = 1
SendMessage hWnd, %WM_DESTROY, wParam, lParam
END IF
END SELECT
CASE %WM_DESTROY
' is sent when program ends - a good place to delete any created objects and
' store settings in file for next run, etc. Must send PostQuitMessage to end
' properly in SDK-style dialogs. The PostQuitMessage function sends a WM_QUIT
' message to the program's (thread's) message queue, and then WM_QUIT causes
' the GetMessage function to return zero in WINMAIN's message loop.
'----------------------------------------------------------------------------
PostQuitMessage RetVal
FUNCTION = 0 : EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
END FUNCTION