#ifndef __CeModule_h__
#define __CeModule_h__
#include "CeLib.h"
class CeProcess: public CeWaitableHandle
{
private:
DWORD m_dwProcessId;
DWORD GetId() const
{ return m_dwProcessId; }
};
class CeModule
{
protected:
HINSTANCE m_hInst;
public:
// Initialization
CeModule()
{ m_hInst = NULL; }
void Attach(HINSTANCE hInst)
{ ASSERT(NULL == m_hInst); m_hInst = hInst; }
HINSTANCE Detach()
{ ASSERT(NULL != m_hInst); HINSTANCE h = m_hInst; m_hInst = NULL; return h; }
// Resource mnethods
LPCTSTR LoadString(UINT uID, int* pLen=NULL)
{
// Windows CE: If lpBuffer is set to NULL, the return value is a pointer to
// the requested string. The caller should cast the return value to an LPCTSTR.
// This pointer points directly to the resource, so the string is read-only.
// The length of the string, not including any NULL terminator, can be found
// in the word preceding the string.
LPCTSTR lpsz = (LPCTSTR) ::LoadString(m_hInst, uID, NULL, 0);
if (pLen && lpsz)
*pLen = *(((WORD*)lpsz) - 1);
return lpsz;
}
int LoadString(UINT uID, LPTSTR lpBuffer, int nBufferMax)
{ return ::LoadString(m_hInst, uID, lpBuffer, nBufferMax); }
HBITMAP LoadBitmap(LPCTSTR lpszRes)
{ return (HBITMAP) ::LoadImage(m_hInst, lpszRes, IMAGE_BITMAP, 0, 0, 0); }
HBITMAP LoadBitmap(UINT uRes)
{ return LoadBitmap(MAKEINTRESOURCE(uRes)); }
HICON LoadIcon(LPCTSTR lpszRes, int cxDesired = 0, int cyDesired = 0)
{ return (HICON) ::LoadImage(m_hInst, lpszRes, IMAGE_ICON, cxDesired, cyDesired, 0); }
HICON LoadSmallIcon(UINT uRes)
{ return LoadIcon(MAKEINTRESOURCE(uRes), 16, 16); }
HICON LoadLargeIcon(UINT uRes)
{ return LoadIcon(MAKEINTRESOURCE(uRes), 32, 32); }
};
class CeAppModule: public CeModule // , public CeProcess
{
private:
static CeAppModule* m_pApp;
HWND m_hWndMain;
HACCEL m_hAccel;
public:
CeAppModule()
{ m_hWndMain = NULL; m_hAccel = NULL; CeAppModule::m_pApp = this; }
static CeAppModule* CeGetApp()
{ return CeAppModule::m_pApp; }
BOOL LoadAccelerators( LPCTSTR lpTableName )
{ return NULL != (m_hAccel = ::LoadAccelerators( m_hInst, lpTableName )); }
BOOL LoadAccelerators( UINT uRes )
{ return LoadAccelerators(MAKEINTRESOURCE(uRes)); }
HWND SetMainWindow(HWND hWnd)
{ HWND hWndOld = m_hWndMain; m_hWndMain = hWnd; return hWndOld; }
HWND GetMainWindow() const
{ return m_hWndMain; }
virtual int OnRun();
virtual int OnInitInstance(HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
virtual int OnExitInstance();
};
#ifdef CEAPP
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
CeAppModule* m_pApp = CeAppModule::CeGetApp();
if (m_pApp != NULL)
{
m_pApp->Attach(hInstance);
if (0 != m_pApp->OnInitInstance(hPrevInstance, lpCmdLine, nCmdShow))
{
m_pApp->Detach();
return 1;
}
m_pApp->OnRun();
int nRet = m_pApp->OnExitInstance();
m_pApp->Detach();
return nRet;
}
return 0;
}
#endif
/*
Under construction....
class CeDLLModule: public CeModule
{
static CeMap<HANDLE,>
publc:
virtual void OnProcessAttach();
{}
virtual void OnProcessDetach();
{}
virtual void OnThreadAttach();
{}
virtual void OnThreadDetach();
{}
};
#ifdef CEDLL
int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
CeDLLModule::
if (dwReason == DLL_PROCESS_ATTACH)
{
Attach(hInstance);
// Extension DLL one-time initialization
CeDLLModule::OnProcessAttach();
}
else if (dwReason == DLL_PROCESS_DETACH)
{
// Extension DLL per-process termination
CeDLLModule::OnProcessDetach();
Detach();
}
else if (dwReason == DLL_THREAD_ATTACH)
{
CeDLLModule::OnThreadAttach();
}
else if (dwReason == DLL_THREAD_DETACH)
{
CeDLLModule::OnThreadDetach();
}
return 1; // ok
}
#endif
*/
#endif //__CeModule_h__