#ifndef __CEWnd_h__
#define __CEWnd_h__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "CeDebug.h"
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#ifndef UNUSED_ALWAYS
#define UNUSED_ALWAYS(var)
#endif
#ifndef GetFirstChild
#define GetFirstChild(hWnd) GetWindow(hWnd, GW_CHILD)
#endif
typedef struct tagCEMSG {
HWND hwnd;
UINT uMsg;
WPARAM wParam;
LPARAM lParam;
} CEMSG;
#ifdef _WIN32_WCE
#define _FIRST_WM_MESSAGE WM_CREATE
#define _LAST_WM_MESSAGE WM_DESTROY
#else
#define _FIRST_WM_MESSAGE WM_NCCREATE
#define _LAST_WM_MESSAGE WM_NCDESTROY
#endif
#define RectWidth(rc) (rc.right - rc.left)
#define RectHeight(rc) (rc.bottom - rc.top)
#define RectSize(rc, sz) (sz.cx = (rc.right - rc.left), sz.cy = (rc.bottom - rc.top))
#define WC_CEGENERICWNDCLASS _T("CeWnd:GENERIC")
///////////////////////////////////////////////////////////////////////////////
//
// Raw window class, base for ALL window classes, provides generic HWND wrapper
//
///////////////////////////////////////////////////////////////////////////////
class CeBaseWnd
{
public:
HWND m_hWnd; // the only member required
CeBaseWnd() { m_hWnd = NULL; }
virtual ~CeBaseWnd() { if (IsWindow()) DestroyWindow(); }
// hookup the window
BOOL Attach(HWND hWndNew);
HWND Detach();
BOOL DestroyWindow();
// Attributes
operator HWND() const { return m_hWnd; }
DWORD GetStyle() const;
DWORD GetExStyle() const;
// these were left out by accident, they work, so use them
#ifndef GWL_HINSTANCE
# define GWL_HINSTANCE (-6)
#endif
#ifndef GWL_HWNDPARENT
# define GWL_HWNDPARENT (-8)
#endif
LONG GetWindowLong(int nIndex) const;
LONG SetWindowLong(int nIndex, LONG dwNewLong);
static BOOL ModifyStyle(HWND hWnd, DWORD dwRemove, DWORD dwAdd, UINT nFlags);
BOOL ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags);
// Message Functions
LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
BOOL PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
BOOL SendNotifyMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
// support for C style macros
static LRESULT SendMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// Window Text Functions
BOOL SetWindowText(LPCTSTR lpszString);
int GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const;
int GetWindowTextLength() const;
// Font Functions
void SetFont(HFONT hFont, BOOL bRedraw);
HFONT GetFont() const;
// Menu Functions (non-child windows only)
BOOL DrawMenuBar();
BOOL HiliteMenuItem(HMENU hMenu, UINT uItemHilite, UINT uHilite);
// Window Size and Position Functions
BOOL IsIconic() const;
BOOL IsZoomed() const;
BOOL MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE);
BOOL MoveWindow(LPCRECT lpRect, BOOL bRepaint = TRUE);
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags);
BOOL SetWindowPos(HWND hWndInsertAfter, LPCRECT lpRect, UINT nFlags);
UINT ArrangeIconicWindows();
BOOL BringWindowToTop();
BOOL GetWindowRect(LPRECT lpRect) const;
BOOL GetClientRect(LPRECT lpRect) const;
BOOL CenterWindow(HWND hWndCenter = NULL);
#ifndef _WIN32_WCE
// methods supported by 95/98/NT but NOT CE
WORD GetWindowWord(int nIndex) const;
WORD SetWindowWord(int nIndex, WORD wNewWord);
HMENU GetMenu() const;
BOOL SetMenu(HMENU hMenu);
HMENU GetSystemMenu(BOOL bRevert) const;
BOOL GetWindowPlacement(WINDOWPLACEMENT FAR* lpwndpl) const;
BOOL SetWindowPlacement(const WINDOWPLACEMENT FAR* lpwndpl);
BOOL ScrollWindow(int xAmount, int yAmount, LPCRECT lpRect = NULL, LPCRECT lpClipRect = NULL);
BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL, HRGN hRgnUpdate = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
BOOL FlashWindow(BOOL bInvert);
HWND GetTopWindow() const;
BOOL ValidateRgn(HRGN hRgn);
BOOL ShowOwnedPopups(BOOL bShow = TRUE);
HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags);
BOOL WinHelp(LPCTSTR lpszHelp, UINT nCmd = HELP_CONTEXT, DWORD dwData = 0);
BOOL EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH);
#endif
// Implemented by WinCE
BOOL ShowScrollBar(int nBar, BOOL bShow);
int GetScrollPos(int nBar) const;
BOOL GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const;
// Coordinate Mapping Functions
BOOL ClientToScreen(LPPOINT lpPoint) const;
BOOL ClientToScreen(LPRECT lpRect) const;
BOOL ScreenToClient(LPPOINT lpPoint) const;
BOOL ScreenToClient(LPRECT lpRect) const;
int MapWindowPoints(HWND hWndTo, LPPOINT lpPoint, UINT nCount) const;
int MapWindowPoints(HWND hWndTo, LPRECT lpRect) const;
// Update and Painting Functions
HDC BeginPaint(LPPAINTSTRUCT lpPaint);
void EndPaint(LPPAINTSTRUCT lpPaint);
HDC GetDC();
HDC GetWindowDC();
int ReleaseDC(HDC hDC);
BOOL UpdateWindow();
void SetRedraw(BOOL bRedraw = TRUE);
BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase = FALSE);
int GetUpdateRgn(HRGN hRgn, BOOL bErase = FALSE);
BOOL Invalidate(BOOL bErase = TRUE);
BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE);
BOOL ValidateRect(LPCRECT lpRect);
void InvalidateRgn(HRGN hRgn, BOOL bErase = TRUE);
BOOL ShowWindow(int nCmdShow);
BOOL IsWindowVisible() const;
BOOL LockWindowUpdate(BOOL bLock = TRUE);
// Timer Functions
UINT SetTimer(UINT nIDEvent, UINT nElapse);
BOOL KillTimer(UINT nIDEvent);
// Window State Functions
BOOL IsWindowEnabled() const;
BOOL EnableWindow(BOOL bEnable = TRUE);
HWND SetActiveWindow();
HWND SetCapture();
HWND SetFocus();
// Dialog-Box Item Functions
BOOL CheckDlgButton(int nIDButton, UINT nCheck);
BOOL CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton);
UINT GetDlgItemInt(int nID, BOOL* lpTrans = NULL, BOOL bSigned = TRUE) const;
UINT GetDlgItemText(int nID, LPTSTR lpStr, int nMaxCount) const;
HWND GetNextDlgGroupItem(HWND hWndCtl, BOOL bPrevious = FALSE) const;
HWND GetNextDlgTabItem(HWND hWndCtl, BOOL bPrevious = FALSE) const;
UINT IsDlgButtonChecked(int nIDButton) const;
LRESULT SendDlgItemMessage(int nID, UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
BOOL SetDlgItemInt(int nID, UINT nValue, BOOL bSigned = TRUE);
BOOL SetDlgItemText(int nID, LPCTSTR lpszString);
// Scrolling Functions
int ScrollWindowEx(int dx, int dy, LPCRECT lpRectScroll, LPCRECT lpRectClip, HRGN hRgnUpdate, LPRECT lpRectUpdate, UINT uFlags);
int ScrollWindowEx(int dx, int dy, UINT uFlags, LPCRECT lpRectScroll = NULL, LPCRECT lpRectClip = NULL, HRGN hRgnUpdate = NULL, LPRECT lpRectUpdate = NULL);
int SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE);
BOOL SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE);
// Window Access Functions
HWND ChildWindowFromPoint(POINT point) const;
HWND ChildWindowFromPointEx(POINT point, UINT uFlags) const;
HWND GetWindow(UINT nCmd) const;
HWND GetLastActivePopup() const;
BOOL IsChild(HWND hWnd) const;
HWND GetParent() const;
HWND SetParent(HWND hWndNewParent);
HWND GetTopLevelWindow() const;
static HWND GetTopLevelWindow(HWND hWnd);
// Window Tree Access
int GetDlgCtrlID() const;
int SetDlgCtrlID(int nID);
HWND GetDlgItem(int nID) const;
// Alert Functions
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption = _T(""), UINT nType = MB_OK);
// Clipboard Functions
BOOL ChangeClipboardChain(HWND hWndNewNext);
HWND SetClipboardViewer();
BOOL OpenClipboard();
// Caret Functions
BOOL CreateCaret(HBITMAP hBitmap);
BOOL CreateSolidCaret(int nWidth, int nHeight);
BOOL CreateGrayCaret(int nWidth, int nHeight);
BOOL HideCaret();
BOOL ShowCaret();
#ifdef _INC_SHELLAPI
// Drag-Drop Functions
void DragAcceptFiles(BOOL bAccept = TRUE);
#endif
// Icon Functions
HICON SetIcon(HICON hIcon, BOOL bBigIcon = TRUE);
HICON GetIcon(BOOL bBigIcon = TRUE) const;
// Help Functions
BOOL SetWindowContextHelpId(DWORD dwContextHelpId);
DWORD GetWindowContextHelpId() const;
// Hot Key Functions
int SetHotKey(WORD wVirtualKeyCode, WORD wModifiers);
DWORD GetHotKey() const;
// Misc. Operations
BOOL GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const;
BOOL SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE);
BOOL IsDialogMessage(LPMSG lpMsg);
void NextDlgCtrl() const;
void PrevDlgCtrl() const;
void GotoDlgCtrl(HWND hWndCtrl) const;
int GetWindowRgn(HRGN hRgn) const;
int SetWindowRgn(HRGN hRgn, BOOL bRedraw = FALSE);
DWORD GetWindowThreadID();
DWORD GetWindowProcessID();
BOOL IsWindow() const;
BOOL IsWindowUnicode() const;
BOOL IsParentDialog() const;
BOOL ShowWindowAsync(int nCmdShow);
};
//
// The HWND wrapper class for working more easily with window handles and
//
class __declspec(novtable) CeMsgWnd
{
public:
WNDPROC m_lpfnOldWndProc;
CEMSG m_cemsg;
CeMsgWnd() { m_lpfnOldWndProc = NULL; }
virtual ~CeMsgWnd() {}
// Default handling of the message procedure
virtual LRESULT Default();
virtual LRESULT ProcessMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
// Window message virtual functions
virtual void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags, bool& bHandled );
virtual void OnClose( bool& bHandled );
virtual int OnCreate( LPCREATESTRUCT lpCS, bool& bHandled );
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam, bool& bHandled);
virtual LRESULT OnNotify(int nCtrlId, LPNMHDR pNMH, bool& bHandled);
virtual void OnDestroy(bool& bHandled);
virtual void OnEnable( BOOL bEnable, bool& bHandled );
virtual BOOL OnEraseBkgnd( HDC hDC, bool& bHandled );
virtual void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags, bool& bHandled );
virtual void OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags, bool& bHandled );
virtual void OnLButtonDblClk( UINT nFlags, POINT point, bool& bHandled );
virtual void OnLButtonDown( UINT nFlags, POINT point, bool& bHandled );
virtual void OnLButtonUp( UINT nFlags, POINT point, bool& bHandled );
virtual void OnMouseMove( UINT nFlags, POINT point, bool& bHandled );
virtual void OnMove( int x, int y, bool& bHandled );
virtual void OnPaint( bool& bHandled );
virtual void OnShowWindow( BOOL bShow, UINT nStatus, bool& bHandled );
virtual void OnSize( UINT nType, int cx, int cy, bool& bHandled );
virtual void OnTimer( UINT nTimer, bool& bHandled );
virtual void OnSettingChange( WORD wFlag, LPCTSTR pszSection, bool& bHandled );
virtual LRESULT OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
#ifndef _WIN32_WCE
virtual BOOL OnQueryEndSession( UINT nSource, BOOL fLogOff, bool& bHandled );
virtual void OnEndSession(BOOL fEndSession, UINT fLogoff, bool& bHandled );
virtual BOOL OnSetCursor( HWND hWnd, UINT nHitTest, UINT message, bool& bHandled );
#endif
// Other timely virtual functions for override
virtual void OnFirstMessage(HWND hWnd);
virtual void OnFinalMessage(HWND hWnd);
};
class CeWnd: public CeBaseWnd, public CeMsgWnd
{
private:
static LRESULT CALLBACK StartWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
static LPCTSTR CreateGenericWndClass(HINSTANCE hInst=NULL);
BOOL RegisterWndSuperclass(LPCTSTR lpszClass, WNDPROC& lpfnWndProc, HINSTANCE hInst=NULL);
BOOL IsCeWndProc(LPCTSTR lpstrWndClass, HINSTANCE hInst=NULL);
BOOL Subclass(UINT nID, HWND hWndParent);
BOOL Subclass(HWND hWnd);
HWND Unsubclass();
// Association, initialization, creation
static bool RegisterClass(LPCTSTR lpszClassName, UINT style=0,
int cbClsExtra=0, int cbWndExtra=0, HICON hIcon=NULL,
HCURSOR hCursor=NULL, HBRUSH hbrBackground=NULL,
LPCTSTR lpszMenuName=NULL,
HINSTANCE hInst=NULL);
BOOL Create(LPCTSTR lpstrWndClass, HWND hWndParent,
const RECT& rcPos, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle=0,
UINT nID = 0, HINSTANCE hInst=NULL);
BOOL Create(LPCTSTR lpstrWndClass, HWND hWndParent,
LPCRECT lpRect, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle = 0,
HMENU hMenu=NULL, HINSTANCE hInst=NULL);
};
#include "CeWnd.inl"
#include "CeCmdBar.h"
#endif // __CEWnd_h__