Types of Windows |
|
|
|
A Window's Childhood |
After creating the main window, you can use it as a parent for other windows. To specify that a window is a child of another window, when creating it with either the CreateWindow() or the CreateWindowEx() function, pass the handle of the parent as the hWndParent argument. Here is an example: // Create a window CreateWindowEx(0, WndClassName, CaptionOrText, ChildStyle, Left, Top, Width, Height, hWndParent, NULL, hInstance, NULL); If a window is a child of another window, to get a handle to its parent, you can call the GetParent() function. Its syntax is: HWND GetParent(HWND hWnd); The hWnd argument is a handle to the child window whose parent you want to find out. Alternatively, you can also use the GetWindowLong() function, passing the second argument as GWL_HWNDPARENT, to get a handle to the parent of a window.
|
The Borders of a Window |
To distinguish a particular window from the other objects on a screen, a window can be defined by surrounding borders on the left, the top, the right, and the bottom. One of the effects the user may want to control on a window is its size. For example, the user may want to narrow, enlarge, shrink, or heighten a window. To do this, a user would position the mouse on one of the borders, click and drag in the desired direction. This action is referred to as resizing a window. For the user to be able to change the size of a window, the window must have a special type of border referred to as a thick frame. To provide this border, apply or add the WS_THICKFRAME style: CreateWindow(ClsName, WndName, WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME); Because many windows will need this functionality, a special style can combine them and it is called WS_OVERLAPPEDWINDOW. Therefore, you can create a resizable window as follows: CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW,
|
Window's Location and Size |
The location of a window is defined by the distance from the left border of the monitor to the window's left border and its distance from the top border of the monitor to its own top border. The size of a window is its width and its height. These can be illustrated for a main window frame as follows: For a Win32 application, the original distance from the left border of the monitor is passed as the x argument to the CreateWindow() or the CreateWindowEx() function. The distance from top is specified using the y argument. The x and y arguments define the location of the window. The distance from the left border of the monitor to the right border of the window is specified as the nWidth argument. The distance from the top border of the monitor to the lower border of the window is specified with the nHeight value. If you cannot make up your mind for these four values, you can use the CW_USEDEFAULT (when-Creating-the-Window-USE-the-DEFAULT-value) constant for either one or all four arguments. In such a case, the compiler would select a value for the argument. Here is an example: INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WndClsEx; . . . RegisterClassEx(&WndClsEx); HWND hWnd = CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, return 0; }
|
Displaying the Window |
Once a window has been created and if this was done successfully, you can display it to the user. This is done by calling the ShowWindow() function. Its syntax is: BOOL ShowWindow(HWND hWnd, int nCmdShow); The hWnd argument is a handle to the window that you want to display. It could be the window returned by the CreateWindow() or the CreateWindowEx() function. The nCmdShow specifies how the window must be displayed. Its possible values are:
To show its presence on the screen, the window must be painted. This can be done by calling the UpdateWindow() function. Its syntax is: BOOL UpdateWindow(HWND hWnd); This function simply wants to know what window needs to be painted. This window is specified by its handle. Here is an example: INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WndClsEx; . . . RegisterClassEx(&WndClsEx); HWND hWnd = CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if( !hWnd ) // If the window was not created, return 0; // stop the application ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); return 0; }
|
The Multiple Document Interface (MDI) |
Introduction |
A multiple document is the type of application that uses a main, external window that acts as a frame and hosts other, floating window that act as its children. This concept allows the user to open more than one document at a time in an application, making it possible to switch from one document to another without closing the application. |
MDI Application Creation |
You start an MDI like the types of applications we have created so far. One of the primary differences is that the window procedure must return the DefFrameProc() function. Its syntax is: LRESULT DefFrameProc(HWND hWnd, HWND hWndMDIClient, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
||
Previous | Copyright © 2003-2015, FunctionX, Inc. | Next |
|