Click here to Skip to main content
15,893,814 members
Articles / Mobile Apps

The StateWizard VC++ Add-in and Engine with Source Code

Rate me:
Please Sign up or sign in to vote.
4.73/5 (24 votes)
26 Mar 2009CPOL12 min read 190.8K   2.8K   132  
A cross-platform state-oriented application framework and a ClassWizard-like round-trip UML dynamic modeling/development tool that runs in popular IDEs. Aims at providing concurrent, distributed, and real-time application development tools for Win32/Linux
/* =============================================================================
 * This notice must be untouched at all times.
 *
 * Copyright  IntelliWizard Inc. 
 * All rights reserved.
 * LICENSE: LGPL
 * Web: http://www.intelliwizard.com
 * eMail: info@intelliwizard.com
 * We provide technical support for non-commercial or commercial UML StateWizard users.
 * -----------------------------------------------------------------------------
*/
// EgnSubclassWnd.cpp: implementation of the CEgnSubclassWnd class.
//
//////////////////////////////////////////////////////////////////////

#include "afxwin.h"
#include "EgnSubclassWnd.h"
#include "ThreadManager.h"

///////////////////////////////////////////////////////////////////////
extern SME_GET_THREAD_CONTEXT_PROC g_pfnGetThreadContext;


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEgnSubclassWnd::CEgnSubclassWnd()
{

}

CEgnSubclassWnd::~CEgnSubclassWnd()
{

}


LRESULT CEgnSubclassWnd::WindowProc(HWND hwnd, UINT msg, WPARAM wp,LPARAM lp)
{
	struct SME_EVENT_T* pExtEvent=NULL;
	MSG WinMsg;
	WinMsg.hwnd = hwnd;
	WinMsg.message =msg;
	WinMsg.wParam = wp;
	WinMsg.lParam = lp;

	LRESULT ret = 0;
	switch (msg)
	{
	case WM_EXT_EVENT_ID:
		// An external event is triggered. Handle external event and trigger state transitions.
		OnExtEvent(WinMsg);
		break;

	default:
		break;
	}

	ret = CSubclassWnd::WindowProc(hwnd,msg,wp,lp);
	return ret;
}

/*******************************************************************************************
* DESCRIPTION:  Just like SmeRun(), this function dispatches external event to applications. 
* INPUT:  
* OUTPUT: None.
* NOTE: 
Engine has to check internal event first, because SmeActivateApp() may trigger some internal events.

Case:
	SmeActivateApp(&SME_GET_APP_VAR(PowerUpDown),NULL);
	SmeRun();
   
*******************************************************************************************/
struct SME_EVENT_T * GetEventFromQueue();
BOOL DispatchInternalEvents(SME_THREAD_CONTEXT_PT pThreadContext);
BOOL DispatchEventToApps(SME_THREAD_CONTEXT_PT pThreadContext,SME_EVENT_T *pEvent);

LRESULT CEgnSubclassWnd::OnExtEvent(MSG& WinMsg)
{
	SME_APP_T *pApp;
	SME_THREAD_CONTEXT_PT pThreadContext=NULL;
	SME_EVENT_T *pEvent=TranslateEvent(&WinMsg);

	if (pEvent==NULL)
		return 0;

	if (g_pfnGetThreadContext)
		pThreadContext = (*g_pfnGetThreadContext)();
	if (!pThreadContext) return 0;

	pApp = pThreadContext->pActAppHdr;

	/* Call hook function on an external event coming. */
	if (pThreadContext->fnOnEventComeHook)
		(*pThreadContext->fnOnEventComeHook)(SME_EVENT_ORIGIN_EXTERNAL, pEvent);

	/* Dispatch it to active applications.*/
	DispatchEventToApps(pThreadContext, pEvent);

	DispatchInternalEvents(pThreadContext);

	/* Free external event if necessary. */
	if (pThreadContext->fnDelExtEvent && pEvent)
	{
		(*pThreadContext->fnDelExtEvent)(pEvent);
		// Engine should delete this event, because translation of external event will create an internal event. 
		SmeDeleteEvent(pEvent); 
	}
	
	return 0;
}

CEgnSubclassWnd EngSubclassWnd;

BOOL MfcHookWnd(HWND hWndHooked)
{
	if (hWndHooked==NULL || !IsWindow(hWndHooked)) return FALSE;

	CWnd *pWnd = CWnd::FromHandle(hWndHooked);
	return EngSubclassWnd.HookWindow(pWnd);	
}

BOOL MfcUnhookWnd(HWND hWndHooked)
{
	if (hWndHooked==NULL || !IsWindow(hWndHooked)) return FALSE;

	CWnd *pWnd = CWnd::FromHandle(hWndHooked);
	return EngSubclassWnd.HookWindow(pWnd);	
}

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
Software Developer (Senior)
United States United States
Alex "Question is more important than the answer."

Comments and Discussions