#include "SRWnd.h" using namespace SRFramework; SRWnd::SRWnd() { m_dwStyle = 0; m_hInstance = 0; m_hMenu = 0; m_hWnd = 0; m_pParentWnd = NULL; } SRWnd::~SRWnd(void) { } BOOL SRWnd::Create(const WCString &wcsClassName, const WCString &wcsWindowName, DWORD dwStyle, RECT rect, SRWnd* pParentWnd, HMENU hMenu, HINSTANCE hInstance) { m_pParentWnd = pParentWnd; HWND hParent = m_pParentWnd ? m_pParentWnd->m_hWnd : NULL; m_hMenu = hMenu; m_hInstance = hInstance; m_hWnd = CreateWindow(wcsClassName.w_str(), wcsWindowName.w_str(), dwStyle, rect.left, rect.top, rect.right == CW_USEDEFAULT ? CW_USEDEFAULT : rect.right - rect.left, rect.right == CW_USEDEFAULT ? CW_USEDEFAULT : rect.bottom - rect.top, hParent, m_hMenu, m_hInstance, this); return m_hWnd != NULL; } /* Routes the messages to the appropiate WindowProcedure by unwrapping the lParam * we associated with this window upon creation. */ LRESULT CALLBACK SRWnd::MessageRoute(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { SRWnd* wnd = NULL; if (message == WM_CREATE) { ::SetWindowLong (hwnd, GWL_USERDATA, long((LPCREATESTRUCT(lParam))->lpCreateParams)); } wnd = (SRWnd*) (::GetWindowLong (hwnd, GWL_USERDATA)); if (wnd) return wnd->WndProc(hwnd, message, wParam, lParam); return ::DefWindowProc(hwnd, message, wParam, lParam); } void SRWnd::Show() { ::ShowWindow(m_hWnd, SW_SHOW); ::InvalidateRect(m_hWnd, NULL, TRUE); ::UpdateWindow(m_hWnd); ::SetFocus(m_hWnd); } void SRWnd::Hide() { ::ShowWindow(m_hWnd, SW_HIDE); } BOOL SRWnd::IsVisible() { return ::IsWindowVisible(m_hWnd); } void SRWnd::RefreshWindow() { ::InvalidateRect(m_hWnd, NULL, TRUE); ::UpdateWindow(m_hWnd); } void SRWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint) { ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint); } void SRWnd::MoveWindow(LPCRECT lpRect,BOOL bRepaint) { MoveWindow(lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, bRepaint); } HWND SRWnd::GetWindowHandle() const { return m_hWnd; } VOID SRWnd::SetFocus() { ::SetFocus(m_hWnd); } LRESULT CALLBACK SRWnd::WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { switch(wMsg) { case WM_MOVE: return OnMove(hWnd, wMsg, wParam, lParam); case WM_SIZE: return OnSize(hWnd, wMsg, wParam, lParam); case WM_ACTIVATE: return OnActivate(hWnd, wMsg, wParam, lParam); case WM_SETFOCUS: return OnSetFocus(hWnd, wMsg, wParam, lParam); case WM_KILLFOCUS: return OnKillFocus(hWnd, wMsg, wParam, lParam); //... case WM_PAINT: return OnPaint(hWnd, wMsg, wParam, lParam); case WM_ERASEBKGND: return OnEraseBackground(hWnd, wMsg, wParam, lParam); case WM_SETCURSOR: return OnSetCursor(hWnd, wMsg, wParam, lParam); case WM_NOTIFY: return OnNotify(hWnd, wMsg, wParam, lParam); case WM_HELP: return OnHelp(hWnd, wMsg, wParam, lParam); case WM_KEYDOWN: return OnKeyDown(hWnd, wMsg, wParam, lParam); case WM_KEYUP: return OnKeyUp(hWnd, wMsg, wParam, lParam); case WM_CHAR: return OnChar(hWnd, wMsg, wParam, lParam); case WM_DEADCHAR: return OnDeadChar(hWnd, wMsg, wParam, lParam); case WM_SYSKEYDOWN: return OnSysKeyDown(hWnd, wMsg, wParam, lParam); case WM_SYSKEYUP: return OnSysKeyUp(hWnd, wMsg, wParam, lParam); case WM_SYSCHAR: return OnSysChar(hWnd, wMsg, wParam, lParam); case WM_SYSDEADCHAR: return OnSysDeadChar(hWnd, wMsg, wParam, lParam); //... case WM_INITDIALOG: return OnInitDialog(hWnd, wMsg, wParam, lParam); case WM_COMMAND: return OnCommand(hWnd, wMsg, wParam, lParam); case WM_SYSCOMMAND: return OnSysCommand(hWnd, wMsg, wParam, lParam); case WM_TIMER: return OnTimer(hWnd, wMsg, wParam, lParam); case WM_HSCROLL: return OnHScroll(hWnd, wMsg, wParam, lParam); case WM_VSCROLL: return OnVScroll(hWnd, wMsg, wParam, lParam); case WM_INITMENUPOPUP: return OnInitMenuPopup(hWnd, wMsg, wParam, lParam); case WM_MENUCHAR: return OnMenuChar(hWnd, wMsg, wParam, lParam); case WM_MOUSEMOVE: return OnMouseMove(hWnd, wMsg, wParam, lParam); case WM_LBUTTONDOWN: return OnLButtonDown(hWnd, wMsg, wParam, lParam); case WM_LBUTTONUP: return OnLButtonUp(hWnd, wMsg, wParam, lParam); case WM_LBUTTONDBLCLK: return OnLButtonDblClk(hWnd, wMsg, wParam, lParam); case WM_RBUTTONDOWN: return OnRButtonDown(hWnd, wMsg, wParam, lParam); case WM_RBUTTONUP: return OnRButtonUp(hWnd, wMsg, wParam, lParam); case WM_RBUTTONDBLCLK: return OnRButtonDblClk(hWnd, wMsg, wParam, lParam); case WM_MBUTTONDOWN: return OnMButtonDown(hWnd, wMsg, wParam, lParam); case WM_MBUTTONUP: return OnMButtonUp(hWnd, wMsg, wParam, lParam); case WM_MBUTTONDBLCLK: return OnMButtonDblClk(hWnd, wMsg, wParam, lParam); //... case WM_CUT: return OnCut(hWnd, wMsg, wParam, lParam); case WM_COPY: return OnCopy(hWnd, wMsg, wParam, lParam); case WM_PASTE: return OnPaste(hWnd, wMsg, wParam, lParam); case WM_CLEAR: return OnClear(hWnd, wMsg, wParam, lParam); case WM_UNDO: return OnUndo(hWnd, wMsg, wParam, lParam); //... case WM_HIBERNATE: return OnHibernate(hWnd, wMsg, wParam, lParam); //... case WM_CREATE: return OnCreate(hWnd, wMsg, wParam, lParam); case WM_DESTROY: return OnDestroy(hWnd, wMsg, wParam, lParam); case WM_CLOSE: return OnClose(hWnd, wMsg, wParam, lParam); case WM_QUIT: return OnQuit(hWnd, wMsg, wParam, lParam); default: return DefWindowProc (hWnd, wMsg, wParam, lParam); } return FALSE; // Never happens. } RECT SRWnd::GetBounds() { RECT clientRect; GetClientRect(m_hWnd, &clientRect); return clientRect; }