Click here to Skip to main content
15,889,808 members
Articles / Desktop Programming / WTL

Form Designer

26 Jul 2021CPOL24 min read 351.6K   82.5K   230  
Component for adding scriptable forms capabilities to an application.
// DDTextBox.h : Declaration of the CDDTextBox
//
// Author : David Shepherd
//			Copyright (c) 2003, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "resource.h"       // main symbols
#include <atlctl.h>

// the edit box id
#define IDC_EDIT	0x1000

/////////////////////////////////////////////////////////////////////////////
// IDDTextBox
[
	object,
	uuid("9DA41C46-7F5C-46D2-A537-F746BD11D451"),
	dual,
	helpstring("IDDTextBox Interface"),
	pointer_default(unique)
]
__interface IDDTextBox : public IDispatch
{
	////////////////////////////////////////
	// enabled
	[propget, requestedit, bindable,
		id(DISPID_ENABLED),
		helpstring("")]
	HRESULT Enabled([out, retval] VARIANT_BOOL* pVal);
	[propput, requestedit, bindable,
		id(DISPID_ENABLED),
		helpstring("")]
	HRESULT Enabled([in] VARIANT_BOOL newVal);
	////////////////////////////////////////
	// background color
	[propget, requestedit, bindable,
		id(DISPID_BACKCOLOR),
		helpstring("")]
	HRESULT BackColor([out, retval] OLE_COLOR* pVal);
	[propput, requestedit, bindable,
		id(DISPID_BACKCOLOR),
		helpstring("")]
	HRESULT BackColor([in] OLE_COLOR newVal);
	////////////////////////////////////////
	// foreground color
	[propget, requestedit, bindable,
		id(DISPID_FORECOLOR),
		helpstring("")]
	HRESULT ForeColor([out, retval] OLE_COLOR* pVal);
	[propput, requestedit, bindable,
		id(DISPID_FORECOLOR),
		helpstring("")]
	HRESULT ForeColor([in] OLE_COLOR newVal);
	////////////////////////////////////////
	// font
	[propget, requestedit, bindable,
		id(DISPID_FONT),
		helpstring("")]
	HRESULT Font([out, retval] IFontDisp** pVal);
	[propput, requestedit, bindable,
		id(DISPID_FONT),
		helpstring("")]
	HRESULT Font([in] IFontDisp* newVal);
	[propputref, requestedit, bindable,
		id(DISPID_FONT),
		helpstring("")]
	HRESULT Font([in] IFontDisp* newVal);
	////////////////////////////////////////
	// text
	[propget, bindable,
		id(DISPID_TEXT),
		helpstring("")]
	HRESULT Text([out, retval] BSTR* pVal);
	[propput, bindable,
		id(DISPID_TEXT),
		helpstring("")]
	HRESULT Text([in] BSTR newVal);
	////////////////////////////////////////
	// default property
	[propget, nonbrowsable,
		id(DISPID_VALUE),
		helpstring("")]
	HRESULT _Default([out, retval] BSTR* pVal);
	[propput, nonbrowsable,
		id(DISPID_VALUE),
		helpstring("")]
	HRESULT _Default([in] BSTR newVal);
};

/////////////////////////////////////////////////////////////////////////////
// _IDDTextBoxEvents
[
	uuid("A033DEA6-FB10-4F7C-A65E-6EC49B0069B6"),
	dispinterface,
	helpstring("_IDDTextBoxEvents Interface")
]
__interface _IDDTextBoxEvents
{
	[id(1), helpstring("")] HRESULT Change();
};

/////////////////////////////////////////////////////////////////////////////
// CDDTextBox
[
	coclass,
	threading("apartment"),
	vi_progid("DDControlPack.DDTextBox"),
	progid("DDControlPack.DDTextBox.1"),
	version(1.0),
	uuid("9DD0C8DC-2EA3-4001-8D85-B5E4DA6DD55A"),
	helpstring("DDTextBox Class"),
	event_source("com"),
	support_error_info(IDDTextBox),
	registration_script("control.rgs")
]
class ATL_NO_VTABLE CDDTextBox :
	public IDispatchImpl<IDDTextBox>,
	public IPersistStreamInitImpl<CDDTextBox>,
	public IOleControlImpl<CDDTextBox>,
	public IOleObjectImpl<CDDTextBox>,
	public IOleInPlaceActiveObjectImpl<CDDTextBox>,
	public IViewObjectExImpl<CDDTextBox>,
	public IOleInPlaceObjectWindowlessImpl<CDDTextBox>,
	public IPersistStorageImpl<CDDTextBox>,
	public ISpecifyPropertyPagesImpl<CDDTextBox>,
	public IQuickActivateImpl<CDDTextBox>,
	public IDataObjectImpl<CDDTextBox>,
	public CComControl<CDDTextBox>
{
private:
	CContainedWindow m_ctlEdit;

	__event __interface _IDDTextBoxEvents;

/////////////////////////////////////////////////////////////////////////////
// properties
	LONG					m_Reserved0;			// reserved
	LONG					m_Reserved1;			// reserved
	VARIANT_BOOL			m_Enabled;				// enabled
	OLE_COLOR				m_BackColor;			// background color
	OLE_COLOR				m_ForeColor;			// foreground color
	CComPtr<IFontDisp>		m_spFontDisp;			// font
	CComBSTR				m_Text;					// text

/////////////////////////////////////////////////////////////////////////////
// property change validators
	HRESULT OnBackColorChanging(OLE_COLOR newVal);

/////////////////////////////////////////////////////////////////////////////
// property change handlers
	void OnEnabledChanged();
	void OnBackColorChanged();
	void OnForeColorChanged();

/////////////////////////////////////////////////////////////////////////////

	// the background brush
	CBrush m_BackBrush;

	// creates the background brush
	void CreateBackgroundBrush(OLE_COLOR BackColor);

	// edit box accelerators
	HACCEL m_hAccel;

public:
	CDDTextBox();

DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct();
	void FinalRelease();

static const TCHAR* GetObjectFriendlyName();

DECLARE_OLEMISC_STATUS(
	OLEMISC_RECOMPOSEONRESIZE |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_INSIDEOUT |
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST)

BEGIN_PROP_MAP(CDDTextBox)
	PROP_DATA_ENTRY("_reserved0", m_Reserved0, VT_I4)
	PROP_DATA_ENTRY("_reserved1", m_Reserved1, VT_I4)
	PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
	PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
	PROP_ENTRY("Enabled", DISPID_ENABLED, CLSID_NULL)
	PROP_ENTRY("BackColor", DISPID_BACKCOLOR, CLSID_NULL)
	PROP_ENTRY("ForeColor", DISPID_FORECOLOR, CLSID_NULL)
	PROP_ENTRY("Font", DISPID_FONT, CLSID_NULL)
	PROP_ENTRY("Text", DISPID_TEXT, CLSID_NULL)
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CDDTextBox)
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
	MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
	MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorEdit)
	COMMAND_HANDLER(IDC_EDIT, EN_CHANGE, OnEditChanged)
	COMMAND_ID_HANDLER(ID_CUT, OnCut)
	COMMAND_ID_HANDLER(ID_COPY, OnCopy)
	COMMAND_ID_HANDLER(ID_PASTE, OnPaste)
	COMMAND_ID_HANDLER(ID_UNDO, OnUndo)
	CHAIN_MSG_MAP(CComControl<CDDTextBox>)
ALT_MSG_MAP(1)
	// Replace this with message map entries for superclassed Edit
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

// message handlers
	BOOL PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet);
	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnEditChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnCut(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnCopy(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnPaste(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnUndo(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

// IOleInPlaceObjectWindowless
	STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip);

// IViewObjectEx
	DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IDDTextBox
	IMPLEMENT_CUSTOM_BOOL_PROPERTY(Enabled,m_Enabled,DISPID_ENABLED);
	IMPLEMENT_CUSTOM_COLOR_PROPERTY(BackColor,m_BackColor,DISPID_BACKCOLOR);
	IMPLEMENT_CUSTOM_COLOR_PROPERTY(ForeColor,m_ForeColor,DISPID_FORECOLOR);
	STDMETHOD(get_Font)(IFontDisp** pVal);
	STDMETHOD(put_Font)(IFontDisp* newVal);
	STDMETHOD(putref_Font)(IFontDisp* newVal);
	STDMETHOD(get_Text)(BSTR* pVal);
	STDMETHOD(put_Text)(BSTR newVal);
	STDMETHOD(get__Default)(BSTR* pVal);
	STDMETHOD(put__Default)(BSTR 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)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions