Click here to Skip to main content
15,895,084 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 91K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
/*----------------------------------------------------------------------
Copyright (c) 2000 Russ Freeman. All Rights Reserved.
Email: russf@gipsysoft.com
Web site: http://www.gipsysoft.com

This code may be used in compiled form in any way you desire. This
file may be redistributed unmodified 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. If 
the source code in this file is used in any commercial application 
then a simple email would be nice.

This file is provided 'as is' with no expressed or implied warranty.
The author accepts no liability if it causes any damage to your
computer.

Expect bugs.

Please use and enjoy. Please let me know of any bugs/mods/improvements 
that you have found/implemented and I will fix/incorporate them into this
file.

File:	CenterWindow.cpp
Owner:	russf@gipsysoft.com
Purpose:	Centers a window within another.
----------------------------------------------------------------------*/
#include "stdafx.h"

extern bool CentreWindow( HWND hwndParent, HWND hwndChild );

bool CentreWindow( HWND hwndParent, HWND hwndChild )
{
	//ASSERT_VALID_HWND( hwndParent );
	//ASSERT_VALID_HWND( hwndChild );
	RECT rcParent, rcChild;

	bool bRetVal = false;
	if( GetWindowRect( hwndParent, &rcParent ) && GetWindowRect( hwndChild, &rcChild ) )
	{
		int x = rcParent.left + ( ( rcParent.right - rcParent.left )  -  ( rcChild.right - rcChild.left ) ) / 2;
		int y = rcParent.top + ( ( rcParent.bottom - rcParent.top ) -  ( rcChild.bottom - rcChild.top ) ) / 2;
		if( SetWindowPos( hwndChild, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ))
		{
			bRetVal = true;
		}
	}
	return bRetVal;
}

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
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions