www.pudn.com > DialogResizeable.zip > WinRect.cpp, change:2001-10-08,size:2857b


// 
// WinRect 
// 
// Written by Laurent Kempé (lkempe@netcourrier.com) for Tech Head WebSite 
// Copyright (c) 2001 Laurent Kempé. 
// 
// This code may be used in compiled form in any way you desire. This 
// file may be redistributed by any means PROVIDING it is  
// not sold for profit without the authors written consent, and  
// providing that this notice and the authors name is included.  
// 
// This file is provided "as is" with no expressed or implied warranty. 
// The author accepts no liability if it causes any damage to you or your 
// computer whatsoever. It's free, so don't hassle me about it. 
// 
// Origin: July 2001 issue of MSDN Magazine 
//         Paul DiLascia  
//         Windows UI: Our WinMgr Sample Makes Custom Window Sizing Simple 
// 
//////////////////////////////////////////////////////////////// 
// MSDN Magazine -- July 2001 
// If this code works, it was written by Paul DiLascia. 
// If not, I don't know who wrote it. 
// Compiles with Visual C++ 6.0. Runs on Win 98 and probably Win 2000 too. 
// Set tabsize = 3 in your editor. 
// 
#include "StdAfx.h" 
#include "WinMgr.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
////////////////// 
// Construct from args 
// 
WINRECT::WINRECT(WORD f, UINT id, LONG p) 
{ 
	memset(this, 0, sizeof(WINRECT)); 
	flags = f; 
	nID = id; 
	param = p; 
} 
 
////////////////// 
// Get the parent of a given WINRECT. To find the parent, chase the prev 
// pointer to the start of the list, then take the item before that in 
// memory.  
// 
WINRECT* WINRECT::Parent() 
{ 
	for (WINRECT* pEntry=this; pEntry->Prev(); pEntry=pEntry->Prev()) { 
		; // go backwards to the end 
	} 
	// the entry before the first child is the group 
	WINRECT *parent = pEntry-1; 
	ATLASSERT(parent->IsGroup()); 
	return parent; 
} 
 
////////////////// 
// Get group margins 
// 
BOOL WINRECT::GetMargins(int& w, int& h) 
{ 
	if (IsGroup()) { 
		w=(short)LOWORD(param); 
		h=(short)HIWORD(param); 
		return TRUE; 
	} 
	w=h=0; 
	return FALSE; 
} 
 
////////////////// 
// Initialize map: set up all the next/prev pointers. This converts the 
// linear array to a more convenient linked list. Called from END_WINDOW_MAP. 
// 
WINRECT* WINRECT::InitMap(WINRECT* pWinMap, WINRECT* parent) 
{ 
	ATLASSERT(pWinMap); 
 
	WINRECT* pwrc = pWinMap;  // current table entry 
	WINRECT* prev = NULL;	  // previous entry starts out none 
 
	while (!pwrc->IsEndGroup()) { 
		pwrc->prev=prev; 
		pwrc->next=NULL; 
		if (prev) 
			prev->next = pwrc; 
		prev = pwrc; 
		if (pwrc->IsGroup()) { 
			pwrc = InitMap(pwrc+1,pwrc); // recurse! Returns end-of-grp 
			ATLASSERT(pwrc->IsEndGroup()); 
		} 
		pwrc++; 
	} 
	// safety checks 
	ATLASSERT(pwrc->IsEndGroup()); 
	ATLASSERT(prev); 
	ATLASSERT(prev->next==NULL); 
	return parent ? pwrc : NULL; 
}