#pragma once #ifndef __wap__ #define __wap__ #define BeginMsgProc() LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { #define BeginDlgMsgProc() bool DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { #define CreateMsg() case WM_CREATE: return OnCreate((CREATESTRUCT *)lParam); #define CommandMsg() case WM_COMMAND: if(!::SendMessage((HWND)lParam, WM_APP - 1, 0, 0)) return OnCommand(LOWORD(wParam), HIWORD(wParam), (oHWND *)&lParam); else return OnCommand(LOWORD(wParam), HIWORD(wParam), (oHWND *)::SendMessage((HWND)lParam, WM_APP - 1, 0, 0)); #define DestroyMsg() case WM_DESTROY: return OnDestroy(); #define DefaultMDIChildMsg() default: #define EndMsgProc() case WM_APP - 1: return (LRESULT)this; } return DefWindowProc(uMsg, wParam, lParam); } #define EndMsgProcOnMDIClient(__poMDIClient__) case WM_APP - 1: return (LRESULT)this; } return (__poMDIClient__)->DefFrameProc(uMsg, wParam, lParam); } #define EndMsgProcOnMDIChild() case WM_APP - 1: return (LRESULT)this; } return DefMDIChildProc(uMsg, wParam, lParam); } #define EndDlgMsgProc() } return false; } #define LButtonDownMsg() case WM_LBUTTONDOWN: return OnLButtonDown(wParam, LOWORD(lParam), HIWORD(lParam)); #define LButtonUpMsg() case WM_LBUTTONUP: return OnLButtonUp(wParam, (int)LOWORD(lParam), (int)HIWORD(lParam)); #define LButtonDblClkMsg() case WM_LBUTTONDBLCLK: return OnLButtonDblClk(wParam, LOWORD(lParam), HIWORD(lParam)); #define MouseMoveMsg() case WM_MOUSEMOVE: return OnMouseMove(wParam, (int)LOWORD(lParam), (int)HIWORD(lParam)); #define InitDialogMsg() return OnInitDialog((oHWND *)&lParam); #define MsgDo(__uMsg__, __func__) case __uMsg__: return __func__(uMsg, wParam, lParam); #define IDDo(__nID__, __func__) case __nID__: return __func__(nID, nNtfMsg, pohWnd); #define When(__any__) case __any__: #define BeginIDMap() switch(nID) { #define EndIDMap() } return 0; #define BeginNtfMap() switch(nNtfMsg) { #define EndNtfMap() } #define MDIActivateMsg() case WM_MDIACTIVATE: if(!::SendMessage((HWND)wParam, WM_APP - 1, 0, 0)) return OnMDIActivate((oHWND *)&wParam); else return OnMDIActivate((oHWND *)::SendMessage((HWND)wParam, WM_APP - 1, 0, 0)); #define SizeMsg() case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); #define SetFocusMsg() case WM_SETFOCUS: if(!::SendMessage((HWND)wParam, WM_APP - 1, 0, 0)) return OnSetFocus((oHWND *)&wParam); else return OnSetFocus((oHWND *)::SendMessage((HWND)wParam, WM_APP - 1, 0, 0)); #include #include #include #include namespace wap { class oICCX { protected: INITCOMMONCONTROLSEX m_iccx; public: oICCX(void) { m_iccx.dwSize = sizeof(INITCOMMONCONTROLSEX); m_iccx.dwICC = ICC_WIN95_CLASSES; } bool InitCommonControlsEx(void) { return (bool)::InitCommonControlsEx(&m_iccx); } void SetICC(DWORD dwICC) { m_iccx.dwICC = dwICC; return; } }; class oMsg { protected: MSG m_Msg; public: template int Run(T *pT = NULL, bool (T::*lpfnPre)(oMsg *poMsg) = NULL, void (T::*lpfnIdle)(void) = NULL) { BOOL bRet; for(;;) { while(pT && lpfnIdle && !::PeekMessage(&m_Msg, NULL, 0, 0, PM_NOREMOVE)) (pT->*lpfnIdle)(); bRet = ::GetMessage(&m_Msg, NULL, 0, 0); if(bRet == -1) continue; else if(!bRet) break; else if(pT && lpfnPre) { if(!(pT->*lpfnPre)(this)) { ::TranslateMessage(&m_Msg); ::DispatchMessage(&m_Msg); } } else { ::TranslateMessage(&m_Msg); ::DispatchMessage(&m_Msg); } } return (int)m_Msg.wParam; } }; class oPoint { protected: POINT m_Point; public: POINT *GetPOINTPointer(void) { return &m_Point; } }; class oRect { protected: RECT m_rc; public: RECT *GetRECTPointer(void) { return &m_rc; } }; class oDC { protected: HDC m_hDC; public: oDC(void) { m_hDC = NULL; } oDC(HDC hDC) { m_hDC = hDC; } HDC GetHDC(void) { return m_hDC; } bool MoveToEx(int x, int y, oPoint *poPoint) { return (bool)::MoveToEx(m_hDC, x, y, poPoint->GetPOINTPointer()); } bool LineTo(int x, int y) { return (bool)::LineTo(m_hDC, x, y); } }; class oMenu { protected: HMENU m_hMenu; public: oMenu(void) { m_hMenu = NULL; } oMenu(HMENU hMenu) { m_hMenu = NULL; } HMENU GetHMENU(void) { return m_hMenu; } void SetHMENU(HMENU hMenu) { m_hMenu = hMenu; } bool Load(LPCTSTR lpMenuName) { m_hMenu = ::LoadMenu(::GetModuleHandle(NULL), lpMenuName); if(!m_hMenu) return false; return true; } bool Is(void) { return (bool)::IsMenu(m_hMenu); } oMenu GetSub(int nPos) { return oMenu(::GetSubMenu(m_hMenu, nPos)); } }; class oHWND { protected: HWND m_hWnd; public: oHWND(void) { m_hWnd = NULL; } oHWND(HWND hWnd) { m_hWnd = hWnd; } LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam); } bool Destroy(void) { return (bool)::DestroyWindow(m_hWnd); } DWORD GetClassLong(int nIndex) { return ::GetClassLong(m_hWnd, nIndex); } HWND GetHWND(void) { return m_hWnd; } oHWND GetWindow(unsigned int uCmd) { return oHWND(::GetWindow(m_hWnd, uCmd)); } oHWND *GetWindowImplemented(unsigned int uCmd) { return (oHWND *)::SendMessage(::GetWindow(m_hWnd, uCmd), WM_APP - 1, 0, 0); } template T GetWindow(unsigned int uCmd) { T temp; temp.SetHWND(::GetWindow(m_hWnd, uCmd)); return temp; } template T *GetWindowImplemented(unsigned int uCmd) { HWND temp = ::GetWindow(m_hWnd, uCmd); return (T *)::SendMessage(temp, WM_APP - 1, 0, 0); } long GetWindowLong(int nIndex) { return ::GetWindowLong(m_hWnd, nIndex); } bool Is(void) { return (bool)::IsWindow(m_hWnd); } bool KillTimer(unsigned int nIDEvent) { return (bool)::KillTimer(m_hWnd, (UINT_PTR)nIDEvent); } int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption = NULL, UINT uType = MB_OK) { return ::MessageBox(m_hWnd, lpszText, lpszCaption, uType); } LRESULT SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { return ::SendMessage(m_hWnd, uMsg, wParam, lParam); } void SetHWND(HWND hWnd) { m_hWnd = hWnd; } unsigned int SetTimer(unsigned int nIDEvent, unsigned int uElapse, TIMERPROC lpTimerFunc) { return (unsigned int)::SetTimer(m_hWnd, (UINT_PTR)nIDEvent, uElapse, lpTimerFunc); } // VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); long SetWindowLong(int nIndex, LONG dwNewLong) { return ::SetWindowLong(m_hWnd, nIndex, dwNewLong); } bool Show(int nCmdShow) { return (bool)::ShowWindow(m_hWnd, nCmdShow); } oMenu GetMenu(void) { return oMenu(::GetMenu(m_hWnd)); } bool SetMenu(oMenu *poMenu) { return (bool)::SetMenu(m_hWnd, poMenu->GetHMENU()); } oHWND GetParent(void) { return oHWND(::GetParent(m_hWnd)); } oHWND *GetParentImplemented(void) { HWND temp = ::GetParent(m_hWnd); return (oHWND *)::SendMessage(temp, WM_APP - 1, 0, 0); } oHWND GetDlgItem(int nIDDlgItem) { return oHWND(::GetDlgItem(m_hWnd, nIDDlgItem)); } oHWND *GetDlgItemImplemented(int nIDDlgItem) { return (oHWND *)::SendMessage(::GetDlgItem(m_hWnd, nIDDlgItem), WM_APP - 1, 0, 0); } template T GetParent(void) { T temp; temp.SetHWND(::GetParent(m_hWnd)); return temp; } template T *GetParentImplemented(void) { return (T *)::SendMessage(::GetParent(m_hWnd), WM_APP - 1, 0, 0); } template T GetDlgItem(int nIDDlgItem) { T temp; temp.SetHWND(::GetDlgItem(m_hWnd, nIDDlgItem)); return temp; } template T *GetDlgItemImplemented(int nIDDlgItem) { return (T *)::SendMessage(::GetDlgItem(m_hWnd, nIDDlgItem), WM_APP - 1, 0, 0); } template T *GetThisPointer(void) { return (T *)SendMessage(WM_APP - 1, 0, 0); } bool DrawMenuBar(void) { return (bool)::DrawMenuBar(m_hWnd); } bool MoveWindow(int x, int y, int nWidth, int nHeight,bool bRepaint) { return (bool)::MoveWindow(m_hWnd, x, y, nWidth, nHeight, (BOOL)bRepaint); } oHWND SetFocus(void) { return oHWND(::SetFocus(m_hWnd)); } oHWND *SetFocusImplemented(void) { return (oHWND *)::SendMessage((HWND)::SetFocus(m_hWnd), WM_APP - 1, 0, 0); } template T SetFocus(void) { T temp; temp.SetHWND(::SetFocus(m_hWnd)); return temp; } template T *SetFocusImplemented(void) { return (T *)SendMessage((HWND)::SetFocus(m_hWnd), WM_APP - 1, 0, 0); } bool InvalidateRect(oRect *poRect, bool bErase) { return (bool)::InvalidateRect(m_hWnd, (poRect ? poRect->GetRECTPointer() : NULL), bErase); } oDC GetDC(void) { return oDC(::GetDC(m_hWnd)); } int ReleaseDC(oDC *poDC) { return ::ReleaseDC(m_hWnd, poDC->GetHDC()); } }; class oDlg : public oHWND { protected: static int m_nExtended; public: oDlg(void) { m_hWnd = NULL; } bool Modeless(LPCTSTR lpTemplate, oHWND *poWndParent) { if(!::IsWindow(m_hWnd)) { if(0 > m_nExtended) ExtendWndExtra(); if(!(m_hWnd = ::CreateDialogParam(GetModuleHandle(NULL), lpTemplate, (poWndParent ? poWndParent->GetHWND() : NULL), PreProc1, (LPARAM)this))) return false; return true; } return false; } int Modal(LPCTSTR lpTemplate, oHWND *poWndParent) { if(!::IsWindow(m_hWnd)) { if(0 > m_nExtended) ExtendWndExtra(); return (int)::DialogBoxParam(GetModuleHandle(NULL), lpTemplate, (poWndParent ? poWndParent->GetHWND() : NULL), PreProc1, (LPARAM)this); } return 0; } bool ExtendWndExtra(void) { HWND hWnd; bool bRet = true; hWnd = ::CreateWindow(TEXT("#32770"), NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); if(!hWnd) return false; m_nExtended = ::GetClassLong(hWnd, GCL_CBWNDEXTRA); ::SetClassLong(hWnd, GCL_CBWNDEXTRA, m_nExtended + sizeof(void *)); if(m_nExtended + sizeof(void *) != ::GetClassLong(hWnd, GCL_CBWNDEXTRA)) bRet = false; DestroyWindow(hWnd); return true; } static BOOL CALLBACK PreProc1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(WM_INITDIALOG == uMsg) { ((oDlg *)lParam)->SetHWND(hwndDlg); ::SetWindowLong(hwndDlg, m_nExtended, (long)lParam); if((long)lParam != ::GetWindowLong(hwndDlg, m_nExtended)) { ::EndDialog(hwndDlg, -1); return FALSE; } ::SetWindowLong(hwndDlg, DWL_DLGPROC, (long)PreProc2); if((long)PreProc2 != ::GetWindowLong(hwndDlg, DWL_DLGPROC)) { ::EndDialog(hwndDlg, -1); return FALSE; } return ::SendMessage(hwndDlg, uMsg, wParam, lParam); } return FALSE; } static BOOL CALLBACK PreProc2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { return (BOOL)(((oDlg *)::GetWindowLong(hwndDlg, m_nExtended))->DlgProc(uMsg, wParam, lParam)); } bool EndDialog(int nResult) { return (bool)::EndDialog(m_hWnd, nResult); } virtual bool DlgProc(unsigned int, WPARAM, LPARAM) = 0; }; int oDlg::m_nExtended = -1; class oWnd : public oHWND { protected: static int m_nExtended; public: oWnd(void) { m_hWnd = NULL; } bool Create(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int nWidth = CW_USEDEFAULT, int nHeight = CW_USEDEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, oHWND *poWndParent = NULL, oMenu *poMenu = NULL) { m_hWnd = ::CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, (poWndParent ? poWndParent->GetHWND() : NULL), (poMenu ? poMenu->GetHMENU() : NULL), GetModuleHandle(NULL), (void *)this); if(!m_hWnd) return false; return true; } static LRESULT CALLBACK PreProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(WM_CREATE == uMsg) { ((oWnd *)(((CREATESTRUCT *)lParam)->lpCreateParams))->SetHWND(hWnd); ::SetWindowLongW(hWnd, 0, (long)(((CREATESTRUCT *)lParam)->lpCreateParams)); if((long)(((CREATESTRUCT *)lParam)->lpCreateParams) != ::GetWindowLong(hWnd, 0)) return -1; ::SetWindowLong(hWnd, GWL_WNDPROC, (long)PreProc2); if((long)PreProc2 != ::GetWindowLong(hWnd, GWL_WNDPROC)) return -1; return ::SendMessage(hWnd, uMsg, wParam, lParam); } return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } static LRESULT CALLBACK PreProc2(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return ((oWnd *)::GetWindowLong(hWnd, 0))->WndProc(uMsg, wParam, lParam); } virtual LRESULT WndProc(unsigned int uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(uMsg, wParam, lParam); } }; int oWnd::m_nExtended = 0; class oWC { private: WNDCLASS m_wc; public: oWC(void) { m_wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; m_wc.cbClsExtra = 0; m_wc.cbWndExtra = sizeof(void *); m_wc.hInstance = GetModuleHandle(NULL); m_wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); m_wc.hCursor = LoadCursor(NULL, IDC_ARROW); m_wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); m_wc.lpszMenuName = NULL; m_wc.lpfnWndProc = oWnd::PreProc1; } bool Register(LPCTSTR lpszClassName) { m_wc.lpszClassName = lpszClassName; if(!::RegisterClass(&m_wc)) return false; return true; } void SetBackground(HBRUSH hbrBackground) { m_wc.hbrBackground = hbrBackground; return; } void SetClassName(LPCTSTR lpszClassName) { m_wc.lpszClassName = lpszClassName; return; } void SetClsExtra(int cbClsExtra) { m_wc.cbClsExtra = cbClsExtra; return; } void SetCursor(HCURSOR hCursor) { m_wc.hCursor = hCursor; return; } void SetIcon(HICON hIcon) { m_wc.hIcon = hIcon; return; } void SetInstance(HINSTANCE hInstance) { m_wc.hInstance = hInstance; return; } void SetMenuName(LPCTSTR lpszMenuName) { m_wc.lpszMenuName = lpszMenuName; return; } void SetStyle(UINT style) { m_wc.style = style; return; } }; class oWCX { protected: WNDCLASSEX m_wcx; public: oWCX(void) { m_wcx.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; m_wcx.cbClsExtra = 0; m_wcx.cbWndExtra = sizeof(void *); m_wcx.hInstance = GetModuleHandle(NULL); m_wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); m_wcx.hCursor = LoadCursor(NULL, IDC_ARROW); m_wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); m_wcx.lpszMenuName = NULL; m_wcx.cbSize = sizeof(WNDCLASSEX); m_wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); m_wcx.lpfnWndProc = oWnd::PreProc1; } bool Register(LPCTSTR lpszClassName) { m_wcx.lpszClassName = lpszClassName; if(!::RegisterClassEx(&m_wcx)) return false; return true; } void SetBackground(HBRUSH hbrBackground) { m_wcx.hbrBackground = hbrBackground; return; } void SetClsExtra(int cbClsExtra) { m_wcx.cbClsExtra = cbClsExtra; return; } void SetCursor(HCURSOR hCursor) { m_wcx.hCursor = hCursor; return; } void SetIcon(HICON hIcon) { m_wcx.hIcon = hIcon; return; } void SetIconSm(HICON hIconSm) { m_wcx.hIconSm = hIconSm; } void SetInstance(HINSTANCE hInstance) { m_wcx.hInstance = hInstance; return; } void SetMenuName(LPCTSTR lpszMenuName) { m_wcx.lpszMenuName = lpszMenuName; return; } void SetSize(UINT cbSize) { m_wcx.cbSize = cbSize; return; } void SetStyle(UINT style) { m_wcx.style = style; return; } }; class oMDIChild : public oWnd { public: LRESULT DefMDIChildProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { return ::DefMDIChildProc(m_hWnd, uMsg, wParam, lParam); } void MDIDestroy(void) { ::SendMessage(::GetParent(m_hWnd), WM_MDIDESTROY, (WPARAM)m_hWnd, 0); return; } }; class oCtrl : public oHWND { protected: bool _Create(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int nWidth, int nHeight, int x, int y, oHWND *poWndParent, unsigned int nID, LPVOID lpParam = NULL) { m_hWnd = ::CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle | WS_CHILD, x, y, nWidth, nHeight, (poWndParent ? poWndParent->GetHWND() : NULL), (HMENU)nID, GetModuleHandle(NULL), lpParam); if(!m_hWnd) return false; return true; } }; class oButton : public oCtrl { public: bool Create(DWORD dwExStyle, LPCTSTR lpszCaption, DWORD dwStyle, int nWidth, int nHeight, int x, int y, oHWND *poWndParent, unsigned int nID) { return _Create(dwExStyle, TEXT("button"), lpszCaption, dwStyle, nWidth, nHeight, x, y, poWndParent, nID, NULL); } bool Enable(bool fEnable) { return (bool)Button_Enable(m_hWnd, (BOOL)fEnable); } LRESULT GetCheck(void) { return (LRESULT)Button_GetCheck(m_hWnd); } bool GetNote(LPCWSTR psz, int pcc) { return (bool)Button_GetNote(m_hWnd, psz, pcc); } LRESULT GetNoteLength(void) { return (LRESULT)Button_GetNoteLength(m_hWnd); } LRESULT GetState(void) { return (LRESULT)Button_GetState(m_hWnd); } int GetText(LPTSTR lpch, int cchMax) { return (int)Button_GetText(m_hWnd, lpch, cchMax); } int GetTextLength(void) { return (int)Button_GetTextLength(m_hWnd); } bool GetTextMargin(oRect *pmargin) { return (bool)Button_GetTextMargin(m_hWnd, pmargin->GetRECTPointer()); } void SetCheck(int check) { Button_SetCheck(m_hWnd, check); } bool SetDropDownState(bool fDropDown) { return (bool)Button_SetDropDownState(m_hWnd, fDropDown); } LRESULT SetElevationRequiredState(BOOL fRequired) { return (LRESULT)Button_SetElevationRequiredState(m_hWnd, fRequired); } bool SetNote(PCWSTR pszNote) { return (BOOL)Button_SetNote(m_hWnd, pszNote); } LRESULT SetState(bool state) { return (LRESULT)Button_SetState(m_hWnd, (BOOL)state); } void SetStyle(DWORD style, bool fRedraw) { Button_SetStyle(m_hWnd, style, (BOOL)fRedraw); } int SetText(LPTSTR lpszText) { return (int)Button_SetText(m_hWnd, lpszText); } bool SetTextMargin(oRect *pmargin) { return (bool)Button_SetTextMargin(m_hWnd, pmargin->GetRECTPointer()); } }; class oEdit : public oCtrl { public: bool Create(DWORD dwExStyle, DWORD dwStyle, int nWidth, int nHeight, int x, int y, oHWND *poWndParent, unsigned int nID) { return _Create(dwExStyle, TEXT("edit"), NULL, dwStyle | WS_CHILD, x, y, nWidth, nHeight, poWndParent, nID, NULL); } bool Undo(void) { return (bool)Edit_Undo(m_hWnd); } int SetText(LPTSTR lpsz) { return (int)Edit_SetText(m_hWnd, lpsz); } void SetTabStops(int cTabs, int *lpTabs) { Edit_SetTabStops(m_hWnd, cTabs, lpTabs); } void SetSel(int ichStart, int ichEnd) { Edit_SetSel(m_hWnd, ichStart, ichEnd); } void SetRectNoPaint(oRect *porc) { Edit_SetRectNoPaint(m_hWnd, porc->GetRECTPointer()); } void SetRect(oRect *porc) { Edit_SetRect(m_hWnd, porc->GetRECTPointer()); } bool SetReadOnly(bool fReadOnly) { return (bool)Edit_SetReadOnly(m_hWnd, (BOOL)fReadOnly); } void SetPasswordChar(unsigned int ch) { Edit_SetPasswordChar(m_hWnd, ch); } void SetModify(bool fModified) { Edit_SetModify(m_hWnd, (BOOL)fModified); } bool SetCueBannerTextFocused(LPCWSTR lpcwText, bool fDrawFocused) { return (bool)Edit_SetCueBannerTextFocused(m_hWnd, lpcwText, (BOOL)fDrawFocused); } bool SetCueBannerText(LPCWSTR lpcwText) { return (bool)Edit_SetCueBannerText(m_hWnd, lpcwText); } bool ScrollCaret(void) { return (bool)Edit_ScrollCaret(m_hWnd); } void Scroll(int dv, int dh) { Edit_Scroll(m_hWnd, dv, dh); } void ReplaceSel(LPCTSTR lpszReplace) { Edit_ReplaceSel(m_hWnd, lpszReplace); } int LineLength(int line) { return (int)Edit_LineLength(m_hWnd, line); } int LineIndex(int line) { return (int)Edit_LineIndex(m_hWnd, line); } int LineFromChar(int ich) { return (int)Edit_LineFromChar(m_hWnd, ich); } void LimitText(int cchMax) { Edit_LimitText(m_hWnd, cchMax); } bool HideBalloonTip(void) { return (bool)Edit_HideBalloonTip(m_hWnd); } int GetTextLength(void) { return (int)Edit_GetTextLength(m_hWnd); } int GetText(LPTSTR lpch, int cchMax) { return (int)Edit_GetText(m_hWnd, lpch, cchMax); } DWORD GetSel(void) { return (DWORD)Edit_GetSel(m_hWnd); } void GetRect(oRect *porc) { Edit_GetRect(m_hWnd, porc->GetRECTPointer()); } TCHAR GetPasswordChar(void) { return (TCHAR) Edit_GetPasswordChar(m_hWnd); } bool GetModify(void) { return (bool)Edit_GetModify(m_hWnd); } int GetLineCount(void) { return (int)Edit_GetLineCount(m_hWnd); } int GetLine(int line, LPTSTR lpch, int cchMax) { return (int)Edit_GetLine(m_hWnd, line, lpch, cchMax); } int GetFirstVisibleLine(void) { return (int)Edit_GetFirstVisibleLine(m_hWnd); } bool GetCueBannerText(LPCWSTR lpcwText, long cchText) { return (bool)Edit_GetCueBannerText(m_hWnd, lpcwText, cchText); } bool FormatLines(bool fAddEOL) { return (bool)Edit_FmtLines(m_hWnd, (BOOL)fAddEOL); } bool Enable(bool fEnable) { return (bool)Edit_Enable(m_hWnd, (BOOL)fEnable); } void EmptyUndoBuffer(void) { Edit_EmptyUndoBuffer(m_hWnd); } bool CanUndo(void) { return (bool)Edit_CanUndo(m_hWnd); } }; class oMDIClient : public oCtrl { protected: static bool (*lpfnCloseAllProc)(oMDIChild *, LPARAM); public: bool Create(DWORD dwExStyle, DWORD dwStyle, oHWND *poWndParent, unsigned int nID, oMenu *poWindowMenu, unsigned int nIDFirstChild) { CLIENTCREATESTRUCT ccs; ccs.hWindowMenu = poWindowMenu->GetHMENU(); ccs.idFirstChild = nIDFirstChild; return _Create(dwExStyle, TEXT("MDICLIENT"), NULL, WS_CHILD | dwStyle, 0, 0, 0, 0, poWndParent, nID, (LPSTR)&ccs); } void MDIRestore(oMDIChild *poMDIChild) { SendMessage(WM_MDIRESTORE, (WPARAM)poMDIChild->GetHWND(), 0); } bool CloseAll(bool (*lpfnCAP)(oMDIChild *, LPARAM) = oMDIClient::CloseAllProc, LPARAM lParam = 0) { lpfnCloseAllProc = lpfnCAP; return (bool)::EnumChildWindows(m_hWnd, oMDIClient::CloseAllPreProc, lParam); } static BOOL CALLBACK CloseAllPreProc(HWND hWnd, LPARAM lParam) { return (BOOL)lpfnCloseAllProc((oMDIChild *)::SendMessage(hWnd, WM_APP - 1, 0, 0), lParam); } static bool CloseAllProc(oMDIChild *poMDIChild, LPARAM lParam) { if(poMDIChild->GetWindow(GW_OWNER).Is()) return true; poMDIChild->GetParent().MDIRestore(poMDIChild); if(!poMDIChild->SendMessage(WM_QUERYENDSESSION, 0, 0)) return true; poMDIChild->MDIDestroy(); delete poMDIChild; return true; } template T *CreateMDIWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int nWidth = CW_USEDEFAULT, int nHeight = CW_USEDEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, T *pT = NULL) { bool bGivenPointer = true; if(!pT) { bGivenPointer = false; pT = new pT; } if(!pT) return NULL; temp->SetHWND(::CreateMDIWindow(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, this->GetHWND(), ::GetModuleHandle(0), pT)); if(!(temp->GetHWND())) { if(!bGivenPointer) delete pT; return NULL; } return pT; } template T *CreateMDIWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, cArgType param, int nWidth = CW_USEDEFAULT, int nHeight = CW_USEDEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT) { bool bGivenPointer = true; if(!pT) { bGivenPointer = false; pT = new pT(param); } if(!pT) return NULL; temp->SetHWND(::CreateMDIWindow(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, this->GetHWND(), ::GetModuleHandle(0), pT)); if(!(temp->GetHWND())) { if(!bGivenPointer) delete pT; return NULL; } return pT; } void MDITile(int nType) { SendMessage(WM_MDITILE, (WPARAM)nType, 0); return; } void MDICascade(int nType) { SendMessage(WM_MDICASCADE, (WPARAM)nType, 0); return; } void MDIIconArrange(void) { SendMessage(WM_MDIICONARRANGE, 0, 0); return; } oMenu MDISetMenu(oMenu* poMenu, oMenu* poSubMenu) { return oMenu((HMENU)SendMessage(WM_MDISETMENU, (WPARAM)poMenu->GetHMENU(), (LPARAM)poSubMenu->GetHMENU())); } }; bool (oMDIClient::*lpfnCloseAllProc)(oMDIChild *, LPARAM); }; #endif