[sword-svn] r108 - trunk/src/SwordReader_GUI/SRFramework
dtrotzjr at www.crosswire.org
dtrotzjr at www.crosswire.org
Sun Mar 30 19:12:42 MST 2008
Author: dtrotzjr
Date: 2008-03-30 19:12:41 -0700 (Sun, 30 Mar 2008)
New Revision: 108
Modified:
trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp
trunk/src/SwordReader_GUI/SRFramework/SRWnd.h
Log:
Some SRWnd message handling.
Modified: trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp 2008-03-30 23:06:18 UTC (rev 107)
+++ trunk/src/SwordReader_GUI/SRFramework/SRWnd.cpp 2008-03-31 02:12:41 UTC (rev 108)
@@ -1,8 +1,80 @@
#include "SRWnd.h"
using namespace SRFramework;
+/* Idea taken from examples in Programming Windows CE - Douglas Boling */
+struct decodeUINT {
+ UINT Code;
+ LRESULT (CALLBACK SRWnd:: *Fxn)(HWND, UINT, WPARAM, LPARAM);
+};
+struct decodeCMD {
+ UINT Code;
+ LRESULT (SRWnd::* Fxn)(HWND, WORD, HWND, WORD);
+};
+
+// Message dispatch table for MainWindowProc
+decodeUINT MainMessages[] = {
+ // As defined in winuser.h
+ WM_MOVE, &SRWnd::OnMove,
+ WM_SIZE, &SRWnd::OnSize,
+ WM_ACTIVATE, &SRWnd::OnActivate,
+ WM_SETFOCUS, &SRWnd::OnSetFocus,
+ WM_KILLFOCUS, &SRWnd::OnKillFocus,
+ WM_SETREDRAW, &SRWnd::OnSetRedraw,
+ WM_SETTEXT, &SRWnd::OnSetText,
+ WM_GETTEXT, &SRWnd::OnGetText,
+ WM_GETTEXTLENGTH, &SRWnd::OnGetTextLength,
+ WM_PAINT, &SRWnd::OnPaint,
+ WM_ERASEBKGND, &SRWnd::OnEraseBackground,
+ WM_SETCURSOR, &SRWnd::OnSetCursor,
+ WM_NOTIFY, &SRWnd::OnNotify,
+ WM_HELP, &SRWnd::OnHelp,
+ WM_KEYFIRST, &SRWnd::OnKeyFirst,
+ WM_KEYDOWN, &SRWnd::OnKeyDown,
+ WM_KEYUP, &SRWnd::OnKeyUp,
+ WM_CHAR, &SRWnd::OnChar,
+ WM_DEADCHAR, &SRWnd::OnDeadChar,
+ WM_SYSKEYDOWN, &SRWnd::OnSysKeyDown,
+ WM_SYSKEYUP, &SRWnd::OnSysKeyUp,
+ WM_SYSCHAR, &SRWnd::OnSysChar,
+ WM_SYSDEADCHAR, &SRWnd::OnSysDeadChar,
+ //...
+ WM_INITDIALOG, &SRWnd::OnInitDialog,
+ WM_COMMAND, &SRWnd::OnCommand,
+ WM_SYSCOMMAND, &SRWnd::OnSysCommand,
+ WM_TIMER, &SRWnd::OnTimer,
+ WM_CLOSE, &SRWnd::OnClose,
+ WM_HSCROLL, &SRWnd::OnHScroll,
+ WM_VSCROLL, &SRWnd::OnVScroll,
+ WM_INITMENUPOPUP, &SRWnd::OnInitMenuPopup,
+ WM_MENUCHAR, &SRWnd::OnMenuChar,
+ WM_MOUSEMOVE, &SRWnd::OnMouseMove,
+ WM_LBUTTONDOWN, &SRWnd::OnLButtonDown,
+ WM_LBUTTONUP, &SRWnd::OnLButtonUp,
+ WM_LBUTTONDBLCLK, &SRWnd::OnLButtonDblClk,
+ WM_RBUTTONDOWN, &SRWnd::OnRButtonDown,
+ WM_RBUTTONUP, &SRWnd::OnRButtonUp,
+ WM_RBUTTONDBLCLK, &SRWnd::OnRButtonDblClk,
+ WM_MBUTTONDOWN, &SRWnd::OnMButtonDown,
+ WM_MBUTTONUP, &SRWnd::OnMButtonUp,
+ WM_MBUTTONDBLCLK, &SRWnd::OnMButtonDblClk,
+ //...
+ WM_CUT, &SRWnd::OnCut,
+ WM_COPY, &SRWnd::OnCopy,
+ WM_PASTE, &SRWnd::OnPaste,
+ WM_CLEAR, &SRWnd::OnClear,
+ WM_UNDO, &SRWnd::OnUndo,
+ //...
+ WM_HIBERNATE, &SRWnd::OnHibernate,
+ //...
+ WM_CREATE, &SRWnd::OnCreate,
+ WM_DESTROY, &SRWnd::OnDestroy,
+ WM_CLOSE, &SRWnd::OnClose,
+ WM_QUIT, &SRWnd::OnQuit
+};
+
SRWnd::SRWnd()
{
+
}
SRWnd::~SRWnd(void)
@@ -42,7 +114,7 @@
wnd = (SRWnd*) (::GetWindowLong (hwnd, GWL_USERDATA));
if (wnd)
- return wnd->WndProcBText(hwnd, message, wParam, lParam);
+ return wnd->WndProc(hwnd, message, wParam, lParam);
return ::DefWindowProc(hwnd, message, wParam, lParam);
}
@@ -70,4 +142,19 @@
HWND SRWnd::GetWindowHandle() const
{
return m_hWnd;
+}
+
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
+{
+ INT i;
+ //
+ // Search message list to see if we need to handle this
+ // message. If in list, call procedure.
+ //
+ for (i = 0; i < dim(MainMessages); i++) {
+ if (wMsg == MainMessages[i].Code)
+ return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
+ }
+ return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
\ No newline at end of file
Modified: trunk/src/SwordReader_GUI/SRFramework/SRWnd.h
===================================================================
--- trunk/src/SwordReader_GUI/SRFramework/SRWnd.h 2008-03-30 23:06:18 UTC (rev 107)
+++ trunk/src/SwordReader_GUI/SRFramework/SRWnd.h 2008-03-31 02:12:41 UTC (rev 108)
@@ -2,12 +2,17 @@
#include <windows.h>
#include "WCString.h"
+// Returns number of elements
+#define dim(x) (sizeof(x) / sizeof(x[0]))
+
namespace SRFramework
{
+
class SRWnd
{
public:
+
SRWnd();
virtual ~SRWnd(void);
virtual BOOL Register() = 0;
@@ -23,7 +28,7 @@
of this parameter depend on the value of the message
parameter.
*/
- static LRESULT CALLBACK MessageRoute(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+ static LRESULT CALLBACK MessageRoute(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
//! The expected WinProc callback function.
/*! Handles any messages sent to this window.
@param hwnd Handle to the window.
@@ -35,11 +40,77 @@
of this parameter depend on the value of the message
parameter.
*/
- virtual LRESULT CALLBACK WndProcBText(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) = 0;
- void Show();
- void Hide();
- void MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE);
- void MoveWindow(LPCRECT lpRect,BOOL bRepaint = TRUE);
+ virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
+
+ virtual void Show();
+ virtual void Hide();
+ virtual void MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE);
+ virtual void MoveWindow(LPCRECT lpRect,BOOL bRepaint = TRUE);
+
+ virtual LRESULT CALLBACK OnMove(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSize(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnActivate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSetFocus(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnKillFocus(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSetRedraw(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSetText(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnGetText(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnGetTextLength(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnPaint(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnEraseBackground(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSetCursor(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnNotify(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnHelp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnKeyFirst(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnKeyDown(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnKeyUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnChar(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnDeadChar(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSysKeyDown(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSysKeyUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSysChar(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSysDeadChar(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnInitDialog(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnSysCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnTimer(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnHScroll(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnVScroll(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnInitMenuPopup(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnMenuChar(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnMouseMove(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnLButtonDown(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnLButtonUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnLButtonDblClk(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnRButtonDown(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnRButtonUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnRButtonDblClk(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnMButtonDown(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnMButtonUp(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnMButtonDblClk(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnCut(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnCopy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnPaste(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnClear(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnUndo(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnHibernate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnCreate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnDestroy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnClose(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual LRESULT CALLBACK OnQuit(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+
+ /*
+ virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnLButtonDown(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnKeyDown(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnCommand(UINT wMsg, WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnPaint(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnCreate(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnDestroy(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnActivate(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnSettingChange(WPARAM wParam, LPARAM lParam) {}
+ virtual BOOL OnSize(WPARAM wParam, LPARAM lParam) {}
+ */
protected:
HWND m_hWnd;
// These typically are set by the subclass' constructor.
@@ -59,7 +130,10 @@
HMENU hMenu,
HINSTANCE hInstance);
HWND GetWindowHandle() const;
+
- };
-}
\ No newline at end of file
+ }; // END OF SRWnd Class...
+
+}
+
More information about the sword-cvs
mailing list