This unit contains definition of XWindow, which is a base class for XForm and XApplet. It is a
descender of XVisual and adds to it a set of properties and
methods peculiar to windows (i.e. to windows, which are to be registered in Windows
environment) : handle, styles, cursor, icon, menu and so on.
Creating of MFC-based controls, which use XWindow class, requires some
changes in its implementation, making it more similar to corresponding VCL class
TWinControl. But this does not lead to essencial increasing of size of resulting
executable, moreover with using only of MFC-based controls (vs self-painting controls) it
can become even smaller though this even expands set of possible controls, which could be
used by applet.
XWindow <= XVisual <= XClass <= TObject
XWindow properties:
- it is set when window is created and handle is allocated. Use it to pass it to Windows API functions, requiring window handle (e.g. ShowWindow). |
- returns handle of parent window. If this object is XForm, parent window is an applet button window. For windowed controls, parent window is a form of type XForm and its descenders. For MDI child form, parent window is its MDI parent window. |
- window class style. Default is CS_OWNDC.
Look at WNDCLASS topic in Win32.hlp to get more info about other possible flags. Set it before creating a window (just after constructing the object). It is possible to change class style at any time after creating but it is necessary to repaint the window in that case (e.g. invalidating it) to apply changes. |
- window style. Default is WS_VISIBLE + WS_CLIPCHILDREN
+ WS_CLIPSIBLINGS + WS_CAPTION + WS_SYSMENU + WS_MINIMIZEBOX + WS_MAXIMIZEBOX +
WS_OVERLAPPEDWINDOW + WS_BORDER +
WS_THICKFRAME. Look at CreateWindow topic in Win32.hlp to get more info about
window styles. Set Style property before creating a window. It is also possible to change style at any time after creating the window. |
- extended window style. Default is WS_EX_CONTROLPARENT.
Other possible flags are WS_EX_ACCEPTFILES, WS_EX_APPWINDOW, and more. Look at CreateWindowEx topic in
Win32.hlp to get more info about extended window style flags. Set ExStyle property before creating a window. And it is possible to change style later. |
- default cursor for window class. |
- default icon for window class. |
- default menu for window. |
- caption of window. |
- background color of client area not overlapped by children. This property is inherited from XVisual and made public in XWindow. |
- possible states are: xwsNormal, xwsMinimized, xwsMaximized. Default is xwsNormal. |
- this property is a type of pointer. It can point to a canvas of type XCanvas but only in case when canvases module is included into
executable (i.e. unit XCanvases.pas is used at least in one of linked modules). To know
how it works, look at the XCanvas type definition. If applet is using canvases, canvas of window can be obtained by calling function XCanvases.WindowCanvas( Window : XWindow ) : XCanvas. |
Properties inherited from XVisual:
Properties inherited from XClass:
XWindow methods:
- this method is intended to make process of creating MFC-based controls more
similar to this one in VCL. It is created from CreateWindow method to
fill Params with some values. Override it to make changes in Params fields before further
processing. For example, You may want to call CreateSubclass before
returning (this will rewrite some fields of Params with values, sensible for appropriate
Windows control, eg. 'STATIC', 'BUTTON', etc.) See for more detailes lesson 'how to create MFC-based controls' in XMfcControl definition. |
- subclasses window with certain standard Windows control data ('STATIC', 'BUTTON', etc.). Must be used in overriden CreateParams method. |
- makes window visible and brings it to front of view (making it active). |
- makes window invisible. |
- transforms coordinates of a point given respectively to topleft corner of client area of window to coordinates at screen. |
- handles Windows messages (WM_CLOSE, WM_NCDESTROY, WM_SIZE, WM_SHOWWINDOW,
WM_SYSCOMMAND.SC_MINIMIZE, WM_SETFOCUS, WM_SETCURSOR are handled only. To handle other
messages, override this function and supply code to implement its). This method made public to simplify calling of it from XApplets.pas unit. Usually You do not need call it directly, excluding calling of inherited one in descending class. |
- overrides method inherited from XVisual and returns Handle. This method used internally to handle messages and usually You do not need to call XVisuals.GetWindowHandle( ... ) to obtain window handle. |
- overrides correspondent method of XVisual, returning True. |
Methods, inherited from XVisual:
Methods inherited from XClass:
Events of XWindow object:
XEventAccept = procedure( Sender :
TObject; var Accept : Boolean ); - use this event to decide if window can be closed in response to Windows message WM_CLOSE. If not, set Accept to False before return. |
Other definitions of XWindows.pas unit:
Also interface class XWindowsManager is declared here and single variable GlobalWindowsManager of this type. This is derived from TObject and has no methods and properties, but has events:
- These events are not calling by GlobalWindowsManager itself (this object exists
only in a single copy and applet has no other objects of XWindowsManager class, similar
that Applet is a single copy of XApplet class). These
events are only stored here. Events OnCreateWindow and OnDestroyWindow of GlobalWindowsManager are called in XWindow class only if its are assigned. And its are assigned only if XCanvases unit is used and in that case its are redirected to GlobalCanvasManager which adds creating and destroying of Canvas for XWindow when it is creating and destroying. Similar above, events OnBeginPaint and OnEndPaint are used to make add-on to XForm (derived from XWindow), which allow to prepare Canvas of XWindow object to paint using given device context. This object is intended here to provide optional extending of XForm with canvases, which are not mandatory in XCL. Canvases are provided only if XCanvases.pas unit is used in your applet (for example, if You use self-painting controls, derived from XCustomControl). |
Tasks.
Usually You have not to descend objects directly from XWindow. To
create new control, use XControl as a base. And to create new
type of form use XForm as an ancestor. Type XWindow can be
useful if You are not going to use XForm capabilities of
containing controls and managing of active ones.
In XCL, XWindow is used to derive both XForm
and XApplet classes. So, XWindow includes some code to
support capabilities to handle Windows messages: