Win32Forth


Window -- Class for window objects.


Glossary

:CLASS Window         <SUPER Generic-Window

Base class for window objects.

:M ClassInit:   ( -- )

Initialise the class.

Window sizing

:M GetSize:     ( --width height )

Get the size (width and height) of the window.

:M Width:       ( -- width )

Get the width of the window.

:M Height:      ( -- height )

Get the height of the window.

:M SetSize:     ( width height -- )

Set the size of the window.
Note: The window itself will not be resized.

:M On_Size:     ( wParam -- )

User windows should override the On_Size: method. When this method is called, the variables Width and Height will have already been set.
Default does nothing

:M MinSize:     ( -- width height )

To change the minimum window size, override the MinSize: method. Default is 10 by 10.

:M MaxSize:     ( -- width height )

To change the maximum window size, override the MaxSize: method. Default is 8192 by 8192.

:M StartSize:   ( -- width height )

To change the size of the window when it's created, override the StartSize: method or call the SetSize: method before you create the window.

:M SetOrigin:   ( x y -- )

To set the upper left corner of the window when it's created call the SetOrigin: method before you create the window.

:M StartPos:    ( -- left top )

User windows should override the StartPos: method to set the upper left corner of the window when it's created.

Window creation

:M SetClassLong: ( long offset -- )

The SetClassLong method replaces the specified 32-bit (long) value at the specified offset into the extra class memory or the WNDCLASS structure for the class to which the window belongs.

:M GetClassLong: ( offset -- long )

The GetClassLong function retrieves the specified 32-bit (long) value from the WNDCLASS structure associated with the window.

:M WndClassStyle:       ( -- style )

User windows should override the WndClassStyle: method to set the style member of the the WNDCLASS structure associated with the window. Default style is CS_DBLCLKS, CS_HREDRAW and CS_VREDRAW.

To prevent flicker on sizing of the window your method should return CS_DBLCLKS only.

:M Start:       ( -- )

Create the window.

Before the window is created a default window class name for this window will be set. Every window will become it's own class name and it's own window class. Note: If the window class name is set with SetClassName: before the Start: method is called no default class name will be set.

:M On_Init:     ( -- )

Thing's to do during creation of the window. Default does nothing.

:M On_Done:     ( -- )

Thing's to do when the window will be destroyed. Default does nothing.

Your On_Init: and On_Done: methods should look like this:

     :M On_Init:  ( -- )
             On_Init: super
             ... other initialization ...
             ;M

     :M On_Done:  ( -- )
             ... other cleanup ...
             On_Done: super
             ;M


The main application window will need the following methods, which cause the
program to terminate when the user closes the main application window.
Don't uncomment these out here, copy them into your application window
Object or Class, and then uncomment them out.

:M WM_CLOSE  ( h m w l -- res )
             bye
             0 ;M

:M On_Done:  ( h m w l -- res )
             0 call PostQuitMessage drop     \ terminate application
             On_Done: super                  \ cleanup the super class
             0 ;M

For multi-tasking applications the main window of each task should define
the following method, to quit the message loop and exit the task.

:M On_Done:  ( h m w l -- res )
             0 call PostQuitMessage drop     \ terminate application
             On_Done: super                  \ cleanup the super class
             0 ;M
:M SetClassName: ( addr len -- )

Set the window class name.

:M GetClassName: ( -- addr len )

Get the window class name.

:M SetParentWindow: ( hWndParent -- )

Set handle of the owner window (0 if no parent).

:M GetParentWindow: ( -- hWndParent )

Get the handle of the owner window (0 if no parent).

:M SetParent:   ( hWndParent -- )

Set handle of the owner window (0 if no parent).

NOTE: This method is depreacted. Use SetParentWindow: instead.

:M ParentWindow: ( -- hWndParent )

Get the handle of the owner window (0 if no parent).

NOTE: This method is depreacted. Use GetParentWindow: instead.

:M DefaultCursor: ( -- cursor-id )

User windows should override the DefaultCursor: method to set the default cursor for window. Default is IDC_ARROW.

:M DefaultIcon: ( -- hIcon )

User windows should override the WindowStyle: method to set the default icon handle for window. Default is the W32F icon.

:M WindowStyle: ( -- style )

User windows should override the WindowStyle: method to set the window style. Default is WS_OVERLAPPEDWINDOW.

:M ExWindowStyle: ( -- extended_style )

User windows should override the ExWindowStyle: method to set the extended window style. Default is NULL.

:M WindowTitle: ( -- Zstring )

User windows should override the WindowTitle: method to set the window caption. Default is "Window".

Painting

WinDC dc

The window's device context.
It will be valid only when handling the WM_PAINT message (see On_Paint: method)

Record: &ps

The PAINTSTRUCT for Begin- and EndPaint
It will be valid only when handling the WM_PAINT message (see On_Paint: method)

:M On_EraseBackground: ( hwnd msg wparam lparam -- res )

User windows should override the On_EraseBackground: method to handle WM_ERASEBKGND messages.
Default does nothing.

:M On_Paint:    ( -- )

User windows should override the On_Paint: method to handle WM_PAINT messages.
Before this method is called BeginPaint will be called so that the PAINTSTRUCT (&PS ivar) and the window device context (DC ivar) are initialized.
Check ps_fErase in your method to see if the background of the window should be drawn and use ps_left, ps_top, ps_right and ps_bottom to see which part of the window should be painted.
Default does nothing.

Menu support

:M WindowHasMenu: ( -- flag )

Flag is true if the window has a menu. Override this method if your window has a menu. Default is false.

Cursor (caret) support

:M MoveCursor:  ( gx gy -- )

Move the caret.

:M MakeCursor:  ( gx gy width height -- )

Create the caret.

:M DestroyCursor: ( -- )

Destroy the caret.

:M ShowCursor:  ( -- )

Show the caret.

:M HideCursor:  ( -- )

Hide the caret.

:M On_SetFocus: ( h m w l -- )

Override the method to handle the WM_SETFOCUS message.
Example: When cursor is used, you will need something like the following to control the position of the cursor in the window:

           cursor-col char-width  *
           cursor-row char-height *
           char-width char-height MakeCursor: self
:M On_KillFocus: ( h m w l -- )

Override the method to handle the WM_KILLFOCUS message.
Example: Use only when you are displaying a cursor in the window:

           DestroyCursor: self

Keyboard and mouse handling

:M PushKey:     ( c1 -- )

override to process keys yoruself.

Message handling

:M Win32Forth:  ( h m w l -- )

If you define an application specific window class or window object that redefines the method Win32Forth: to perform its own function rather than just doing a beep, then your window will be able to handle interprocess messages.

:M DefWindowProc: ( h m w l -- res )

Call the DefaultWindowProc for the window.

everything else...

:M CenterWindow: ( -- x y )

Calculate the position of the window to center it in the middle of it's parent window. When the windows has no parent it will be placed in the middle of the primary display monitor.

:M Enable:      ( f1 -- )

Enable or disable the window.

:M GetWindowRect: ( -- left top right bottom )

The GetWindowRect method retrieves the dimensions of the bounding rectangle of the window. The dimensions are given in screen coordinates that are relative to the upper-left corner

:M SetTitle:    { adr len \ temp$ -- }

Set the window title.

;CLASS

End of window class.

Helper words outside the class

: find-window   ( z"a1 -- hWnd ) \ w32f

Find a window.

: send-window   ( lParam wParam Message_ID hWnd -- ) \ w32f

Send a message to a window.

: LoadIconFile  ( adr len -- hIcon ) \ w32f

Load an icon from an icon file.


Document $Id: Window.htm,v 1.18 2007/05/26 10:24:12 dbu_de Exp $