Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / MFC

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

Rate me:
Please Sign up or sign in to vote.
4.98/5 (71 votes)
10 Jan 2005CPOL25 min read 533K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
//****************************************************************************
// 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)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!

Comments and Discussions