Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

The Ultimate Toolbox - Updates and User Contributions

, 12 Feb 2013 CPOL
Updates and User Contributions for the Ultimate Toolbox Libraries
OutlookDemoUpdate.zip
Ultimate Grid
Demos
OutlookStyle
OutlookStyle.aps
OutlookStyle.dsp
OutlookStyle.dsw
OutlookStyle.suo
res
bitmap1.bmp
bmattach.bmp
bmp00001.bmp
bmp00002.bmp
bmp00003.bmp
Flags.bmp
OutlookStyle.ico
OutlookStyleDoc.ico
Toolbar.bmp
toolbar1.bmp
toolbar2.bmp
toolbarf.bmp
UltimateGrid72_Src_Update01.zip
CellTypes
Include
Source
UltimateGrid72_Src_Update02.zip
DataSources
ODBC
OleDB
EditControls
UltimateGrid72_Src_Update03.zip
UltimateGrid72_Src_Update04.zip
UltimateGrid73_src.zip
BuildDLL
Build DLL.dsp
Build DLL.dsw
res
BuildLib
ugmfclib.dsp
ugmfclib.dsw
Lib
Skel
UltimateTCP-IP42_Src_Update01.zip
Ultimate TCP-IP
Include
Security
Include
Source
source
UltimateTCP-IP42_Src_Update02.zip
Examples
Client
Mail
icon1.ico
icon2.ico
MailClientS.suo
test.dsp
test.dsw
UltimateTCP-IP42_Src_Update03.zip
ultimatetoolbox93_src_update01.zip
Ultimate Toolbox
include
source
UltimateToolbox93_Src_Update02.zip
lib
Build DLLs
Build Libs
UltimateToolbox93_Src_Update03.zip
UltimateToolbox93_Src_Update04.zip
UltimateToolbox93_Src_Update05.zip
// OXSeparator.cpp : implementation file
//
// Version: 9.3


#include "stdafx.h"
#include "OXSeparator.h"

#include "UTB64Bit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COXSeparator

COXSeparator::COXSeparator()
{
	// set default values
	VERIFY(SetTextColor());
	VERIFY(SetSeparatorColors());
	SetVertOriented(FALSE);
	m_sText.Empty();
}

COXSeparator::~COXSeparator()
{
}


BEGIN_MESSAGE_MAP(COXSeparator, CStatic)
	//{{AFX_MSG_MAP(COXSeparator)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_MESSAGE(WM_SETTEXT,OnSetText)
	ON_MESSAGE(WM_GETTEXT,OnGetText)
	ON_MESSAGE(WM_GETTEXTLENGTH,OnGetTextLength)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COXSeparator message handlers

void COXSeparator::PreSubclassWindow() 
{
	// TODO: Add your specialized code here and/or call the base class

	// make sure there wasn't any border styles specified, 
	// we don't support them
	ModifyStyle(WS_BORDER,0);
	ModifyStyleEx(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|
		WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME,0,SWP_FRAMECHANGED);
	/////////////////////////////////

	// save the window text
	GetWindowText(m_sText);
	
	CStatic::PreSubclassWindow();
}

int COXSeparator::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	// make sure there wasn't any border styles specified, 
	// we don't support them
	ASSERT((lpCreateStruct->style&WS_BORDER)==0);
	ASSERT((lpCreateStruct->dwExStyle&(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|
		WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME))==0);
	lpCreateStruct->style&=~WS_BORDER;
	lpCreateStruct->dwExStyle&=~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|
		WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
	/////////////////////////////////

	if(CStatic::OnCreate(lpCreateStruct)==-1)
		return -1;

	// save the window text
	m_sText=lpCreateStruct->lpszName;
	
	return 0;
}

void COXSeparator::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// draw text
	//

	// setup environment
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(m_clrText);

	CFont* pOldFont=NULL;
	CFont fontVert;
	CFont* pFont=GetFont();
	if(pFont)
	{
		if(m_bVertOriented)
		{
			// setup font for vertically oriented mode
			LOGFONT lf;
			VERIFY(pFont->GetLogFont(&lf));
			lf.lfEscapement=900;
			lf.lfOrientation=900;
			VERIFY(fontVert.CreateFontIndirect(&lf));
			pOldFont=dc.SelectObject(&fontVert);
		}
		else
			pOldFont=dc.SelectObject(pFont);
	}

	CRect rectClient;
	GetClientRect(&rectClient);
	CRect rectSeparator=rectClient;
	CRect rectText(0,0,0,0);

	// flag that specifies that separator is divided in two parts by 
	// centerd text
	BOOL bTwoParts=FALSE;
	if(!m_sText.IsEmpty())
	{
		rectText=rectClient;
		CRect rectHelper;
		if(m_bVertOriented)
		{
			// adjust rectangle to display verical texr
			rectHelper=rectText;
			rectText.top=rectHelper.left;
			rectText.bottom=rectHelper.right;
			rectText.left=rectHelper.top;
			rectText.right=rectHelper.bottom;
		}

		// calculate the rect to siplay text in
		UINT nFormat=DT_LEFT|DT_SINGLELINE;
		dc.DrawText(m_sText,&rectText,nFormat|DT_CALCRECT);
		rectHelper=rectText;
		if(m_bVertOriented)
		{
			rectText.top=rectHelper.left;
			rectText.bottom=rectHelper.right;
			rectText.left=rectHelper.top;
			rectText.right=rectHelper.bottom;
			rectHelper=rectText;
		}

		// adjust coordinates
		if(m_bVertOriented)
		{
			rectText.left+=(rectClient.Width()-rectHelper.Width())/2+
				(rectSeparator.Width()-rectHelper.Width())%2;
			rectText.right=rectText.left+rectHelper.Width();
		}
		else
		{
			rectText.top+=(rectClient.Height()-rectHelper.Height())/2+
				(rectClient.Height()-rectHelper.Height())%2;
			rectText.bottom=rectText.top+rectHelper.Height();
		}

		// adjust the text box depending on text alignment style
		DWORD dwStyle=GetStyle()&0x0000000f;
		switch(dwStyle)
		{
		// SS_CENTER
		case 1:
			bTwoParts=TRUE;
			if(m_bVertOriented)
			{
				rectSeparator.bottom=(rectSeparator.bottom-rectSeparator.top)/2-
					rectText.Height()/2-6;
				rectText.top+=(rectClient.Height()-rectHelper.Height())/2+
					(rectClient.Height()-rectHelper.Height())%2;
				rectText.bottom=rectText.top+rectHelper.Height();
			}
			else
			{
				rectSeparator.right=(rectSeparator.right-rectSeparator.left)/2-
					rectText.Width()/2-6;
				rectText.left+=(rectClient.Width()-rectHelper.Width())/2+
					(rectSeparator.Width()-rectHelper.Width())%2;
				rectText.right=rectText.left+rectHelper.Width();
			}
			break;
		// SS_RIGHT
		case 2:
			if(m_bVertOriented)
			{
				rectSeparator.bottom-=rectText.Height()+6;
				rectText.bottom=rectClient.bottom;
				rectText.top=rectText.bottom-rectHelper.Height();
			}
			else
			{
				rectSeparator.right-=rectText.Width()+6;
				rectText.right=rectClient.right;
				rectText.left=rectText.right-rectHelper.Width();
			}
			break;	
		// SS_LEFT
		default:
			if(m_bVertOriented)
			{
				rectSeparator.top=rectText.bottom+6;
				rectText.top=rectClient.top;
				rectText.bottom=rectText.top+rectHelper.Height();
			}
			else
			{
				rectSeparator.left=rectText.right+6;
				rectText.left=rectClient.left;
				rectText.right=rectText.left+rectHelper.Width();
			}
		}

		rectHelper=rectText;
		if(m_bVertOriented)
		{
			rectHelper.bottom+=rectText.Width();
			rectHelper.right+=rectText.Height();
		}
		// draw text
		dc.DrawText(m_sText,&rectHelper,DT_BOTTOM|DT_LEFT|DT_SINGLELINE);
	}

	// adjust rectangle for separator
	if(m_bVertOriented)
	{
		rectSeparator.left+=(rectSeparator.Width())/2+
			(rectSeparator.Width())%2-1;
		rectSeparator.right=rectSeparator.left+2;
	}
	else
	{
		rectSeparator.top+=(rectSeparator.Height())/2+
			(rectSeparator.Height())%2-1;
		rectSeparator.bottom=rectSeparator.top+2;
	}

	// draw separator
	if((m_bVertOriented && rectSeparator.top<rectSeparator.bottom) ||
		(!m_bVertOriented && rectSeparator.left<rectSeparator.right))
	{
		dc.Draw3dRect(&rectSeparator,m_clrTopLeft,m_clrBottomRight);

		if(bTwoParts)
		{
			if(m_bVertOriented)
			{
				rectSeparator.top=rectSeparator.bottom+rectText.Height()+12;
				rectSeparator.bottom=rectClient.bottom;
			}
			else
			{
				rectSeparator.left=rectSeparator.right+rectText.Width()+12;
				rectSeparator.right=rectClient.right;
			}

			dc.Draw3dRect(&rectSeparator,m_clrTopLeft,m_clrBottomRight);
		}
	}

	if(pOldFont!=NULL)
		dc.SelectObject(pOldFont);

	// Do not call CStatic::OnPaint() for painting messages
}

// v9.3 - update 03 - 64-bit - changed these to LRESULT, WPARAM, LPARAM from LONG, UINT, LONG
LRESULT COXSeparator::OnSetText(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);

	// save the window text
	m_sText=(LPCTSTR)(LONG_PTR)lParam;

	RedrawWindow();

	return TRUE;
}

// v9.3 - update 03 - 64-bit - changed these to LRESULT, WPARAM, LPARAM from LONG, UINT, LONG
LRESULT COXSeparator::OnGetText(WPARAM wParam, LPARAM lParam)
{
	if(wParam>0)
	{
		wParam=wParam>(UINT)m_sText.GetLength()+1 ? 
			m_sText.GetLength()+1 : wParam;
		VERIFY(lstrcpyn((LPTSTR)(LONG_PTR)lParam,m_sText,wParam-1)!=NULL);
	}
	return (LONG)wParam;
}

// v9.3 - update 03 - 64-bit - changed these to LRESULT, WPARAM, LPARAM from LONG, UINT, LONG
LRESULT COXSeparator::OnGetTextLength(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);
	UNREFERENCED_PARAMETER(lParam);

	return (LONG)m_sText.GetLength();
}

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)

Share

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
 
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

394 members


| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 13 Feb 2013
Article Copyright 2008 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid