Click here to Skip to main content
15,861,168 members
Articles / Desktop Programming / WTL

Form Designer

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

#ifndef __VIEWABLEFORM_H_
#define __VIEWABLEFORM_H_

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

#include "DDFormsCP.h"

/////////////////////////////////////////////////////////////////////////////
// CViewableForm
class ATL_NO_VTABLE CViewableForm :
	public CWindowImpl<CViewableForm>,
	public CComObjectRootEx<CComSingleThreadModel>,
	public IDispatchImpl<IViewableForm, &IID_IViewableForm, &LIBID_DDFORMSLib, TlbVerMaj, TlbVerMin>,
	public IConnectionPointContainerImpl<CViewableForm>,
	public CComCoClass<CViewableForm, &CLSID_ViewableForm>,
	public CProxy_IViewableFormEvents<CViewableForm>
{
private:
// properties
	// background color
	OLE_COLOR m_BackColor;
	// foreground color
	OLE_COLOR m_ForeColor;

	// returns the state of the shift key modifiers
	long GetShiftKeyModifiers() const;

public:
	CViewableForm();
	virtual ~CViewableForm();

	// sets the form colors
	void SetColors(OLE_COLOR BackColor,OLE_COLOR ForeColor);
	// returns the form colors
	void GetColors(OLE_COLOR &BackColor,OLE_COLOR &ForeColor) const;

DECLARE_NO_REGISTRY()

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CViewableForm)
	COM_INTERFACE_ENTRY(IViewableForm)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CViewableForm)
	CONNECTION_POINT_ENTRY(DIID__IViewableFormEvents)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(CViewableForm)
	MESSAGE_HANDLER(WM_PAINT, OnPaint)
	MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
	MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseDown)
	MESSAGE_HANDLER(WM_LBUTTONUP, OnMouseUp)
	MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnMouseDblClk)
	MESSAGE_HANDLER(WM_RBUTTONDOWN, OnMouseDown)
	MESSAGE_HANDLER(WM_RBUTTONUP, OnMouseUp)
	MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnMouseDblClk)
	MESSAGE_HANDLER(WM_MBUTTONDOWN, OnMouseDown)
	MESSAGE_HANDLER(WM_MBUTTONUP, OnMouseUp)
	MESSAGE_HANDLER(WM_MBUTTONDBLCLK, OnMouseDblClk)
	MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
	MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
	MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
	MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)
	MESSAGE_HANDLER(WM_CHAR, OnChar)
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
	LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMouseDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMouseUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMouseDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

// IViewableForm
public:
	STDMETHOD(get_Width)(/*[out, retval]*/ long *pVal);
	STDMETHOD(get_Height)(/*[out, retval]*/ long *pVal);
	STDMETHOD(get_BackColor)(/*[out, retval]*/ OLE_COLOR *pVal);
	STDMETHOD(get_ForeColor)(/*[out, retval]*/ OLE_COLOR *pVal);
};

#endif //__VIEWABLEFORM_H_

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