 : ui-wndproc ( -- object )
     "uint" { "void*" "uint" "long" "long" } "stdcall" [
         [
-        pick
+        pick ! global [ dup windows-message-name . ] bind
             {
                 { [ dup WM_CLOSE = ]    [ drop handle-wm-close 0 ] }
                 { [ dup WM_PAINT = ]

                { [ dup WM_KEYUP = over WM_SYSKEYUP = or ]
                    [ drop 4dup handle-wm-keyup DefWindowProc ] }

                { [ dup WM_SETFOCUS = ] [ drop handle-wm-set-focus 0 ] }
                { [ dup WM_KILLFOCUS = ] [ drop handle-wm-kill-focus 0 ] }


    hWnd get window-focus send-gesture
    drop ;

: handle-wm-syscommand ( hWnd uMsg wParam lParam -- n )
    dup alpha? [ 3drop drop 0 ] [ DefWindowProc ] if ;

: cleanup-window ( handle -- )
    dup win-title [ free ] when*
    dup win-hRC wglDeleteContext win32-error=0/f
