Click here to Skip to main content
15,860,943 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.
// ValuePicker.h: interface for the CValuePicker class.
//
// Author : David Shepherd
//			Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_VALUEPICKER_H__CA234EE1_7004_11D6_BCED_A37201894C44__INCLUDED_)
#define AFX_VALUEPICKER_H__CA234EE1_7004_11D6_BCED_A37201894C44__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// list box id
#define VP_IDC_LIST		0x1000
// list box message map id
#define VP_MSG_MAP_LIST	VP_IDC_LIST

/////////////////////////////////////////////////////////////////////////////
// CValuePickerValue
class CValuePickerValue
{
public:
	// name
	std::wstring m_Name;
	// value
	CComVariant m_Value;

	CValuePickerValue();
	virtual ~CValuePickerValue();
};
// CValuePickerValue vector
typedef std::vector<CValuePickerValue> CValuePickerValueVector;

/////////////////////////////////////////////////////////////////////////////
// CValuePicker
class CValuePicker : public CWindowImpl<CValuePicker>
{
private:
	// list box
	CContainedWindowT<CListBox> m_List;

	// while TRUE this keeps the internal message loop running
	BOOL m_RunMessageLoop;

	// returns the value picker font
	CFontHandle GetFont();

	// sizes and positions the value picker
	void SetSizeAndPosition(const CPoint &TopRight,DWORD Width);

	// selects the initial value
	void SelectStartValue();

public:
	// available values
	CValuePickerValueVector m_Values;
	// value
	CComVariant m_Value;

	CValuePicker();
	virtual ~CValuePicker();

	// picks the value
	BOOL PickValue(const CWindow &Parent,const CPoint &TopRight,DWORD Width);

BEGIN_MSG_MAP(CValuePicker)
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
	MESSAGE_HANDLER(WM_SIZE, OnSize)
	MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)
	MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
	MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
	COMMAND_HANDLER(VP_IDC_LIST, LBN_SELCHANGE, OnSelChangeList)
// list box message map
ALT_MSG_MAP(VP_MSG_MAP_LIST)
	MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
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 OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSelChangeList(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

// message handlers (list box)
};

#endif // !defined(AFX_VALUEPICKER_H__CA234EE1_7004_11D6_BCED_A37201894C44__INCLUDED_)

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