Hi,
I'm basically done testing and I would like some comments on my new baseclass. The current feature set is:
New Base class : GDApplication!
Features:
- Tested and approved for Stationary PCs, Pocket PCs and Smartphones.
- Support for full screen and windowed DirectDraw modes on Stationary PCs.
- Full support for stylus (down, up, move, doubleclick) and key input (down, up).
- Support for easy to use, dynamic rotation of the display with no performance loss.
- Flexible and easy to use configuration system.
- Multithreaded main loop for time critical operations.
- Full Minimize/Restore functionality with synchronized pause of main loop.
- Hides all notifications in the background.
- FPS lock (the application will always run at constant FPS independent of CPU speed)
- Full source code included
You begin by subclassing CGDApplication, the interface looks like:
The configuration struct looks like this:
Typically you kick off the application from WinMain:
The entire specification of CGDApplication looks like:
So.. What do you think. Anything I have missed? I plan to release GapiDraw 1.03 this weekend (have some more checking to do on the RLE decoding), and would like the base class to be as feature complete as possible.
/Johan
I'm basically done testing and I would like some comments on my new baseclass. The current feature set is:
New Base class : GDApplication!
Features:
- Tested and approved for Stationary PCs, Pocket PCs and Smartphones.
- Support for full screen and windowed DirectDraw modes on Stationary PCs.
- Full support for stylus (down, up, move, doubleclick) and key input (down, up).
- Support for easy to use, dynamic rotation of the display with no performance loss.
- Flexible and easy to use configuration system.
- Multithreaded main loop for time critical operations.
- Full Minimize/Restore functionality with synchronized pause of main loop.
- Hides all notifications in the background.
- FPS lock (the application will always run at constant FPS independent of CPU speed)
- Full source code included
You begin by subclassing CGDApplication, the interface looks like:
- Code:
//-----------------------------------------------------------------------------
// Name: class CMyGDApplication
// Desc: Main class to run this application. Most functionality is inherited
// from the CGDApplication base class.
//-----------------------------------------------------------------------------
class CMyGDApplication : public CGDApplication
{
// Construction
public:
CMyGDApplication(const GDAPPCONFIG& config);
// Attributes
protected:
// Operations
protected:
// Implementation
public:
virtual HRESULT InitInstance();
virtual HRESULT ExitInstance();
virtual HRESULT CreateSurfaces(CGapiDisplay& display, HINSTANCE hInstance);
virtual HRESULT ProcessNextFrame(CGapiSurface& backbuffer, BOOL bFrametimeOverflow);
virtual HRESULT KeyDown(DWORD dwKey, GDKEYLIST& keylist);
virtual HRESULT KeyUp(DWORD dwKey, GDKEYLIST& keylist);
virtual HRESULT StylusDown(POINT p);
virtual HRESULT StylusUp(POINT p);
virtual HRESULT StylusDblClk(POINT p);
virtual HRESULT StylusMove(POINT p);
virtual ~CMyGDApplication();
};
The configuration struct looks like this:
- Code:
typedef struct _GDAPPCONFIG
{
HINSTANCE hInstance; // Application instance [ mandatory ]
const TCHAR* pAppTitle; // Application title [ mandatory ]
DWORD dwTargetFPS; // Target number of frame updates / second [ mandatory ]
DWORD dwDisplayFlags; // Flags sent to OpenDisplay [ optional ]
DWORD dwDisplayMode; // Flags sent to SetDisplayMode [ optional ]
DWORD dwWindowIcon; // (Stationary PCs) Window icon [ optional ]
DWORD dwWindowBorder; // (Stationary PCs) Window border style [ optional ]
} GDAPPCONFIG;
Typically you kick off the application from WinMain:
- Code:
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Exit the loop by calling Shutdown().
//-----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR pCmdLine, int nCmdShow)
{
GDAPPCONFIG config;
ZeroMemory(&config, sizeof(GDAPPCONFIG));
config.hInstance = hInst;
config.pAppTitle = TEXT("My App");
config.dwWindowIcon = IDI_APP;
config.dwDisplayFlags = GDOPENDISPLAY_SCALEX2;
config.dwDisplayMode = GDDISPMODE_LANDSCAPE1;
config.dwTargetFPS = 30;
// Create the application
CMyGDApplication myapp(config);
// Start main loop
return myapp.Run();
// CGDApplication will now call:
// - InitInstance()
// - CreateSurfaces() <- will also be called if display is rotated
// - ProcessNextFrame() <- until Shutdown() is called
// - ExitInstance()
}
The entire specification of CGDApplication looks like:
- Code:
class CGDApplication
{
// Construction
public:
CGDApplication(const GDAPPCONFIG& config);
// Attributes
private:
enum
{
WM_USER_MINIMIZE = WM_USER + 1
};
HWND m_hWnd;
BOOL m_bActiveWindow;
BOOL m_bDisplayModeShouldChange;
BOOL m_bWindowShouldMinimize;
HANDLE m_hThread;
BOOL m_bThreadShouldExit;
BOOL m_bThreadShouldSuspend;
HANDLE m_hThreadIsFinished;
HANDLE m_hThreadIsSuspended;
TCHAR m_szWndClass[MAX_PATH];
TCHAR m_szError[MAX_PATH];
CGapiDisplay m_display;
CGapiSurface m_backbuffer;
CGapiInput m_input;
protected:
GDAPPCONFIG m_config;
CGapiTimer m_timer;
// Operations
public:
HRESULT Run();
HRESULT Shutdown();
HRESULT Minimize();
HRESULT SetDisplayMode(DWORD dwDisplayMode);
HRESULT SetError(const TCHAR* pErrorDesc, HRESULT hr = 0);
protected:
virtual HRESULT InitInstance() { return S_OK; }
virtual HRESULT ExitInstance() { return S_OK; }
virtual HRESULT CreateSurfaces(CGapiDisplay& display, HINSTANCE hInstance) { return S_OK; }
virtual HRESULT ProcessNextFrame(CGapiSurface& backbuffer, BOOL bFrametimeOverflow) { return S_OK; }
virtual HRESULT KeyDown(DWORD dwKey, GDKEYLIST& keylist) { return S_OK; }
virtual HRESULT KeyUp(DWORD dwKey, GDKEYLIST& keylist) { return S_OK; }
virtual HRESULT StylusDown(POINT p) { return S_OK; }
virtual HRESULT StylusUp(POINT p) { return S_OK; }
virtual HRESULT StylusDblClk(POINT p) { return S_OK; }
virtual HRESULT StylusMove(POINT p) { return S_OK; }
private:
BOOL IsFullscreen();
HRESULT CreateMainWindow();
HRESULT DestroyMainWindow();
HRESULT OpenDisplay();
HRESULT CloseDisplay();
static HRESULT ToggleFullscreen(HWND hWnd, BOOL bFullscreen);
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static unsigned __stdcall ThreadFunc(LPVOID pParam);
// Implementation
public:
virtual ~CGDApplication();
};
So.. What do you think. Anything I have missed? I plan to release GapiDraw 1.03 this weekend (have some more checking to do on the RLE decoding), and would like the base class to be as feature complete as possible.
/Johan