//****************************************************************************
// File: mainwnd.c
//
// Purpose: Main overlapped window's message handler
//
// Functions:
// MainWndProc() - message handler for main overlapped window
// DoCommands() - called by MainWndProc to handle all WM_COMMAND messages
//
// Development Team: HHR
//
//
// Written by Microsoft Product Support Services, Windows Developer Support
// Copyright (c) 1992 Microsoft Corporation. All rights reserved.
//****************************************************************************
#pragma warning (disable:4115)
#pragma warning (disable:4201)
#pragma warning (disable:4214)
#pragma warning (disable:4514)
#include <windows.h>
#define NGLIB_BUILD_DLL // Force classes to be EXPORTED
#include "NGLibrary_DllDefs.h" // DLL export/import definitions
// Global variables used by the scalable dialog.
static float xMult, yMult;
// Local function prototypes.
static void HandleCBCtrls(HWND hWnd, LPRECT lprc);
static void StoreWindowRect(HWND hWnd,LPRECT lprc);
static void RetrieveWindowRect(HWND hWnd, LPRECT lprc);
static void DeleteWindowRect(HWND hWnd);
static void CalcMultiplier(HWND hWnd);
static void CalcNewSize(LPRECT lprc);
//****************************************************************************
// Function: HandleCBCtrls
//
// Purpose: Called by ScalableDlg() to handle Combo boxes special case
// situation with the drop down list size.
//
// Parameters:
// hWnd == Handle to the control child window.
// lprc == Pointer to the controls dimentions obtained through
// GetWindowRect()
//
// Returns : None.
//
// Comments: CBS_DROPDOWN and CBS_DROPDOWNLIST dimensions return by
// GetWindowRect() does not include the drop down list. What
// this function does is adds the height of the list box to
// the RECT.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void HandleCBCtrls(HWND hWnd, LPRECT lprc)
{
char ClassName[20];
RECT rcl;
LONG CBStyles;
// Get the class name
GetClassName(hWnd,(LPSTR)ClassName,20);
// Check to see if it is a combo box then check to see if it is either
// CBS_DROPDOWN or CBS_DROPDOWNLIST, if so then get the list boxes
// dimentions and add in its height.
if (!lstrcmpi(ClassName,"COMBOBOX")){
CBStyles = GetWindowLong(hWnd,GWL_STYLE);
if ((CBStyles & CBS_DROPDOWN) || (CBStyles & CBS_DROPDOWNLIST)){
SendMessage(hWnd,CB_GETDROPPEDCONTROLRECT,0,(DWORD)((LPRECT)&rcl));
lprc->bottom = rcl.bottom; // Take the the height of the CB
// including its drop down list box
}
}
return;
}
//****************************************************************************
// Function: StoreWindowRect
//
// Purpose: Called by ScalableDlg() to calculate and store the initial
// rect values in the windows property.
//
// Parameters:
// hWnd == Handle to the dialog or its child controls
// lprc == The rect dimentions to be stored.
//
// Returns : None.
//
// Comments: This functions should be called only once at the very begining
// to store the initial values.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void StoreWindowRect(HWND hWnd,LPRECT lprc)
{
SetProp(hWnd,"top",(HANDLE)lprc->top);
SetProp(hWnd,"bottom",(HANDLE)lprc->bottom);
SetProp(hWnd,"left",(HANDLE)lprc->left);
SetProp(hWnd,"right",(HANDLE)lprc->right);
return;
}
//****************************************************************************
// Function: RetrieveWindowRect
//
// Purpose: Called by ScalableDlg() to handle retrieve the initial dimentions
// for either the dialog or its child controls.
//
// Parameters:
// hWnd == Handle to either dialog or its child controls
// lprc == Pointer to the RECT structure used to return the saved
// values
//
// Returns : None.
//
// Comments: This function must be called after StoreWindowRect is called to
// store the values.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void RetrieveWindowRect(HWND hWnd, LPRECT lprc)
{
lprc->top = (int) GetProp(hWnd,"top");
lprc->bottom = (int) GetProp(hWnd,"bottom");
lprc->left = (int) GetProp(hWnd,"left");
lprc->right = (int) GetProp(hWnd,"right");
return;
}
//****************************************************************************
// Function: DeleteWindowRect
//
// Purpose: Called by ScalableDlg() to delete the stored properties for the
// given window.
//
// Parameters:
// hWnd == Handle to either the dialog or its child controls.
//
// Returns : None.
//
// Comments: This must be called before the dialog is closed and only if
// StoreWindowRect was called to install them.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void DeleteWindowRect(HWND hWnd)
{
RemoveProp(hWnd,"top");
RemoveProp(hWnd,"bottom");
RemoveProp(hWnd,"left");
RemoveProp(hWnd,"right");
return;
}
//****************************************************************************
// Function: CalcMultiplier
//
// Purpose: Called by ScalableDlg() to Calculate the expansion or reduction
// ratio based on the dialog size for use to adjust the child conrol
// sizes
//
// Parameters:
// hWnd == Handle to the dialog
//
// Returns : None.
//
// Comments: xMult and yMult two global variables are set to be used by
// CalcNewSize() to calculate the child controls new sizes.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void CalcMultiplier(HWND hWnd)
{
RECT rc,rcInit;
GetClientRect(hWnd,&rc); // Get the new Rect of Dialog
RetrieveWindowRect(hWnd,&rcInit); // Get the Original Rect of Dialog
// Calculate the multiplier to calculate the new size of controls.
xMult = // Width's change ratio
(float)(rc.right - rc.left) / // New Width of the dialog
(rcInit.right - rcInit.left); // Original Width of the dialog
yMult = // Height's change ratio
(float)(rc.bottom - rc.top) / // New Height of the dialog
(rcInit.bottom - rcInit.top); // Original Height of the dialog
return;
}
//****************************************************************************
// Function: CalcNewSize
//
// Purpose: Called by ScalableDlg() to calculate the child controls new
// size.
//
// Parameters:
// lprc == Child control's initial size
//
// Returns : None.
//
// Comments: The new dimentions are returned via lprc.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
static void CalcNewSize(LPRECT lprc)
{
lprc->top = (int)((yMult * lprc->top) + 0.5);
lprc->bottom = (int)((yMult * lprc->bottom) + 0.5);
lprc->left = (int)((xMult * lprc->left) + 0.5);
lprc->right = (int)((xMult * lprc->right) + 0.5);
return;
}
//****************************************************************************
// Function: ScalableDlg
//
// Purpose: Called by DoCommands() when want Scalable dialog box.
//
// Parameters:
// hDlg == Handle to _this_ window.
// message == Message to process.
// wParam == WORD parameter -- depends on message
// lParam == LONG parameter -- depends on message
//
// Returns: Depends on message.
//
// Comments: The Scalable dialog has proportionally sized controls.
//
// History: Date Author Reason
// 6/10/93 HHR Created
//****************************************************************************
#pragma warning (disable:4100)
BOOL FAR PASCAL ScalableDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hCtl;
RECT rc;
switch (message){
case WM_INITDIALOG:{
// Get the font used by the dialog. Will be NULL if system font is
// used.
HFONT hDlgFont = (HFONT)SendMessage(hDlg, WM_GETFONT,0,0L);;
// if the handle is NULL get the handle to the system font.
if (!hDlgFont)
hDlgFont = GetStockObject(SYSTEM_FONT);
//Save Font Handle as Window Property
SetProp(hDlg, "hDlgFont", (HANDLE)hDlgFont);
// Get the original size of the dialog and Store it.
GetClientRect(hDlg,&rc);
StoreWindowRect(hDlg,&rc);
// Cycle through all dialog controls and store their original sizes.
hCtl = GetWindow(hDlg,GW_CHILD);
while (hCtl){
GetWindowRect(hCtl,&rc); // Get the Window dimentions
HandleCBCtrls(hCtl,&rc); // special case handling for
// CBS_DROPDOWN/LIST
ScreenToClient(hDlg,(LPPOINT)&rc.left);
ScreenToClient(hDlg,(LPPOINT)&rc.right);
StoreWindowRect(hCtl,&rc);
hCtl = GetWindow(hCtl,GW_HWNDNEXT);
}
}
break;
case WM_DESTROY:
// Cycle through all dialog controls and store their original sizes.
hCtl = GetWindow(hDlg,GW_CHILD);
while (hCtl){
DeleteWindowRect(hCtl);
hCtl = GetWindow(hCtl,GW_HWNDNEXT);
}
DeleteWindowRect(hDlg);
//Remove Font properties
{
HFONT hNewFont = (HFONT)RemoveProp(hDlg, "hNewFont");
if (hNewFont)
DeleteObject(hNewFont);
RemoveProp(hDlg, "hDlgFont");
}
break;
case WM_GETMINMAXINFO:{
MINMAXINFO FAR* lpmmi;
RECT rc;
// Set the minimum size of the dialog so the controls do not run
// into one another.
lpmmi = (MINMAXINFO FAR*) lParam;
RetrieveWindowRect(hDlg,&rc);
// Set the minimum size at 90% of the original size.
lpmmi->ptMinTrackSize.x =
(int)(((rc.right - rc.left) * 0.25) + 0.5); // Min width of Dialog
lpmmi->ptMinTrackSize.y =
(int)(((rc.bottom - rc.top) * 0.25) + 0.5); // Min Height of Dialog
}
break;
case WM_SIZE:{
HFONT hDlgFont = (HFONT)GetProp(hDlg, "hDlgFont");
if (hDlgFont && GetWindowLong(hDlg, GWL_STYLE)&WS_THICKFRAME){
HFONT hNewFont = (HFONT)RemoveProp(hDlg, "hNewFont");
LOGFONT lf;
// Calculate the new size ratio.
CalcMultiplier(hDlg);
// Get the LOGFONT structure for the original font
GetObject(hDlgFont, sizeof(LOGFONT), (LPSTR) &lf);
// Scale up or down the font
if (yMult < 1.0 ) lf.lfHeight = (int)((yMult * lf.lfHeight) + 0.5);
if (xMult < 1.0 ) lf.lfWidth = (int)((xMult * lf.lfWidth) + 0.5);
// Delete old font and Create ans Save the new font
if (hNewFont)
DeleteObject(hNewFont);
hNewFont = CreateFontIndirect(&lf);
SetProp(hDlg, "hNewFont", (HANDLE)hNewFont);
// Set the font for the dialog
SendMessage(hDlg,WM_SETFONT,(WPARAM) hNewFont,0L);
// Start with the first control and cycle through all controls
hCtl = GetWindow(hDlg,GW_CHILD);
while (hCtl) {
// Set the font for the Control
SendMessage(hCtl,WM_SETFONT,(WPARAM) hNewFont,0L);
// Retrieve the original size of the control and calculate its new
// size then resize the control.
RetrieveWindowRect(hCtl,&rc);
CalcNewSize(&rc);
MoveWindow(hCtl,rc.left,rc.top,
(rc.right-rc.left),(rc.bottom-rc.top),FALSE);
InvalidateRect(hCtl,NULL,TRUE);
// Get the next control.
hCtl = GetWindow(hCtl,GW_HWNDNEXT);
}
// Make the dialog to repaint entirely.
InvalidateRect(hDlg,NULL,TRUE);
}
}
break;
}//switch
return (FALSE); // Didn't process a message
}
#pragma warning (default:4100)