Click here to Skip to main content
15,893,588 members
Articles / Web Development / HTML

A Comprehensive CE Class Library to Replace ATL and MFC

Rate me:
Please Sign up or sign in to vote.
4.48/5 (14 votes)
4 Oct 2000CPOL 281.7K   998   70  
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.
#ifndef __CeMgr_h__
#define __CeMgr_h__

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "CeMisc.h"
#include "CeArray.h"

enum eChildFlags
{
   //
   // o Anchoring to the left is easy - no action has to be taken.
   // o Anchoring to the right takes work - we preserve the distance of the right
   //   edge of the child to the right edge of the parent.

   // o Anchoring to the top is easy - no action has to be taken.
   // o Anchoring to the bottom takes work - we preserve the distance of the bottom
   //   edge of the child to the bottom edge of the parent.

   // o With "absolute" height/width adjustments, change is equal to parent.
   // o With "proportional" height/width adjustments, change is proportional
   //   to parent change.

   // Use these to maintain the distance from the edge of a control to the edge of
   // it's parent.
   //
   AL_ANCHOR_LEFT         =  0x00001,
   AL_ANCHOR_RIGHT        =  0x00002,
   AL_ANCHOR_TOP          =  0x00004,
   AL_ANCHOR_BOTTOM       =  0x00008,

   AL_ANCHOR_TOPLEFT      =  AL_ANCHOR_TOP|AL_ANCHOR_LEFT,
   AL_ANCHOR_TOPRIGHT     =  AL_ANCHOR_TOP|AL_ANCHOR_RIGHT,
   AL_ANCHOR_BOTLEFT      =  AL_ANCHOR_BOTTOM|AL_ANCHOR_LEFT,
   AL_ANCHOR_BOTRIGHT     =  AL_ANCHOR_BOTTOM|AL_ANCHOR_RIGHT,

   AL_ANCHOR_ALL		  =  AL_ANCHOR_TOP|AL_ANCHOR_LEFT|AL_ANCHOR_BOTTOM|AL_ANCHOR_RIGHT,

   //
   // Use these to adjust height or width by the same pixel count as the
   // parent's height/width change.
   //
   AL_ADJUST_WIDTH        =  0x00010,
   AL_ADJUST_HEIGHT       =  0x00020,
   AL_ADJUST_SIZE		  =  AL_ADJUST_WIDTH|AL_ADJUST_HEIGHT,

   //
   // Use these to adjust height or width such that original ratios
   // to original parent height/width are maintained.
   //
   AL_PROP_ADJUST_WIDTH   =  0x00040,
   AL_PROP_ADJUST_HEIGHT  =  0x00080,
   AL_PROP_ADJUST_SIZE	  =  AL_PROP_ADJUST_WIDTH|AL_PROP_ADJUST_HEIGHT,

   //
   // Use these to adjust vertical or horizontal position such that
   // position is maintained if you imagine parent's coordinate system
   // to be scaled (rather than extended).  (For instance, a control
   // in the center of the parent would remain in the center of the parent
   // after a resize if both of these flags are true.)
   //
   AL_PROP_ADJUST_HORZPOS = 0x00100,
   AL_PROP_ADJUST_VERTPOS = 0x00200,

   //
   // AL_ELASTIC is just shorthand - it causes a control to proportionately
   // move and size.
   //
   AL_ELASTIC             = AL_PROP_ADJUST_WIDTH|AL_PROP_ADJUST_HEIGHT|AL_PROP_ADJUST_HORZPOS|AL_PROP_ADJUST_VERTPOS,

   //
   // Use this to cause a static text label that precedes a control (in tab order)
   // to automatically track with the control itself.  Distance from the right edge
   // of the label to the left edge of the control is maintained.  (Vertical adjustment
   // also made.)
   //
   AL_FIX_LABEL           = 0x01000,

   //
   // the same as AL_FIX_LABEL but it assumes the label is above the control and doesn't
   // allocate horizontal spacing for it
   //
   AL_FIX_LABEL_ABOVE     = 0x02000,

   //
   // Keeps the spinner along the right border and keeps the vertical size equal
   // to the childs size
   //
   AL_FIX_SPINNER         = 0x04000,
};

class CeChildMgr
{

protected:
	class CeChildInfo
	{
	public:
	   CeChildInfo();

	   HWND m_hWndChild;
	   DWORD m_nFlags;				// AL_*** constants, generally OR'd together.
	   CeRect m_rcOriginal;			// Original rectangle for hWnd in parent's client coordinates
	   CeSize m_sizeMin;				// Smallest allowable size, default to size of NC area

	   CeRect m_rcMove;				// Where to move it after sizing

	   CeSize m_sizeAssocLabelDelta;	// Distance from right edge of associated label (hAssocWnd) to left edge of hWnd
									// (as well as top of label to top of hWnd).
									// Only used if AL_FIX_ASSOC_LABEL specified.
	   HWND m_hWndLabel;			// Handle to associated window, or label.  
	   CeRect m_rcLabel;				// Labels rectangle

	   CeSize m_sizeAssocSpinDelta;	// Distance from left edge of associated label (hAssocWnd) to right edge of hWnd
									// (as well as top of label to top of hWnd).
									// Only used if AL_FIX_SPINNER specified.
	   HWND m_hWndSpinner;			// Handle to spinner
	   CeRect m_rcSpinner;			// Spinners rectangle
	};

	CeArray<CeChildInfo> m_arrayInfo;
	HWND m_hWnd;					// parents handle

	CeRect m_rcOriginal;
	CeRect m_rcLastParent;			// Last size
   
public:
	CeChildMgr();
	virtual ~CeChildMgr();

	int Manage(HWND hChild, UINT nFlags);
	void OnSize(UINT nType, int cx, int cy);

	// Offset ALL child controls by size, this function
	// works for all children, not just the managed ones
	static void OffsetChildren(HWND hWnd, CeSize size);

	// Iterates thourhg the child windows on a dialog
	// or other window and excludes the children from the
	// clipping rectangle of the parent so when erasing the
	// background (eg, OnSize()) the background doesn't 
	// flash like hell
	static void ValidateChildBkgnd(HDC hDC, HWND hWnd);

	// Adjusts the parent rectangle, useful for things like
	// adding dialog bars to the parents client area
	// and then adjust the controls with fixed distances
	// to the parents borders
	void AdjustArea(const SIZE& sizeDelta, BOOL bTopLeft);

protected:
	SIZE CalcSize(CeChildInfo *pInfo, CeRect &rcParent);
	static void MsgBoxCurrentSize(HWND hWnd);

	// Call this when handling WM_GETMINMAXINFO, for example:
	// lpMMI->ptMinTrackSize = CAutoLayout::SizeDialogToScreen(250,210);
	static POINT SizeDialogToScreen(int nDialogX, int nDialogY);

	// This works...but there is not much that you can do with it.
	BOOL DetectCollision();
};

#endif // __CeMgr_h__

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions