Managing Windows


The Window class is the base class for all the Windows you will be manipulating in your application. Some of the Window classes' events will sound familiar; they are similar to the ones found in the App object. There are also some unique events, as well, which I will identify next.

Controls aren't subclasses of Windows, so they don't share a hierarchical class structure, but there is a hierarchical structure that is important to understand when working with them, and this is a hierarchy of containment. A Window will contain many Controls, and some Controls will contain even more Controls.

If you think of the Window as a flat sheet, the Controls are overlaid over the Window, and if a Control contains a second Control, the second Control is overlaid over the first. In other words, Controls and Windows are layered.

There are a few methods you can use to determine how many Controls a Window has and gain access to them without knowing their names:

Window.ControlCount as Integer Window.Control() as RectControl 


With these two pieces of information, you can iterate over all the Controls and do whatever you want to with them.

Window States

There are several states a Window can be in, and certain events are triggered whenever a Window changes from one state to another.

Windows can be activated or deactivated. A deactivated Window is a Window that is open, but that is not the front-most Window on the computer screen. When a Window that has been deactivated is activated by being returned to the front, the Activate event is triggered. You can have REALbasic worry about activation for you by setting AutoDeactivate to true.

In addition to being activated or deactivated, a Window can be minimized, which means that it is no longer visible in the desktop portion of the screen and is usually represented on the taskbar/dock/panel only. Windows get minimized when the Minimize button is clicked. When a minimized Window is restored, the Restore event is triggered.

A Window can be made visible or invisible by setting the Visible property to true. A second way of making an invisible Window visible is to call the Show method of the Window. In addition to making the Window visible, it also activates the Window if it was inactive and brings it to the front of the screen.

Hide, Show, Open, and Close

Hide and the various "Shows" don't remove or load a Window into memory. It simply makes it visible or not. If you want to remove a Window from memory, you need to Close it.

Users can manipulate the state of a Window by interacting with the title bar of the Window and the Tray/Dock.

Open, Close, and CancelClose Events

These events work just like the ones associated with the App class. The only caveat is that the CancelClose events are called on all open Windows before the Close events are called.

EnableMenuItems Event

EnableMenuItems serves the same purpose as it does in the App class.

Close, Minimize, and Maximize Methods

This method programmatically minimizes or maximizes Windows, which is equivalent to pressing the Close, Minimize, or Maximize buttons.

Restore Method

Returns a Window to its unminimized state.

Mouse Position

MouseX and MouseY Properties

These two properties identify the position of the mouse pointer at any given moment. MouseX measures how far from the left side of the Window the mouse is (the horizontal axis), and MouseY measures how far down it is from the top of the Window (the vertical axis).

MouseDown, MouseUp Events

MouseDown and MouseUp are both passed the coordinates X and Y, which indicate the position of the mouse when the mouse button was pressed down and the position when the mouse button was released.

MouseDown has a special role, both with Windows and, as you will see later on, in Controls. MouseDown is a function that returns a Boolean. If you return true from the MouseDown, then, and only then, will the MouseUp event be triggered.

MouseMove and MouseDrag Events

MouseMove gets passed coordinates just like MouseUp and MouseDown, and it indicates that the mouse is moving and that it is currently at position X and Y. MouseMove is fired only when the mouse button is not pressed down. The MouseDrag event, however, occurs when the mouse button remains pressed down while the mouse moves. MouseDrag is also contingent upon the MouseDown event; MouseDown must return true for you to get access to the MouseDrag event.

MouseEnter, MouseExit Events

MouseEnter and MouseExit fire when the mouse has moved the pointer into a position over the Window. The events are not passed the coordinates where this has taken place, because you can consult MouseMove, or MouseX and MouseY.

Top, Left

Top and Left refer to the actual pixel position of the Window.




REALbasic Cross-Platform Application Development
REALbasic Cross-Platform Application Development
ISBN: 0672328135
EAN: 2147483647
Year: 2004
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net