[ Next ] [ Previous ] | Chapter 10 |
BOOL WinShowWindow(HWND hwnd, BOOL fShow);
The first parameter is the window to be made visible or invisible. A
value of TRUE for the next parameter indicates the window is to be made
visible. FALSE indicates the window is to be made invisible.
A window that is enabled is one that can respond so user input. An
application can disable a window by using WinEnableWindow.
Items on a dialog box can be disabled from being chosen if the choices
are no longer applicable.
BOOL WinEnableWindow(HWND hwnd, BOOL fEnable);
The first parameter is the window to be enabled or disabled. A value of TRUE for the next parameter indicates the window is to be enabled. FALSE indicates the window is to be disabled.
WINSIZE.C |
Winsize.exe window |
LONG WinQuerySysValue(HWND hwndDesktop, LONG iSysValue);HwndDesktop is the desktop window handle, and iSysValue is a constant used to query a specific value. The constants available are too numerous to list here, but are listed in the documentation for WinQuerySysValue.
lWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);This function will provide lots of information about the dimensions of various system components. The values we are interested in are the height and width of the screen, SV_CXSCREEN and SV_CYSCREEN. The value returned from the function is the answer to your query.
lHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
The frame window must be subclassed in order to alter the default frame window behavior. For more information on subclassing, see Chapter 27. In this program, the old (in this case, the default) frame window procedure is saved, along with the minimum height and width, in the frame window word. Window words were covered in Chapter 9. Remember, some of the system control windows, such as the frame windows, have reserved space for a user-defined window word.
hab = WinQueryAnchorBlock(hwndFrame);In case the window pointer is not found, the frame resorts back to its old window procedure. The path to the old window procedure is found by using two very useful functions, WinQueryAnchorBlock and WinQueryClassInfo.
WinQueryClassInfo(hab,
WC_FRAME,
&classInfo);
pfnNormalFrameProc = classInfo.pfnWindowProc;
return ((*pfnNormalFrameProc)(hwndFrame,
ulMsg,
mpParm1,
mpParm2));
HAB WinQueryAnchorBlock(HWND hwnd);WinQueryAnchorBlock has only one parameter, the window handle of the window for with to retrieve the anchor block handle. The function returns the handle to the anchor block.
BOOL APIENTRY WinQueryClassInfo(HAB hab,This function has three parameters. hab is the anchor block handle, pszClassName is the name of the class for which to retrieve the information, and pClassInfo is a pointer to CLASSINFO structure.
PSZ pszClassName,
PCLASSINFO pClassInfo);
typedef struct _CLASSINFO /* clsi */The structure contains the class style flags, flClassStyle. A pointer to the window procedure, pfnWindowProc, and also the number of additional window words, cbWindowData.
{ ULONG flClassStyle;
PFNWP pfnWindowProc;
ULONG cbWindowData;
} CLASSINFO;
typedef CLASSINFO *PCLASSINFO;
WinQueryAnchorBlock is used to retrieve the anchor block for our message queue. Once we have the anchor block handle, WinQueryClassInfo is called to retrieve the default window procedure for the frame class. Then, this window procedure is executed rather than the subclassed frame window procedure.
typedef struct _TRACKINFO /* ti */The default frame window procedure is called in order to get TRACKINFO structure that is already filled in.
{LONG cxBorder;
LONG cyBorder;
LONG cxGrid;
LONG cyGrid;
LONG cxKeyboard;
LONG cyKeyboard;
RECTL rclTrack;
RECTL rclBoundary;
POINTL ptlMinTrackSize;
POINTL ptlMaxTrackSize;
ULONG fs;
} TRACKINFO;
typedef TRACKINFO *PTRACKINFO;
pTrackInfo->ptlMinTrackSize.x = pFrameInfo->lWidth/2;Once we have this structure, we modify the ptlMinTrackSize.x and ptlMinTrackSize.y values. We use one-half the screen width and one-half the screen height as the new minimum tracking sizes. The last step is to return mrReply which will be TRUE in all cases, except for errors.
pTrackInfo->ptlMinTrackSize.y = pFrameInfo->lHeight/2;
WINSAVE.C |
Winsave.exe restotes window position. |
bReturn = WinRestoreWindowPos ( SAVE_NAME,WinRestoreWindowPos is called right after the frame window is created. This enables the saved changes to be visible right when the window is created.
SAVE_KEY,
hwndFrame );
BOOL APIENTRY WinRestoreWindowPos(PSZ pazAppName,The first parameter is the application name, placed in the .INI tile. The second is the keyword used in conjunction with the application name. The last parameter is the window to apply the changes to.
PSZ pszKeyName,
HWND hwnd);
BOOL APIENTRY WinSetWindowPos(HWND hwnd,WinSetWindowPos is a very handy function. It is used to position, size, activate, deactivate, maximize, minimize, hide, or restore a window. One of the nice aspects of WinSetWindowPos is its ability to consolidate several function calls into one.
HWND hwndInsertBehind,
LONG x,
LONG y,
LONG cx,
LONG cy,
ULONG fl);
WinSetWindowPos ( hwndFrame,hwndFrame is the window to adjust. The next parameter HWND_TOP indicates the position in the Z-order for the window. We've mentioned Z-order before; it's time for a little more detail.
HWND_TOP,
0,
0,
0,
0,
SWP_ACTIVATE | SWP_SHOW ) ;
typedef struct _SWP /* swp */After calling WinRestoreWindowPos, either WinShowWindow or WinSetWindowPos with the SWP_SHOW flag should be called.
{
ULONG fl;
LONG cy;
LONG cx;
LONG y;
LONG x;
HWND hwndInsertBehind;
HWND hwnd;
ULONG ulReserved1;
ULONG ulReserved2;
} SWP;
typedef SWP *PSWP;
case WM_SAVEAPPLICATION:Presentation Manager sends a special message at application shutdown time for the sole purpose of giving the programmer a chance to save the options and settings the user has customized to reflect his or her preferences. This is the WM_SAVEAPPLICATION message. Catchy name. This is the time to call WinStoreWindowPos.
WinStoreWindowPos ( SAVE_NAME,
SAVE_KEY,
WinQueryWindow ( hwndWnd, QW_PARENT )) ;
break ;
BOOL APIENTRY WinStoreWindowPos(PCSZ pszAppName,The parameters for this function are exactly the same as WinRestoreWindowPos.
PCSZ pszKeyName,
HWND hwnd);
Gotcha!
One little note here: The settings for the frame window, not the client, are the ones to be retrieved. |
Gotcha! FCF_SIZEBORDER flag has one size effect: you can't make window width less than about 136 pixels. Атас! Флаг FCF_SIZEBORDER не позволяет сделать ширину окна меньше, чем примерно 136 пикселей. |
[ Next ] [ Previous ] | Chapter 10 |