factor/contrib/win32/examples.factor

56 lines
1.6 KiB
Factor
Raw Normal View History

2005-11-28 22:31:00 -05:00
IN: win32
2006-02-22 20:53:01 -05:00
USING: alien namespaces math io prettyprint kernel words ;
USING: inspector ;
2005-11-28 22:31:00 -05:00
SYMBOL: hInst
SYMBOL: wc
SYMBOL: className "SimpleWindowClass" className set
: hello-world
f "Hello, world!" "First Application" MB_OK MessageBox win32-error drop ;
2005-11-28 22:31:00 -05:00
! : message-loop ( -- )
! message-loop ;
2006-02-22 20:53:01 -05:00
: wndproc ( hwnd uMsg wParam lParam -- lresult )
"uint" { "void*" "uint" "long" "long" } [
pick WM_DESTROY = [
3drop drop
f PostQuitMessage 0
] [
DefWindowProc
] if
] alien-callback ;
: register-wndclassex ( name wndproc -- )
"WNDCLASSEX" <c-object>
2005-11-28 22:31:00 -05:00
"WNDCLASSEX" c-size over set-WNDCLASSEX-cbSize
CS_HREDRAW CS_VREDRAW bitor over set-WNDCLASSEX-style
2006-02-22 20:53:01 -05:00
>r execute r> [ set-WNDCLASSEX-lpfnWndProc ] keep
2005-11-28 22:31:00 -05:00
0 over set-WNDCLASSEX-cbClsExtra
0 over set-WNDCLASSEX-cbWndExtra
hInst get over set-WNDCLASSEX-hInstance
2006-02-22 20:53:01 -05:00
! COLOR_WINDOW 1+ GetSysColorBrush over set-WNDCLASSEX-hbrBackground
! "" over set-WNDCLASSEX-lpszMenuName
! [ set-WNDCLASSEX-lpszClassName ] keep
f IDI_APPLICATION LoadIcon over [ set-WNDCLASSEX-hIcon ] 2keep
set-WNDCLASSEX-hIconSm
f IDC_ARROW LoadCursor over set-WNDCLASSEX-hCursor
2005-11-28 22:31:00 -05:00
! RegisterClassEx
2006-02-22 20:53:01 -05:00
;
: app2
f GetModuleHandle hInst set
"App2" \ wndproc register-wndclassex
! 0 className get "Second Application" WS_OVERLAPPEDWINDOW CW_USEDEFAULT CW_USEDEFAULT CW_USEDEFAULT CW_USEDEFAULT f f hInst get f CreateWindowEx
2005-11-28 22:31:00 -05:00
! dup SW_SHOWDEFAULT ShowWindow
! dup UpdateWindow
! message-loop
! f GetModuleHandle
;