Click here to Skip to main content
14,140,660 members
Click here to Skip to main content

Stats

299.2K views
79.1K downloads
227 bookmarked
Posted 30 Dec 2005
Licenced CPOL

Form Designer

, 1 Aug 2009
Component for adding scriptable forms capabilities to an application.
MFCDemo.exe
CSDemo
App.ico
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
CSDemo.suo
DaeDoe.bmp
MFCDemo
MFCDemo.dsp
MFCDemo.odl
MFCDemo.reg
res
DaeDoe.bmp
MFCDemo.ico
MFCDemoDoc.ico
Toolbar1.bmp
Toolbar2.bmp
Toolbar3.bmp
Wand.bmp
VBDemo
Bmp
ABottom.bmp
About.bmp
ALeft.bmp
ARight.bmp
ATop.bmp
AX.bmp
BringFront.bmp
Button.bmp
Center.bmp
Check.bmp
Combo.bmp
Copy.bmp
Cut.bmp
Delete.bmp
Down.bmp
Edit.bmp
Frame.bmp
Grid.bmp
GridSettings.bmp
HCenter.bmp
HScroll.bmp
HSL.bmp
HSpace.bmp
HSS.bmp
Left.bmp
List.bmp
New.bmp
Open.bmp
Paste.bmp
Picture.bmp
Preview.bmp
Progress.bmp
Props.bmp
Radio.bmp
Rectangle.bmp
Redo.bmp
Right.bmp
Save.bmp
SelAll.bmp
SelNone.bmp
SendBack.bmp
SL.bmp
Slider.bmp
Spin.bmp
SS.bmp
Tab.bmp
Text.bmp
Undo.bmp
Up.bmp
Validate.bmp
VCenter.bmp
VScroll.bmp
VSL.bmp
VSpace.bmp
VSS.bmp
Wand.bmp
DaeDoe.bmp
VBDemo.vbp
DDForms.chm
DDForms
Archive
FormEditorItems.rgs
vssver.scc
Constants.scr
DaeDoe.bmp
DDForms.def
DDForms.vcproj
DDForms.vcproj.vspscc
EventSinkPassThrough.rgs
FormEditor.bmp
FormEditor.rgs
FormEditorItemCollection.rgs
FormEditorItemDetails.rgs
FormViewer.bmp
FormViewer.rgs
FormViewerItemCollection.rgs
FormViewerItemDetails.rgs
mssccprj.scc
PropPageExtended.rgs
PropPageFormEditor.rgs
PropPageFormViewer.rgs
PropPageSimpleScriptEditor.rgs
SimpleScriptEditor.bmp
SimpleScriptEditor.rgs
vssver.scc
DDFormsTools
CodeMaxDriver
CodeMaxDriver.rgs
CodeMaxDriver.vcproj
CodeMaxDriver.vcproj.vspscc
CodeMaxDriverps.def
CodeMaxDriverPS.vcproj
CodeMaxDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
CodeSenseDriver
CodeSenseDriver.rgs
CodeSenseDriver.vcproj
CodeSenseDriver.vcproj.vspscc
CodeSenseDriverps.def
CodeSenseDriverPS.vcproj
CodeSenseDriverPS.vcproj.vspscc
mssccprj.scc
vssver.scc
DDPropPageAll
DDPropPageAll.def
DDPropPageAll.vcproj
DDPropPageAll.vcproj.vspscc
mssccprj.scc
PropPageAll.rgs
vssver.scc
DDUnlock
DDUnlock.vcproj
DDUnlock.vcproj.vspscc
mssccprj.scc
vssver.scc
DDControlPack
DDButton.bmp
DDCheckBox.bmp
DDComboBox.bmp
DDControlPack.rgs
DDControlPack.vcproj
DDControlPack.vcproj.vspscc
DDHorzScrollBar.bmp
DDLabel.bmp
DDListBox.bmp
DDPicture.bmp
DDRadioButton.bmp
DDTextBox.bmp
DDVertScrollBar.bmp
mssccprj.scc
vssver.scc
Redistributables
Ansi
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
Unicode
CodeMaxDriver.dll
CodeSenseDriver.dll
DDControlPack.dll
DDForms.dll
DDPropPageAll.dll
// ViewableForm.cpp : Implementation of CViewableForm
//
// Author : David Shepherd
//			Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DDForms.h"
#include "ViewableForm.h"

// shift key modifier bits
#define SHIFT_KEY_BIT		0
#define CTRL_KEY_BIT		1
#define ATL_KEY_BIT			2

/////////////////////////////////////////////////////////////////////////////
// CViewableForm

CViewableForm::CViewableForm()
{
	// initialise everything
	m_BackColor=MAKE_OLE_COLOR(COLOR_BTNFACE);
	m_ForeColor=MAKE_OLE_COLOR(COLOR_BTNTEXT);
}

CViewableForm::~CViewableForm()
{
	// clean up
}

long CViewableForm::GetShiftKeyModifiers() const
{
	// return the state of the shift key modifiers
	long ShiftKeyModifiers=0;
	if(GetKeyState(VK_SHIFT) & 0x80000000)		// shift
	{
		ShiftKeyModifiers |= (1 << SHIFT_KEY_BIT);
	}
	if(GetKeyState(VK_CONTROL) & 0x80000000)	// ctrl
	{
		ShiftKeyModifiers |= (1 << CTRL_KEY_BIT);
	}
	if(GetKeyState(VK_MENU) & 0x80000000)		// alt
	{
		ShiftKeyModifiers |= (1 << ATL_KEY_BIT);
	}
	return ShiftKeyModifiers;
}

void CViewableForm::SetColors(OLE_COLOR BackColor,OLE_COLOR ForeColor)
{
	// if the colors are changing a redraw will be required
	if(m_BackColor!=BackColor or m_ForeColor!=ForeColor)
	{
		if(IsWindow())
		{
			(void)Invalidate(FALSE);
		}
	}
	// set the colors
	m_BackColor=BackColor;
	m_ForeColor=ForeColor;
}

void CViewableForm::GetColors(OLE_COLOR &BackColor,OLE_COLOR &ForeColor) const
{
	// return the colors
	BackColor=m_BackColor;
	ForeColor=m_ForeColor;
}

LRESULT CViewableForm::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// get the paint device context
	CPaintDC dc(*this);
	if(dc==NULL)
	{
		throw std::exception();
	}
	// get the client rect
	CRect ClientRect(0,0,0,0);
	if(GetClientRect(ClientRect)==FALSE)
	{
		throw std::exception();
	}
	// fill in the background
	COLORREF RGBBackColor=RGB(0,0,0);
	if(!SUCCEEDED(OleTranslateColor(m_BackColor,NULL,&RGBBackColor)))
	{
		throw std::exception();
	}
	dc.FillSolidRect(ClientRect,RGBBackColor);
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// to prevent flicker do not erase the background
	return TRUE;
}

LRESULT CViewableForm::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// fire the got focus event
	(void)Fire_GotFocus();
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// fire the lost focus event
	(void)Fire_LostFocus();
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnMouseDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// obtain the focus
	(void)SetFocus();
	// get the cursor position
	CPoint CursorPos(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
	// capture the mouse
	if(GetCapture()!=*this)
	{
		(void)SetCapture();
	}
	// fire the mouse down event
	switch(uMsg)
	{
	// left button
	case WM_LBUTTONDOWN:
		(void)Fire_MouseDown(VK_LBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// right button
	case WM_RBUTTONDOWN:
		(void)Fire_MouseDown(VK_RBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// middle button
	case WM_MBUTTONDOWN:
		(void)Fire_MouseDown(VK_MBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// unknown button
	default:
		ATLASSERT(FALSE);
		break;
	}
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnMouseUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// get the cursor position
	CPoint CursorPos(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
	// release the mouse if all buttons are up
	if(!(wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)))
	{
		if(GetCapture()==*this)
		{
			(void)ReleaseCapture();
		}
	}
	// fire the mouse up event
	switch(uMsg)
	{
	// left button
	case WM_LBUTTONUP:
		(void)Fire_MouseUp(VK_LBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// right button
	case WM_RBUTTONUP:
		(void)Fire_MouseUp(VK_RBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// middle button
	case WM_MBUTTONUP:
		(void)Fire_MouseUp(VK_MBUTTON,
			GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
		break;
	// unknown button
	default:
		ATLASSERT(FALSE);
		break;
	}
	// if the cursor is over the form fire the click event
	if(ChildWindowFromPointEx(CursorPos,
		CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT)==*this)
	{
		(void)Fire_Click();
	}
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnMouseDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// get the cursor position
	CPoint CursorPos(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
	// if the cursor is over the form fire the double click event
	if(ChildWindowFromPointEx(CursorPos,
		CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT)==*this)
	{
		(void)Fire_DblClick();
	}
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// get the cursor position
	CPoint CursorPos(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
	// get the state of the mouse buttons
	DWORD Buttons=0;
	Buttons |= (wParam & MK_LBUTTON) ? VK_LBUTTON : 0;
	Buttons |= (wParam & MK_RBUTTON) ? VK_RBUTTON : 0;
	Buttons |= (wParam & MK_MBUTTON) ? VK_MBUTTON : 0;
	// fire the mouse move event
	(void)Fire_MouseMove(
		Buttons,GetShiftKeyModifiers(),CursorPos.x,CursorPos.y);
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// todo : implement this when required
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// handle the repeat count
	for(long l=0; l<LOWORD(lParam); l++)
	{
		// fire the key down event
		(void)Fire_KeyDown(wParam,GetShiftKeyModifiers());
	}
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// handle the repeat count
	for(long l=0; l<LOWORD(lParam); l++)
	{
		// fire the key up event
		(void)Fire_KeyUp(wParam,GetShiftKeyModifiers());
	}
CATCH_ALL
	return 0;
}

LRESULT CViewableForm::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
	// handle the repeat count
	for(long l=0; l<LOWORD(lParam); l++)
	{
		// fire the key press event
		(void)Fire_KeyPress(wParam);
	}
CATCH_ALL
	return 0;
}

// begin standard method implementation block
#define METHOD_BEGIN			\
	if(IsWindow()==FALSE)		\
	{							\
		throw CHResult(E_FAIL);	\
	}

// end standard method implementation block
#define METHOD_END

// begin standard property put implementation block
#define PROPPUT_BEGIN			\
	if(IsWindow()==FALSE)		\
	{							\
		throw CHResult(E_FAIL);	\
	}

// end standard property put implementation block
#define PROPPUT_END

// begin standard property get implementation block
#define PROPGET_BEGIN			\
	if(IsWindow()==FALSE)		\
	{							\
		throw CHResult(E_FAIL);	\
	}

// end standard property get implementation block
#define PROPGET_END

STDMETHODIMP CViewableForm::get_Width(long *pVal)
{
IMP_BEGIN
PROPGET_BEGIN
	// check parameters
	if(pVal==NULL)
	{
		throw CHResult(E_POINTER);
	}
	// get the form width
	CRect ClientRect(0,0,0,0);
	if(GetClientRect(ClientRect)==FALSE)
	{
		throw CHResult(E_FAIL);
	}
	*pVal=ClientRect.Width();
PROPGET_END
IMP_END
	return RetVal;
}

STDMETHODIMP CViewableForm::get_Height(long *pVal)
{
IMP_BEGIN
PROPGET_BEGIN
	// check parameters
	if(pVal==NULL)
	{
		throw CHResult(E_POINTER);
	}
	// get the form height
	CRect ClientRect(0,0,0,0);
	if(GetClientRect(ClientRect)==FALSE)
	{
		throw CHResult(E_FAIL);
	}
	*pVal=ClientRect.Height();
PROPGET_END
IMP_END
	return RetVal;
}

STDMETHODIMP CViewableForm::get_BackColor(OLE_COLOR *pVal)
{
IMP_BEGIN
PROPGET_BEGIN
	// check parameters
	if(pVal==NULL)
	{
		throw CHResult(E_POINTER);
	}
	// get the background color
	*pVal=m_BackColor;
PROPGET_END
IMP_END
	return RetVal;
}

STDMETHODIMP CViewableForm::get_ForeColor(OLE_COLOR *pVal)
{
IMP_BEGIN
PROPGET_BEGIN
	// check parameters
	if(pVal==NULL)
	{
		throw CHResult(E_POINTER);
	}
	// get the foreground color
	*pVal=m_ForeColor;
PROPGET_END
IMP_END
	return RetVal;
}

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)

Share

About the Author

DaveShep
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190518.1 | Last Updated 1 Aug 2009
Article Copyright 2005 by DaveShep
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid