|
| TEXTBLOCK HELLOWIN.C -- (c) Charles Petzold, 1992
/*--------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows" in client area
(c) Charles Petzold, 1992
HELLOWIN.PRG - CA Visual Objects adaptation
John Forsberg, 1994
--------------------------------------------------------*/
FUNCTION Start()
STATIC szAppName := "HelloWin" AS STRING
LOCAL hWnd AS WORD
LOCAL msg IS
_WINMSG
LOCAL wndclass IS
_WINWNDCLASS
/* Parameters not received by VO */
LOCAL hPrevinstance := _GetPrevInst() AS WORD
LOCAL hInstance := _GetInst() AS WORD
LOCAL nCmdShow := _GetCmdShow() AS WORD
IF hPrevInstance == 0
wndclass.style := _OR(CS_HREDRAW, CS_VREDRAW)
wndclass.lpfnWndProc := @WndProc()
wndclass.cbClsExtra := 0
wndclass.cbWndExtra := 0
wndclass.hInstance := hInstance
wndclass.hIcon := LoadIcon (hInstance,
IDI_APPLICATION)
wndclass.hCursor := LoadCursor (0, IDC_ARROW)
wndclass.hbrBackground := GetStockObject (WHITE_BRUSH)
wndclass.lpszMenuName := ""
wndclass.lpszClassName := szAppName
RegisterClass (@wndclass)
ENDIF
hwnd := CreateWindow (szAppName, ; // window class name
"The Hello Program", ; // window
caption
WS_OVERLAPPEDWINDOW, ; // window style
CW_USEDEFAULT, ; // initial x
position
CW_USEDEFAULT, ; // initial y
position
CW_USEDEFAULT, ; // initial x
size
CW_USEDEFAULT, ; // initial y
size
0, ;
// parent window handle
0, ;
// window menu handle
hInstance, ;
// program instance handle
NULL_PTR) //
creation parameters
/* Not in the book. Add it if you prefer */
// if hWnd = 0
// return FALSE
// endif
ShowWindow (hwnd, nCmdShow)
UpdateWindow (hwnd)
WHILE (GetMessage (@msg, 0, 0, 0))
TranslateMessage (@msg)
DispatchMessage (@msg)
END
/* Not in the book. Add it if you prefer */
// UnregisterClass ( szAppName, hInstance )
RETURN msg.wParam
FUNCTION WndProc (hwnd AS WORD, message AS WORD, wParam AS WORD, ;
lParam AS LONG) AS LONG _WINCALL
LOCAL hdc AS WORD
LOCAL ps IS _WINPAINTSTRUCT
LOCAL rect IS _WINRECT
DO CASE
CASE message == WM_PAINT
hdc := BeginPaint (hwnd, @ps)
GetClientRect (hwnd, @rect)
DrawText (hdc, "Hello, Windows!", -1, @rect, ;
_OR(_OR(DT_SINGLELINE, DT_CENTER), DT_VCENTER))
EndPaint (hwnd, @ps)
RETURN 0L
CASE message == WM_DESTROY
PostQuitMessage (0)
RETURN 0L
ENDCASE
RETURN DefWindowProc (hwnd, message, wParam, lParam) |