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

Form Designer

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

#pragma once

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

/////////////////////////////////////////////////////////////////////////////
// IDDHorzScrollBar
[
	object,
	uuid("C00D5EF4-A166-447D-A934-3B91E856C5FC"),
	dual,
	helpstring("IDDHorzScrollBar Interface"),
	pointer_default(unique)
]
__interface IDDHorzScrollBar : 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);
	////////////////////////////////////////
	// minimum value
	[propget, requestedit, bindable,
		id(DISPID_MINVALUE),
		helpstring("")]
	HRESULT Min([out, retval] LONG* pVal);
	[propput, requestedit, bindable,
		id(DISPID_MINVALUE),
		helpstring("")]
	HRESULT Min([in] LONG newVal);
	////////////////////////////////////////
	// maximum value
	[propget, requestedit, bindable,
		id(DISPID_MAXVALUE),
		helpstring("")]
	HRESULT Max([out, retval] LONG* pVal);
	[propput, requestedit, bindable,
		id(DISPID_MAXVALUE),
		helpstring("")]
	HRESULT Max([in] LONG newVal);
	////////////////////////////////////////
	// small step
	[propget, requestedit, bindable,
		id(DISPID_SMALLSTEP),
		helpstring("")]
	HRESULT SmallStep([out, retval] LONG* pVal);
	[propput, requestedit, bindable,
		id(DISPID_SMALLSTEP),
		helpstring("")]
	HRESULT SmallStep([in] LONG newVal);
	////////////////////////////////////////
	// large step
	[propget, requestedit, bindable,
		id(DISPID_LARGESTEP),
		helpstring("")]
	HRESULT LargeStep([out, retval] LONG* pVal);
	[propput, requestedit, bindable,
		id(DISPID_LARGESTEP),
		helpstring("")]
	HRESULT LargeStep([in] LONG newVal);
	////////////////////////////////////////
	// value
	[propget, requestedit, bindable,
		id(DISPID_VALUE_NOTDEFAULT),
		helpstring("")]
	HRESULT Value([out, retval] LONG* pVal);
	[propput, requestedit, bindable,
		id(DISPID_VALUE_NOTDEFAULT),
		helpstring("")]
	HRESULT Value([in] LONG newVal);
	////////////////////////////////////////
	// default property
	[propget, nonbrowsable,
		id(DISPID_VALUE),
		helpstring("")]
	HRESULT _Default([out, retval] LONG* pVal);
	[propput, nonbrowsable,
		id(DISPID_VALUE),
		helpstring("")]
	HRESULT _Default([in] LONG newVal);
};

/////////////////////////////////////////////////////////////////////////////
// _IDDHorzScrollBarEvents
[
	uuid("F332CF89-16C0-4F86-9CB1-DA3414048581"),
	dispinterface,
	helpstring("_IDDHorzScrollBarEvents Interface")
]
__interface _IDDHorzScrollBarEvents
{
	[id(1), helpstring("")] HRESULT Change();
	[id(2), helpstring("")] HRESULT Scroll();
};

/////////////////////////////////////////////////////////////////////////////
// CDDHorzScrollBar
[
	coclass,
	threading("apartment"),
	vi_progid("DDControlPack.DDHorzScrollBar"),
	progid("DDControlPack.DDHorzScrollBar.1"),
	version(1.0),
	uuid("192A56C3-7D0E-45CC-85A3-7ED56E0755E8"),
	helpstring("DDHorzScrollBar Class"),
	event_source("com"),
	support_error_info(IDDHorzScrollBar),
	registration_script("control.rgs")
]
class ATL_NO_VTABLE CDDHorzScrollBar :
	public IDispatchImpl<IDDHorzScrollBar>,
	public IPersistStreamInitImpl<CDDHorzScrollBar>,
	public IOleControlImpl<CDDHorzScrollBar>,
	public IOleObjectImpl<CDDHorzScrollBar>,
	public IOleInPlaceActiveObjectImpl<CDDHorzScrollBar>,
	public IViewObjectExImpl<CDDHorzScrollBar>,
	public IOleInPlaceObjectWindowlessImpl<CDDHorzScrollBar>,
	public IPersistStorageImpl<CDDHorzScrollBar>,
	public ISpecifyPropertyPagesImpl<CDDHorzScrollBar>,
	public IQuickActivateImpl<CDDHorzScrollBar>,
	public IDataObjectImpl<CDDHorzScrollBar>,
	public CComControl<CDDHorzScrollBar>
{
private:
	CContainedWindow m_ctlScrollBar;

	__event __interface _IDDHorzScrollBarEvents;

/////////////////////////////////////////////////////////////////////////////
// properties
	LONG					m_Reserved0;			// reserved
	LONG					m_Reserved1;			// reserved
	VARIANT_BOOL			m_Enabled;				// enabled
	LONG					m_MinValue;				// minimum value
	LONG					m_MaxValue;				// maximum value
	LONG					m_SmallStep;			// small step
	LONG					m_LargeStep;			// large step
	LONG					m_Value;				// value

/////////////////////////////////////////////////////////////////////////////
// property change validators
	HRESULT OnSmallStepChanging(LONG newVal);
	HRESULT OnLargeStepChanging(LONG newVal);
	HRESULT OnValueChanging(LONG newVal);

/////////////////////////////////////////////////////////////////////////////
// property change handlers
	void OnEnabledChanged();
	void OnValueChanged();

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

	// returns the value for the passed scroll position
	LONG ValueFromScrollPos(LONG Pos);
	// returns the scroll position for the passed value
	LONG ScrollPosFromValue(LONG Value);

	// returns the normalised minimum value
	LONG NormalisedMinValue();
	// returns the normalised maximum value
	LONG NormalisedMaxValue();

public:
	CDDHorzScrollBar();

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(CDDHorzScrollBar)
	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("MinValue", DISPID_MINVALUE, CLSID_NULL)
	PROP_ENTRY("MaxValue", DISPID_MAXVALUE, CLSID_NULL)
	PROP_ENTRY("SmallStep", DISPID_SMALLSTEP, CLSID_NULL)
	PROP_ENTRY("LargeStep", DISPID_LARGESTEP, CLSID_NULL)
	PROP_ENTRY("Value", DISPID_VALUE_NOTDEFAULT, CLSID_NULL)
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CDDHorzScrollBar)
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
	MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
	CHAIN_MSG_MAP(CComControl<CDDHorzScrollBar>)
ALT_MSG_MAP(1)
	// Replace this with message map entries for superclassed ScrollBar
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 OnHScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

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

// IViewObjectEx
	DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IDDHorzScrollBar
	IMPLEMENT_CUSTOM_BOOL_PROPERTY(Enabled,m_Enabled,DISPID_ENABLED);
	STDMETHOD(get_Min)(LONG *pVal);
	STDMETHOD(put_Min)(LONG newVal);
	STDMETHOD(get_Max)(LONG *pVal);
	STDMETHOD(put_Max)(LONG newVal);
	IMPLEMENT_CUSTOM_PROPERTY(LONG,SmallStep,m_SmallStep,DISPID_SMALLSTEP);
	IMPLEMENT_CUSTOM_PROPERTY(LONG,LargeStep,m_LargeStep,DISPID_LARGESTEP);
	IMPLEMENT_CUSTOM_PROPERTY(LONG,Value,m_Value,DISPID_VALUE_NOTDEFAULT);
	STDMETHOD(get__Default)(LONG* pVal);
	STDMETHOD(put__Default)(LONG 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