Generic-Window is the base class for all window objects. This class contains a single ivar, hWnd, that is the (MS Windows) handle for the window. This class encapsulates all the Win32 API calls that specify a window handle. There will be the following subclasses of Generic-Window:
Since Generic-Window is a generic class it should not be used to create
any instances.
The Global Rectangle objects wRect and WndRect ( originally
defined in Window.f ) have been replaced by a Rectangle IVAR WinRect so that
Windows in different threads don't interfere with each other's drawing
operations.
For backwards compatibility wRect is defined as an int which is set
to the address of WinRect by the ClassInit: method ( and WndRect is defined as
an alias of wRect in Window.f. Also ) however WinRect should be used in new
code since it uses early binding. ClientRect in class EditControl ( in Controls.f )
is also defined as an alias of wRect for compatibility.
We also provide wRect as an alias of TempRect for compatibility.
Temporarily added new generic class Dialog&Control and moved some code into it and
duplicated the same code in Class Window so that Ivar offsets in Class Window are
the same for temporary compatibility.
: get-mouse-xy ( hWnd -- x y) \ W32F
Return the co-ordinates of the mouse pointer in window, hWnd.
:CLASS Generic-Window <Super Object
Base class for all window objects.
int hWnd
handle to Win32 window object
: SendMessage:Self ( lParam wParam message -- result )
Send a windows message to our self.
: SendMessage:SelfDrop ( lParam wParam message -- )
Send a windows message to our self and discard the result.
:M Classinit: ( -- )
Initialise the class.
:M GetHandle: ( -- hWnd )
Get the window handle.
:M PutHandle: ( hWnd -- )
Set the window handle. Normally handled by the system.
:M ZeroWindow: ( -- )
Clear the window handle. Normally handled by the system. At start-up all window objects are zeroed automatically.
:M DestroyWindow: ( -- )
Destroy the window. The handle is always zero after executing this method. In a mult-tasking application this method causes an error if executed by a task that didn't create the window.
:M Close: ( -- )
Close the window.
:M Paint: ( -- )
Force window repaint. A WM_PAINT message is posted to the message queue.
:M SetRedraw: ( f -- )
Set the redraw state of the window.
f Specifies the redraw state. If this parameter is TRUE, the content can be redrawn after a change. If this parameter is FALSE, the content cannot be redrawn after a change.
:M Show: ( state -- )
The ShowWindow function sets the specified window's show state.
Possible values for state are:
SW_FORCEMINIMIZE | Windows 2000: Minimizes a window, even if the thread that owns the window is hung. This flag should only be used when minimizing windows from a different thread. |
SW_HIDE | Hides the window and activates another window. |
SW_MAXIMIZE | Maximizes the specified window. |
SW_MINIMIZE | Minimizes the specified window and activates the next top-level window in the Z order. |
SW_RESTORE | Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. |
SW_SHOW | Activates the window and displays it in its current size and position. |
SW_SHOWDEFAULT | Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. |
SW_SHOWMAXIMIZED | Activates the window and displays it as a maximized window. |
SW_SHOWMINIMIZED | Activates the window and displays it as a minimized window. |
SW_SHOWMINNOACTIVE | Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. |
SW_SHOWNA | Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated. |
SW_SHOWNOACTIVATE | Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived. |
SW_SHOWNORMAL | Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. |
If the window belongs to a different task or application the WM_SHOW is posted to the the message queue to prevent the current task hanging. If the window belongs to the current task the message is sent.
:M GDIFlush: ( -- )
The GdiFlush function flushes the calling thread's current batch.
:M Update: ( -- )
The UpdateWindow function updates the client area of the window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the window, bypassing the application queue. If the update region is empty, no message is sent.
:M Scroll: { x y -- }
The ScrollWindow function scrolls the contents of the specified window's client area.
:M Move: { x y w h -- }
The MoveWindow function changes the position and dimensions of window. For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. For a child window, they are relative to the upper-left corner of the parent window's client area.
:M SetWindowPos: { x y -- }
The SetWindowPos function changes the position of a child, pop-up, or top-level window.
X Specifies the new position of the left side of the window, in client coordinates.
Y Specifies the new position of the top of the window, in client coordinates.
:M SetMenu: ( MenuHandle -- )
The SetMenu function assigns a new menu to the window. If MenuHandle is NULL, the window's current menu is removed.
:M SetText: { addr len \ text$ -- }
The SetWindowText function changes the text of the window's title bar (if it has one). If the window is a control, the text of the control is changed.
:M GetText: ( -- addr len )
The GetWindowText function copies the text of the window's title bar (if it has one) into a buffer. If the window is a control, the text of the control is copied.
:M SetTextAlign: ( flag -- )
Set the text-alignment for the window.
The current position is updated after each text output call.
The current position is used as the reference point.
Possible values for flag are:
0 | The reference point will be on the left edge of the bounding rectangle. |
1 | The reference point will be on the right edge of the bounding rectangle. |
2 | The reference point will be aligned horizontally with the center of the bounding rectangle. |
:M GetDC: ( -- hdc )
The GetDC function retrieves a handle to a display device context (DC)
for the client area of the window.
You have to call ReleaseDC when the DC isn't needed any longer.
:M GetWindowDC: ( -- hdc )
The GetWindowDC function retrieves the device context (DC) for the entire
window, including title bar, menus, and scroll bars. A window device context
permits painting anywhere in a window, because the origin of the device context
is the upper-left corner of the window instead of the client area.
GetWindowDC assigns default attributes to the window device context each time it
retrieves the device context. Previous attributes are lost.
You have to call ReleaseDC when the DC isn't needed any longer.
:M ReleaseDC: ( hdc -- )
The ReleaseDC function releases the device context (DC) of the window.
Call only after GetDC or GetWindowDC.
:M BeginPaint: ( ps -- hdc )
The BeginPaint function prepares the window for painting and fills a PAINTSTRUCT (ps) structure with information about the painting.
:M EndPaint: ( ps -- )
The EndPaint function marks the end of painting in the window. This function is required for each call to the BeginPaint function, but only after painting is complete.
:M GetClientRect: ( rect -- )
The GetClientRect function retrieves the coordinates of the window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).
:M GetWindowLong: ( index -- value )
The GetWindowLong function retrieves information about the window. The function
also retrieves the 32-bit (long) value at the specified offset into the extra
window memory.
Index Specifies the zero-based offset to the value to be retrieved. Valid values are
in the range zero through the number of bytes of extra window memory, minus four; for
example, if you specified 12 or more bytes of extra memory, a value of 8 would be an
index to the third 32-bit integer. To retrieve any other value, specify one of the
following values.
GWL_EXSTYLE | Retrieves the extended window styles. For more information, see CreateWindowEx. |
GWL_STYLE | Retrieves the window styles. |
GWL_WNDPROC | Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure. |
GWL_HINSTANCE | Retrieves a handle to the application instance. |
GWL_HWNDPARENT | Retrieves a handle to the parent window, if any. |
GWL_ID | Retrieves the identifier of the window. |
GWL_USERDATA | Retrieves the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window. This value is initially zero. |
:M SetWindowLong: ( value index -- oldval )
The SetWindowLong function changes an attribute of the window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
GWL_EXSTYLE | Sets a new extended window style. For more information, see CreateWindowEx. |
GWL_STYLE | Sets a new window style. |
GWL_WNDPROC | Sets a new address for the window procedure. Windows NT/2000: You cannot change this attribute if the window does not belong to the same process as the calling thread. |
GWL_HINSTANCE | Sets a new application instance handle. |
GWL_ID | Sets a new identifier of the window. |
GWL_USERDATA | Sets the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window. This value is initially zero. |
:M GetStyle: ( -- style )
Retrieves the window styles.
:M SetStyle: ( style -- )
Sets a new window style.
:M +Style: ( style -- )
Add a window style.
:M -Style: ( style -- )
Remove a window style.
:M SetFocus: ( -- )
The SetFocus function sets the keyboard focus to the window. The window must be attached to the calling thread's message queue.
:M SetForegroundWindow: ( -- )
The SetForegroundWindow function puts the thread that created the specified window
into the foreground and activates the window. Keyboard input is directed to the window,
and various visual cues are changed for the user. The system assigns a slightly higher
priority to the thread that created the foreground window than it does to other threads.
The foreground window is the window at the top of the Z order. It is the window that the
user is working with. In a preemptive multitasking environment, you should generally let the
user control which window is the foreground window.
Windows 98, Windows 2000: The system restricts which processes can set the foreground window.
A process can set the foreground window only if one of the following conditions is true:
- The process is the foreground process.
- The process was started by the foreground process.
- The process received the last input event.
- There is no foreground process.
- The foreground process is being debugged.
- The foreground is not locked (see LockSetForegroundWindow).
- The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
- Windows 2000: No menus are active.
With this change, an application cannot force a window to the foreground while the user is
working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow)
and call the FlashWindowEx function to notify the user. For more information, see Foreground and
Background Windows.
A process that can set the foreground window can enable another process to set the foreground window by
calling the AllowSetForegroundWindow function. The process specified by dwProcessId loses the ability to
set the foreground window the next time the user generates input, unless the input is directed at that
process, or the next time a process calls AllowSetForegroundWindow, unless that process is specified.
The foreground process can disable calls to SetForegroundWindow by calling the LockSetForegroundWindow function.
:M SetActiveWindow: ( -- )
The SetActiveWindow function activates a window. The window must be attached to the calling thread's message queue.
The SetActiveWindow function activates a window, but not if the application is in the background. The window will be
brought into the foreground (top of Z order) if its application is in the foreground when the system activates the window.
If the window identified by the hWnd parameter was created by the calling thread, the active window status of the calling
thread is set to hWnd. Otherwise, the active window status of the calling thread is set to NULL.
By using the AttachThreadInput function, a thread can attach its input processing to another thread.
This allows a thread to call SetActiveWindow to activate a window attached to another thread's message queue.
:M MessageBox: ( szText szTitle style -- result )
The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons.
szText | Pointer to a null-terminated string that contains the message to be displayed. |
szTitle | Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title Error is used. |
Type | Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags. |
To indicate the buttons displayed in the message box, specify one of the following values. |
MB_ABORTRETRYIGNORE | The message box contains three push buttons: Abort, Retry, and Ignore. |
MB_CANCELTRYCONTINUE | Windows 2000: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE. |
MB_HELP | Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner. |
MB_OK | The message box contains one push button: OK. This is the default. |
MB_OKCANCEL | The message box contains two push buttons: OK and Cancel. |
MB_RETRYCANCEL | The message box contains two push buttons: Retry and Cancel. |
MB_YESNO | The message box contains two push buttons: Yes and No. |
MB_YESNOCANCEL | The message box contains three push buttons: Yes, No, and Cancel. |
To display an icon in the message box, specify one of the following values.
MB_ICONEXCLAMATION, MB_ICONWARNING | An exclamation-point icon appears in the message box. |
MB_ICONINFORMATION, MB_ICONASTERISK | An icon consisting of a lowercase letter i in a circle appears in the message box. |
MB_ICONQUESTION | A question-mark icon appears in the message box. |
MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND | A stop-sign icon appears in the message box. |
To indicate the default button, specify one of the following values.
MB_DEFBUTTON1 | The first button is the default button. MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified |
MB_DEFBUTTON2 | The second button is the default button. |
MB_DEFBUTTON3 | The third button is the default button. |
MB_DEFBUTTON4 | The fourth button is the default button. |
To specify other options, use one or more of the following values.
MB_RIGHT | The text is right-justified. |
MB_SETFOREGROUND | The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box. |
MB_TOPMOST | The message box is created with the WS_EX_TOPMOST window style. |
If the function succeeds, the return value is one of the following menu-item values.
IDABORT | Abort button was selected. |
IDCANCEL | Cancel button was selected. |
IDCONTINUE | Continue button was selected. |
IDIGNORE | Ignore button was selected. |
IDNO No | button was selected. |
IDOK OK | button was selected. |
IDRETRY | Retry button was selected. |
IDTRYAGAIN | Try Again button was selected. |
IDYES | Yes button was selected. |
:M InvalidateRect: ( bgflag rectangle -- )
The InvalidateRect function adds a rectangle to the window's update region. The update region represents the portion of the window's client area that must be redrawn.
lpRect | Pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region. |
bErase | Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. |
:M GetDlgItem: ( id -- handle )
The GetDlgItem function retrieves a handle of the control (id) in the window.
:M GetDlgItemText: ( addr len id -- len )
The GetDlgItemText function retrieves the title or text associated with a control in the window.
:M SetDlgItemText: ( addr len id -- )
The SetDlgItemText function sets the title or text of a control in then window.
:M SetDlgItemFocus: ( id -- )
Set the focus to the control (id) in the window.
:M SelectDlgItemAll: ( id -- )
Selects all characters in the edit control (id). You can use this forn an edit control or a rich edit control.
:M IsDlgButtonChecked: ( id -- f1 )
The IsDlgButtonChecked function determines whether a button control has a check mark next to it or whether a three-state button control is grayed, checked, or neither.
:M CheckDlgButton: ( uCheck id -- )
The CheckDlgButton function changes the check state of a button control. Possible values for uCheck are:
BST_CHECKED | Sets the button state to checked. |
BST_INDETERMINATE | Sets the button state to grayed, indicating an indeterminate state. Use this value only if the button has the BS_3STATE or BS_AUTO3STATE style. |
BST_UNCHECKED | Sets the button state to cleared |
:M SetDlgItemAlign: ( flag id -- )
Set the text-alignment for a control (id) in the window.
The current position is updated after each text output call.
The current position is used as the reference point.
Possible values for flag are:
0 | The reference point will be on the left edge of the bounding rectangle. |
1 | The reference point will be on the right edge of the bounding rectangle. |
2 | The reference point will be aligned horizontally with the center of the bounding rectangle. |
:M SetAlign: ( flag id -- ) \ DEPRECATED
Obsolescent Method use SetDlgItemAlign: instead.
:M EnableDlgItem: ( flag id -- )
Enable or disable a control (id) in the window. Possible values for flag are:
0 | disable |
1 | enable |
:M ShowDlgItem: ( flag id -- )
Hide or show a control (id) in the window. Possible values for flag are:
0 | hide |
1 | show |
:M CheckRadioButton: ( check_id first_id last_id -- )
The CheckRadioButton function adds a check mark to (checks) a specified radio button in a group and removes a check mark from (clears) all other radio buttons in the group.
check_id | Specifies the identifier of the radio button to select. |
first_id | Specifies the identifier of the first radio button in the group. |
last_id | Specifies the identifier of the last radio button in the group. |
:M SendDlgItemMessage: ( lParam wParam message id -- long )
Send a message to the control (id) in the window.
:M SetDlgItemFont: ( FontObject id -- )
Specify the font that the control (id) is to use when drawing text.
FontObject must be the HANDLE of a font. If this parameter is NULL, the control uses the
default system font to draw text.
;CLASS
End of generic-window class
|CLASS DIALOG&CONTROL <SUPER Generic-Window
Base class for all dialog and control objects.
Since DIALOG&CONTROL is a generic class it should not be used to create any instances.
:M Classinit: ( -- )
Initialise the class.
: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 of the screen.
;CLASS
End of DIALOG&CONTROL class
Document $Id: Generic.htm,v 1.16 2007/05/26 10:24:12 dbu_de Exp $