1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3
4<head>
5<title>Windows Interface Reference: Window structure</title>
6</head>
7
8<body>
9
10<h1>Window </h1>
11
12<p>The Window structure contains functions and structures to create and operate on
13windows. Many other operations are available by sending messages to windows.</p>
14
15<pre>structure Window :
16sig
17    type HWND and HINSTANCE and HMENU
18    type POINT = { x: int, y: int }
19    type RECT =  { left: int, top: int, right: int, bottom: int }
20
21    structure Style:
22    sig
23        include BIT_FLAGS
24        val WS_OVERLAPPED: flags and WS_POPUP: flags and WS_CHILD: flags and WS_MINIMIZE: flags
25        and WS_VISIBLE: flags and WS_DISABLED:flags and WS_CLIPSIBLINGS:flags
26        and WS_CLIPCHILDREN:flags and WS_MAXIMIZE:flags and WS_CAPTION:flags
27        and WS_BORDER:flags and WS_DLGFRAME:flags and WS_VSCROLL:flags and WS_HSCROLL:flags
28        and WS_SYSMENU:flags and WS_THICKFRAME:flags and WS_GROUP:flags and WS_TABSTOP:flags
29        and WS_MINIMIZEBOX:flags and WS_MAXIMIZEBOX:flags and WS_TILED:flags and WS_ICONIC:flags
30        and WS_SIZEBOX:flags and WS_OVERLAPPEDWINDOW:flags and WS_TILEDWINDOW:flags
31        and WS_POPUPWINDOW:flags and WS_CHILDWINDOW:flags
32    end
33
34    datatype WindowPositionStyle =
35            SWP_ASYNCWINDOWPOS
36        |    SWP_DEFERERASE
37        |    SWP_FRAMECHANGED
38        |    SWP_HIDEWINDOW
39        |    SWP_NOACTIVATE
40        |    SWP_NOCOPYBITS
41        |    SWP_NOMOVE
42        |    SWP_NOOWNERZORDER
43        |    SWP_NOREDRAW
44        |    SWP_NOSENDCHANGING
45        |    SWP_NOSIZE
46        |    SWP_NOZORDER
47        |    SWP_SHOWWINDOW
48        |    SWP_OTHER of int
49
50    datatype ShowWindowOptions =
51        SW_HIDE
52    |    SW_MAXIMIZE
53    |    SW_MINIMIZE
54    |    SW_RESTORE
55    |    SW_SHOW
56    |    SW_SHOWDEFAULT
57    |    SW_SHOWMAXIMIZED
58    |    SW_SHOWMINIMIZED
59    |    SW_SHOWMINNOACTIVE
60    |    SW_SHOWNA
61    |    SW_SHOWNOACTIVATE
62    |    SW_SHOWNORMAL
63
64    val SW_NORMAL: ShowWindowOptions
65    val SW_MAX: ShowWindowOptions
66
67    val ShowWindow: HWND * ShowWindowOptions -&gt; bool
68
69    datatype GetWindowFlags =
70        GW_CHILD
71    |    GW_HWNDFIRST
72    |    GW_HWNDLAST
73    |    GW_HWNDNEXT
74    |    GW_HWNDPREV
75    |    GW_OWNER
76
77    datatype <a
78href="#ParentType">ParentType</a> =
79          ChildWindow of {id: int, parent: HWND}
80        | PopupWindow of HMENU
81        | PopupWithClassMenu
82
83    val GWL_EXSTYLE : int
84    val GWL_HINSTANCE : int
85    val GWL_HWNDPARENT : int
86    val GWL_ID : int
87    val GWL_STYLE : int
88    val GWL_USERDATA : int
89
90    val AdjustWindowRect : RECT * Style.flags * bool -&gt; RECT
91    val AdjustWindowRectEx :  RECT * Style.flags * bool * int -&gt; RECT
92    val ArrangeIconicWindows : HWND -&gt; int
93    val BringWindowToTop : HWND -&gt; unit
94    val CW_USEDEFAULT : int
95    val ChildWindowFromPoint : HWND * POINT -&gt; HWND option
96    val CloseWindow : HWND -&gt; unit
97    <a
98name="CreateWindow">val CreateWindow</a> :
99       {x: int, y: int, init: 'a, name: string, class: 'a Class.ATOM,
100         style: Style.flags, width: int, height: int,
101         instance: HINSTANCE, relation: ParentType} -&gt; HWND
102    <a
103name="DestroyWindow">val DestroyWindow</a>: HWND -&gt; unit
104    val FindWindow: string * string option -&gt; HWND
105    val FindWindowEx: HWND option * HWND option * string * string option -&gt; HWND
106    val GetClassName : HWND -&gt; string
107    val GetClientRect : HWND -&gt; RECT
108    val GetDesktopWindow : unit -&gt; HWND
109    val GetForegroundWindow : unit -&gt; HWND
110    val GetLastActivePopup : HWND -&gt; HWND
111    val GetNextWindow : HWND * GetWindowFlags -&gt; HWND
112    val GetParent : HWND -&gt; HWND option
113    val GetTopWindow : HWND option-&gt; HWND option
114    val GetWindow : HWND * GetWindowFlags -&gt; HWND option
115    val GetWindowContextHelpId : HWND -&gt; int
116    val GetWindowLong : HWND * int -&gt; int
117    val GetWindowRect : HWND -&gt; RECT
118    val <a
119name="GetWindowText">GetWindowText</a> : HWND -&gt; string
120    val GetWindowTextLength : HWND -&gt; int
121    val IsChild : HWND * HWND -&gt; bool
122    val IsIconic : HWND -&gt; bool
123    val IsWindow : HWND -&gt; bool
124    val IsWindowVisible : HWND -&gt; bool
125    val IsZoomed : HWND -&gt; bool
126    <a
127name="MoveWindow">val MoveWindow</a> : {x: int, y: int, hWnd: HWND, width: int, height: int, repaint: bool} -&gt; unit
128    val OpenIcon : HWND -&gt; unit
129    val SetForegroundWindow : HWND -&gt; bool
130    val <a
131name="SetParent">SetParent</a> : HWND * HWND option -&gt; HWND
132    val SetWindowContextHelpId : HWND * int -&gt; unit
133    val SetWindowLong : HWND * int * int -&gt; int
134    val SetWindowPos : HWND * HWND * int * int * int * int * WindowPositionStyle list -&gt; unit
135    val SetWindowText : HWND * string -&gt; unit
136    val SubclassWindow :
137       HWND *
138       (HWND * Message.Message * 'a -&gt; Message.LRESULT option * 'a) * 'a -&gt; unit
139    val WindowFromPoint : POINT -&gt; HWND option
140end</pre>
141
142<p><tt>datatype <a name="ParentType">ParentType</a> = ChildWindow of {id: int, parent:
143HWND} | PopupWindow of HMENU &nbsp; |&nbsp; PopupWithClassMenu</tt><br>
144The ParentType datatype is used as one of the arguments to CreateWindow.&nbsp;
145PopupWithClassMenu and PopupWindow both create top-level windows.&nbsp; PopupWindow
146provides a menu to be used whereas PopupWithClassMenu uses the menu, if any, given when
147the class was created.&nbsp; ChildWindow creates a child of the given parent window and
148provides an id for the child.&nbsp; All children must have different identifiers. &nbsp;
149The identifier is used in <a href="Message.html#WM_NOTIFY">WM_NOTIFY</a> messages to
150notify the parent about changes in the child and can be used to find a child window from
151the parent using <a href="Dialog.html#GetDlgItem">GetDlgItem</a>. </p>
152
153<p>&nbsp;</p>
154
155<h4>Subclassing</h4>
156
157<p>It is possible to replace a window procedure for a window by <em>subclassing</em> the
158window.&nbsp; This is useful where a window is required which is almost the same as, say
159an Edit window, but it needs to process a few messages in a special way.&nbsp; A new
160window procedure is installed which process the particular messages but calls the original
161window procedure for any of the others.</p>
162
163<p>(The terminology is, in my opinion confusing: subclassing a window does not create a
164new class of window but changes only a single window).&nbsp; In C this is done using the
165SetWindowLong function: in ML there is a SubclassWindow function which does this and
166automatically calls the window procedure of the base class for any messages which are not
167otherwise processed.</p>
168</body>
169</html>
170