 : copy ( str -- )
     lf>crlf [
         string>u16-alien
-        f OpenClipboard win32-error=0/f
         EmptyClipboard win32-error=0/f
         GMEM_MOVEABLE over length 1+ GlobalAlloc
             dup win32-error=0/f
     
         dup GlobalLock dup win32-error=0/f
-        rot dup length memcpy
+        swapd byte-array>memory
         dup GlobalUnlock win32-error=0/f
         CF_UNICODETEXT swap SetClipboardData win32-error=0/f
     ] with-clipboard ;

    get-dc dup setup-pixel-format dup get-rc ;

M: windows-ui-backend (open-window) ( world -- )
    [ rect-dim first2 create-window dup setup-gl ] keep
    [ f <win> ] keep
    [ swap win-hWnd register-window ] 2keep
    dupd set-world-handle

        RegisterClassEx dup win32-error=0/f
    ] when ;

: adjust-RECT ( RECT -- )
    style 0 ex-style AdjustWindowRectEx win32-error=0/f ;

: make-RECT ( world -- RECT )
    dup world-loc { 40 40 } vmax dup rot rect-dim v+
    "RECT" <c-object>
    over first over set-RECT-right
    swap second over set-RECT-bottom
    over first over set-RECT-left
    swap second over set-RECT-top ;

: make-adjusted-RECT ( rect -- RECT )
    make-RECT dup adjust-RECT ;

: create-window ( rect -- hwnd )
    make-adjusted-RECT
    >r class-name-ptr get-global f r>
    >r >r >r ex-style r> r>
        { WS_CLIPSIBLINGS WS_CLIPCHILDREN style } flags
    r> get-RECT-dimensions
    f f f GetModuleHandle f CreateWindowEx dup win32-error=0/f ;

: show-window ( hWnd -- )
