Click here to Skip to main content
15,892,575 members
Articles / Desktop Programming / WTL

Form Designer

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

#pragma once

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

/////////////////////////////////////////////////////////////////////////////
// IDDPicture
[
	object,
	uuid("DD970934-D763-45BD-9ED5-30FCBB71D377"),
	dual,
	helpstring("IDDPicture Interface"),
	pointer_default(unique)
]
__interface IDDPicture : public IDispatch
{
	////////////////////////////////////////
	// 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);
	////////////////////////////////////////
	// picture
	[propget, requestedit, bindable,
		id(DISPID_PICTURE),
		helpstring("")]
	HRESULT Picture([out, retval] IPictureDisp** pVal);
	[propput, requestedit, bindable,
		id(DISPID_PICTURE),
		helpstring("")]
	HRESULT Picture([in] IPictureDisp* newVal);
	[propputref, requestedit, bindable,
		id(DISPID_PICTURE),
		helpstring("")]
	HRESULT Picture([in] IPictureDisp* newVal);
	////////////////////////////////////////
	// picture align
	[propget, requestedit, bindable,
		id(DISPID_PICTUREALIGN),
		helpstring("")]
	HRESULT PictureAlign([out, retval] ddcpPictureAlign* pVal);
	[propput, requestedit, bindable,
		id(DISPID_PICTUREALIGN),
		helpstring("")]
	HRESULT PictureAlign([in] ddcpPictureAlign newVal);
	////////////////////////////////////////
	// size to fit
	[propget, requestedit, bindable,
		id(DISPID_SIZETOFIT),
		helpstring("")]
	HRESULT SizeToFit([out, retval] VARIANT_BOOL* pVal);
	[propput, requestedit, bindable,
		id(DISPID_SIZETOFIT),
		helpstring("")]
	HRESULT SizeToFit([in] VARIANT_BOOL newVal);
	////////////////////////////////////////
	// border style
	[propget, requestedit, bindable,
		id(DISPID_BORDERSTYLE),
		helpstring("")]
	HRESULT BorderStyle([out, retval] ddcpBorderStyle* pVal);
	[propput, requestedit, bindable,
		id(DISPID_BORDERSTYLE),
		helpstring("")]
	HRESULT BorderStyle([in] ddcpBorderStyle newVal);
};

/////////////////////////////////////////////////////////////////////////////
// _IDDPictureEvents
[
	uuid("2FAED65F-F915-4D48-8830-3112DB0BF05C"),
	dispinterface,
	helpstring("_IDDPictureEvents Interface")
]
__interface _IDDPictureEvents
{
};

/////////////////////////////////////////////////////////////////////////////
// CDDPicture
[
	coclass,
	threading("apartment"),
	vi_progid("DDControlPack.DDPicture"),
	progid("DDControlPack.DDPicture.1"),
	version(1.0),
	uuid("C5C5D448-5B85-43C9-8D70-8EF3FDC78335"),
	helpstring("DDPicture Class"),
	event_source("com"),
	support_error_info(IDDPicture),
	registration_script("control.rgs")
]
class ATL_NO_VTABLE CDDPicture :
	public IDispatchImpl<IDDPicture>,
	public IPersistStreamInitImpl<CDDPicture>,
	public IOleControlImpl<CDDPicture>,
	public IOleObjectImpl<CDDPicture>,
	public IOleInPlaceActiveObjectImpl<CDDPicture>,
	public IViewObjectExImpl<CDDPicture>,
	public IOleInPlaceObjectWindowlessImpl<CDDPicture>,
	public IPersistStorageImpl<CDDPicture>,
	public ISpecifyPropertyPagesImpl<CDDPicture>,
	public IQuickActivateImpl<CDDPicture>,
	public IDataObjectImpl<CDDPicture>,
	public CComControl<CDDPicture>
{
private:
	__event __interface _IDDPictureEvents;

/////////////////////////////////////////////////////////////////////////////
// properties
	LONG					m_Reserved0;			// reserved
	LONG					m_Reserved1;			// reserved
	OLE_COLOR				m_BackColor;			// background color
	CComPtr<IPictureDisp>	m_spPictureDisp;		// picture
	ddcpPictureAlign		m_PictureAlign;			// picture align
	VARIANT_BOOL			m_SizeToFit;			// size to fit
	ddcpBorderStyle			m_BorderStyle;			// border style

/////////////////////////////////////////////////////////////////////////////
// property change validators
	HRESULT OnPictureAlignChanging(ddcpPictureAlign newVal);
	HRESULT OnBorderStyleChanging(ddcpBorderStyle newVal);

/////////////////////////////////////////////////////////////////////////////
// property change handlers

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

	// draws the border
	void DrawBorder(CDCHandle hDC,CRect Rect);
	// draws the picture
	void DrawPicture(CDCHandle hDC,CRect Rect);

public:
	CDDPicture();

DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct();
	void FinalRelease();

static const TCHAR* GetObjectFriendlyName();

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

BEGIN_PROP_MAP(CDDPicture)
	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("BackColor", DISPID_BACKCOLOR, CLSID_NULL)
	PROP_ENTRY("Picture", DISPID_PICTURE, CLSID_NULL)
	PROP_ENTRY("PictureAlign", DISPID_PICTUREALIGN, CLSID_NULL)
	PROP_ENTRY("SizeToFit", DISPID_SIZETOFIT, CLSID_NULL)
	PROP_ENTRY("BorderStyle", DISPID_BORDERSTYLE, CLSID_NULL)
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CDDPicture)
	MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
	CHAIN_MSG_MAP(CComControl<CDDPicture>)
	DEFAULT_REFLECTION_HANDLER()
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);

// base class overrides
	HRESULT OnDraw(ATL_DRAWINFO& di);

// message handlers
	LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

// IOleObject
	STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);

// IViewObjectEx
	DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IDDPicture
	IMPLEMENT_CUSTOM_COLOR_PROPERTY(BackColor,m_BackColor,DISPID_BACKCOLOR);
	IMPLEMENT_CUSTOM_PICTURE_PROPERTY(Picture,m_spPictureDisp,DISPID_PICTURE);
	IMPLEMENT_CUSTOM_PROPERTY(ddcpPictureAlign,PictureAlign,m_PictureAlign,DISPID_PICTUREALIGN);
	IMPLEMENT_CUSTOM_BOOL_PROPERTY(SizeToFit,m_SizeToFit,DISPID_SIZETOFIT);
	IMPLEMENT_CUSTOM_PROPERTY(ddcpBorderStyle,BorderStyle,m_BorderStyle,DISPID_BORDERSTYLE);
};

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