Click here to Skip to main content
14,129,857 members
Click here to Skip to main content

Stats

299.2K views
79.1K downloads
227 bookmarked
Posted 30 Dec 2005
Licenced CPOL

Form Designer

, 1 Aug 2009
Component for adding scriptable forms capabilities to an application.
MFCDemo.exe
CSDemo
App.ico
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
CSDemo.suo
DaeDoe.bmp
MFCDemo
MFCDemo.dsp
MFCDemo.odl
MFCDemo.reg
res
DaeDoe.bmp
MFCDemo.ico
MFCDemoDoc.ico
Toolbar1.bmp
Toolbar2.bmp
Toolbar3.bmp
Wand.bmp
VBDemo
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
DaeDoe.bmp
VBDemo.vbp
DDForms.chm
DDForms
Archive
FormEditorItems.rgs
vssver.scc
Constants.scr
DaeDoe.bmp
DDForms.def
DDForms.vcproj
DDForms.vcproj.vspscc
EventSinkPassThrough.rgs
FormEditor.bmp
FormEditor.rgs
FormEditorItemCollection.rgs
FormEditorItemDetails.rgs
FormViewer.bmp
FormViewer.rgs
FormViewerItemCollection.rgs
FormViewerItemDetails.rgs
mssccprj.scc
PropPageExtended.rgs
PropPageFormEditor.rgs
PropPageFormViewer.rgs
PropPageSimpleScriptEditor.rgs
SimpleScriptEditor.bmp
SimpleScriptEditor.rgs
vssver.scc
DDFormsTools
CodeMaxDriver
CodeMaxDriver.rgs
CodeMaxDriver.vcproj
CodeMaxDriver.vcproj.vspscc
CodeMaxDriverps.def
CodeMaxDriverPS.vcproj
CodeMaxDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
CodeSenseDriver
CodeSenseDriver.rgs
CodeSenseDriver.vcproj
CodeSenseDriver.vcproj.vspscc
CodeSenseDriverps.def
CodeSenseDriverPS.vcproj
CodeSenseDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
DDPropPageAll
DDPropPageAll.def
DDPropPageAll.vcproj
DDPropPageAll.vcproj.vspscc
mssccprj.scc
PropPageAll.rgs
vssver.scc
DDUnlock
DDUnlock.vcproj
DDUnlock.vcproj.vspscc
mssccprj.scc
vssver.scc
DDControlPack
DDButton.bmp
DDCheckBox.bmp
DDComboBox.bmp
DDControlPack.rgs
DDControlPack.vcproj
DDControlPack.vcproj.vspscc
DDHorzScrollBar.bmp
DDLabel.bmp
DDListBox.bmp
DDPicture.bmp
DDRadioButton.bmp
DDTextBox.bmp
DDVertScrollBar.bmp
mssccprj.scc
vssver.scc
Redistributables
Ansi
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
Unicode
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
// DDLabel.cpp : Implementation of CDDLabel
//
// Author : David Shepherd
//			Copyright (c) 2003, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include ".\DDLabel.h"

/////////////////////////////////////////////////////////////////////////////
// CDDLabel

CDDLabel::CDDLabel()
{
	// initialise everything
	m_bWindowOnly=TRUE;
	m_Reserved0=0;
	m_Reserved1=0;
	m_BackColor=MAKE_OLE_COLOR(COLOR_BTNFACE);
	m_ForeColor=MAKE_OLE_COLOR(COLOR_BTNTEXT);
	m_TextAlign=ddcpTextAlignLeft;
	m_CenterVertically=VARIANT_FALSE;
	m_BorderStyle=ddcpBorderStyleNone;
}

HRESULT CDDLabel::FinalConstruct()
{
IMP_BEGIN
	// create the default font
	m_spFontDisp=CreateDefaultFont();
IMP_END
	return RetVal;
}

void CDDLabel::FinalRelease()
{
}

const TCHAR* CDDLabel::GetObjectFriendlyName()
{
	// return the object friendly name
	return _T("DDLabel");
}

HRESULT CDDLabel::OnTextAlignChanging(ddcpTextAlign newVal)
{
IMP_BEGIN
	// check the new value is valid
	if(newVal < ddcpTextAlign_First or newVal > ddcpTextAlign_Last)
	{
		throw CHResult(E_INVALIDARG);
	}
IMP_END
	return RetVal;
}

HRESULT CDDLabel::OnBorderStyleChanging(ddcpBorderStyle newVal)
{
IMP_BEGIN
	// check the new value is valid
	if(newVal < ddcpBorderStyle_First or newVal > ddcpBorderStyle_Last)
	{
		throw CHResult(E_INVALIDARG);
	}
IMP_END
	return RetVal;
}

void CDDLabel::DrawBorder(CDCHandle hDC,CRect Rect)
{
	// save the device context state
	CAutoDCState AutoDCState(hDC);
	// get the draw edge type
	UINT DrawEdgeType=0;
	switch(m_BorderStyle)
	{
	// none
	case ddcpBorderStyleNone:
		break;
	// sunken
	case ddcpBorderStyleSunken:
		DrawEdgeType=EDGE_SUNKEN;
		break;
	// raised
	case ddcpBorderStyleRaised:
		DrawEdgeType=EDGE_RAISED;
		break;
	// etched
	case ddcpBorderStyleEtched:
		DrawEdgeType=EDGE_ETCHED;
		break;
	// bump
	case ddcpBorderStyleBump:
		DrawEdgeType=EDGE_BUMP;
		break;
	// unknown
	default:
		ATLASSERT(FALSE);
		break;
	}
	// draw the border
	if(DrawEdgeType)
	{
		if(hDC.DrawEdge(Rect,DrawEdgeType,BF_RECT)==FALSE)
		{
			throw std::exception();
		}
	}
}

void CDDLabel::DrawText(CDCHandle hDC,CRect Rect)
{
	USES_CONVERSION;
	// save the device context state
	CAutoDCState AutoDCState(hDC);
	// set the background color
	COLORREF BackColor=RGB(0,0,0);
	if(!SUCCEEDED(OleTranslateColor(m_BackColor,NULL,&BackColor)))
	{
		throw std::exception();
	}
	if(hDC.SetBkColor(BackColor)==CLR_INVALID)
	{
		throw std::exception();
	}
	// set the foreground color
	COLORREF ForeColor=RGB(0,0,0);
	if(!SUCCEEDED(OleTranslateColor(m_ForeColor,NULL,&ForeColor)))
	{
		throw std::exception();
	}
	if(hDC.SetTextColor(ForeColor)==CLR_INVALID)
	{
		throw std::exception();
	}
	// set the font
	CComQIPtr<IFont> spFont(m_spFontDisp);
	if(spFont==NULL)
	{
		throw std::exception();
	}
	CFontHandle hFont;
	if(!SUCCEEDED(spFont->get_hFont(&hFont.m_hFont)))
	{
		throw std::exception();
	}
	if(hDC.SelectFont(hFont)==NULL)
	{
		throw std::exception();
	}
	// fill in the background
	hDC.FillSolidRect(Rect,BackColor);
	// get the draw text flags
	UINT DrawTextFlags=DT_NOPREFIX|DT_WORDBREAK;
	switch(m_TextAlign)		// text align
	{
	// left
	case ddcpTextAlignLeft:
		DrawTextFlags |= DT_LEFT;
		break;
	// center
	case ddcpTextAlignCenter:
		DrawTextFlags |= DT_CENTER;
		break;
	// right
	case ddcpTextAlignRight:
		DrawTextFlags |= DT_RIGHT;
		break;
	// unknown
	default:
		ATLASSERT(FALSE);
		break;
	}
	if(m_CenterVertically)	// center vertically
	{
		DrawTextFlags |= DT_VCENTER|DT_SINGLELINE;
		// todo : remove DT_WORDBREAK if required
	}
	// draw the text
	if(hDC.DrawText(W2CT(BSTR2W(m_Text)),-1,Rect,DrawTextFlags)==0)
	{
		throw std::exception();
	}
}

HRESULT CDDLabel::OnDraw(ATL_DRAWINFO& di)
{
IMP_BEGIN
	// device context wrapper
	CDCHandle hDC(di.hdcDraw);
	// bounding rectangle
	CRect Rect=*(RECT*)di.prcBounds;
	// create GDI object wrappers
	// this must be done before the memory device context state is saved
	CBitmap Bitmap;
	// create the memory device context
	CDC dcMem;
	if(dcMem.CreateCompatibleDC(hDC)==NULL)
	{
		throw CHResult(E_FAIL);
	}
	// save the memory device context state
	CAutoDCState AutoDCState(dcMem);
	// create the bitmap and select it into the memory device context
	if(Bitmap.CreateCompatibleBitmap(hDC,Rect.Width(),Rect.Height())==NULL)
	{
		throw CHResult(E_FAIL);
	}
	if(dcMem.SelectBitmap(Bitmap)==NULL)
	{
		throw CHResult(E_FAIL);
	}
	// map coordinates to the control
	if(dcMem.SetWindowOrg(Rect.left,Rect.top)==FALSE)
	{
		throw CHResult(E_FAIL);
	}
	// draw the border
	CRect BorderRect=Rect;
	DrawBorder(CDCHandle(dcMem),BorderRect);
	// get the area in which to draw the text
	CRect TextRect=Rect;
	if(	m_BorderStyle==ddcpBorderStyleSunken	or
		m_BorderStyle==ddcpBorderStyleRaised	or
		m_BorderStyle==ddcpBorderStyleEtched	or
		m_BorderStyle==ddcpBorderStyleBump)
	{
		if(TextRect.Width() < 4 or TextRect.Height() < 4)
		{
			TextRect.SetRectEmpty();		// there is no room for the text
		}
		else
		{
			TextRect.InflateRect(-2,-2);	// there is room for the text
		}
	}
	// draw the text
	DrawText(CDCHandle(dcMem),TextRect);
	// update the screen
	if(hDC.BitBlt(
		Rect.left,Rect.top,Rect.Width(),Rect.Height(),
			dcMem,Rect.left,Rect.top,SRCCOPY)==FALSE)
	{
		throw CHResult(E_FAIL);
	}
IMP_END
	return RetVal;
}

LRESULT CDDLabel::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// to prevent flicker do not erase the background
	return TRUE;
}

STDMETHODIMP CDDLabel::SetClientSite(IOleClientSite *pClientSite)
{
IMP_BEGIN
	// call the base class
	HRESULT hr=IOleObjectImpl<CDDLabel>::SetClientSite(pClientSite);
	if(!SUCCEEDED(hr))
	{
		throw CHResult(hr);
	}
	// set the background color based on the container ambient properties
	OLE_COLOR BackColor=RGB(0,0,0);
	if(SUCCEEDED(GetAmbientBackColor(BackColor)))
	{
		(void)put_BackColor(BackColor);
	}
	// set the foreground color based on the container ambient properties
	OLE_COLOR ForeColor=RGB(0,0,0);
	if(SUCCEEDED(GetAmbientForeColor(ForeColor)))
	{
		(void)put_ForeColor(ForeColor);
	}
IMP_END
	return RetVal;
}

STDMETHODIMP CDDLabel::get__Default(BSTR* pVal)
{
	// delegate to the required default property
	return get_Text(pVal);
}

STDMETHODIMP CDDLabel::put__Default(BSTR newVal)
{
	// delegate to the required default property
	return put_Text(newVal);
}

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

DaveShep
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 1 Aug 2009
Article Copyright 2005 by DaveShep
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid