📄 atlwince.h
字号:
// Windows Template Library - WTL version 7.5
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.
#ifndef __ATLWINCE_H__
#define __ATLWINCE_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atlwince.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error atlwince.h requires atlwin.h to be included first
#endif
#ifndef _WIN32_WCE
#error atlwince.h compiles under Windows CE only
#elif (_WIN32_WCE < 300)
#error atlwince.h requires Windows CE 3.0 or higher.
#endif
#if defined(WIN32_PLATFORM_WFSP) && _MSC_VER < 1400 // EVC compiling SmartPhone code
#if (WIN32_PLATFORM_WFSP < 200)
#error atlwince.h requires Smartphone 2003 or higher
#endif
#endif // WIN32_PLATFORM_WFSP
#if defined(WIN32_PLATFORM_PSPC) && _MSC_VER < 1400 // EVC compiling Pocket PC code
#if (WIN32_PLATFORM_PSPC < 310)
#error atlwince.h requires Pocket PC 2002 or higher
#endif
#endif // WIN32_PLATFORM_PSPC
#if !defined(_AYGSHELL_H_) && !defined(__AYGSHELL_H__)
#error atlwince.h requires aygshell.h to be included first
#else
#if defined(WIN32_PLATFORM_WFSP) && !defined(_TPCSHELL_H_)
#error SmartPhone dialog classes require tpcshell.h to be included first
#endif
#endif
#if _MSC_VER >= 1400 // VS2005
#include <DeviceResolutionAware.h>
#define _WTL_CE_DRA
#endif // _MSC_VER >= 1400
#if !defined(_WTL_CE_NO_DIALOGS) && !defined(__ATLFRAME_H__)
#error Orientation aware dialog classes require atlframe.h to be included first
#endif
#if !defined(_WTL_CE_NO_APPWINDOW) && !defined(__ATLFRAME_H__)
#error Application window class require atlframe.h to be included first
#endif
#if !defined(_WTL_CE_NO_ZOOMSCROLL) && !defined(__ATLSCRL_H__)
#error ZoomScroll implementation requires atlscrl.h to be included first
#endif
#if !defined(_WTL_CE_NO_ZOOMSCROLL) && !defined(__ATLTYPES_H__)
#if !defined(__ATLMISC_H__) || defined(_WTL_NO_WTYPES)
#error ZoomScroll WTL::CSize usage requires _WTL_NO_WTYPES to be undefined and atlmisc.h to be included first
#elif defined(__ATLTYPES_H__)
#if !defined(__ATLMISC_H__) || !defined(_WTL_NO_WTYPES)
#error ZoomScroll ATL::CSize usage requires _WTL_NO_WTYPES to be defined and atlmisc.h to be included first
#endif
#endif
#endif
#if !defined(WIN32_PLATFORM_WFSP) && !defined(WIN32_PLATFORM_PSPC)
#define _WTL_CE_NO_CONTROLS
#endif // !defined(WIN32_PLATFORM_WFSP) && !defined(WIN32_PLATFORM_PSPC)
#ifndef _WTL_CE_NO_CONTROLS
#ifndef __ATLCTRLS_H__
#error The PPC/SmartPhone controls classes require atlctrls.h to be included first
#endif
#include <htmlctrl.h>
#pragma comment(lib, "htmlview.lib")
#include <voicectl.h>
#pragma comment(lib, "voicectl.lib")
#ifdef WIN32_PLATFORM_PSPC
#include <richink.h>
#pragma comment(lib, "richink.lib")
#include <inkx.h>
#pragma comment(lib, "inkx.lib")
#include <doclist.h>
#pragma comment(lib, "doclist.lib")
#endif
#endif
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CStdDialogBase<T, t_shidiFlags, t_bModal> : Standard dialog base class
// CStdDialogImpl<T, t_shidiFlags, t_bModal> : Standard dialog implementation
// CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags> : Standard simple dialog
// CStdDialogResizeBase<T, t_shidiFlags, t_bModal> : Orientation aware standard dialog base class
// CStdDialogResizeImpl<T, t_shidiFlags, t_bModal> : Orientation aware standard dialog implementation
// CStdSimpleDialogResizeImpl<T, t_wDlgTemplateID, t_shidiFlags> : Standard resizing simple dialog implementation
// CStdOrientedDialogBase<T, t_shidiFlags, t_bModal> : Orientable dialog base class
// CStdOrientedDialogImpl<T, t_shidiFlags, t_bModal> : Orientable dialog implementation
// CStdSimpleOrientedDialog<t_wDlgTemplateID, t_wDlgLandscapeID, t_shidiFlags> : Standard simple orientable dialog
//
// CAppInfoBase : Helper for application state save/restore to registry
// CAppInfoT<T> : CAppInfoBase constructed from a CAppWindow<T>
// CAppWindowBase<T> : Base class for PPC/SmartPhone well-behaved application window or dialog
// CAppWindow<T> : PPC/SmartPhone well-behaved application window class
// CAppDialog<T> : PPC/SmartPhone well-behaved application non-modal dialog class
// CAppStdDialogImpl<T, t_shidiFlags> : PPC/SmartPhone implementation of non-modal standard dialog application
//
// CFullScreenFrame<T, t_bHasSip> : Full screen frame class
//
// CZoomScrollImpl<T> : WinCE zooming implementation
//
// CHtmlCtrlT<TBase> - CHtmlCtrl
// CRichInkCtrlT<TBase> - CRichInkCtrl
// CInkXCtrlT<TBase> - CInkXCtrl
// CVoiceRecorderCtrlT<TBase> - CVoiceRecorderCtrl
// CDocListCtrlT<TBase> - CDocListCtrl
// CCapEditT<TBase> - CCapEdit
// CTTStaticT<TBase> - CTTStatic
// CTTButtonT<TBase> - CTTButton
//
// CSpinCtrlT<TBase> - CSpinCtrl : SmartPhone specific UpDown control
// CSpinned<TBase, t_bExpandOnly> : SmartPhone association of control and Spin
// CSpinListBox : SmartPhone spinned ListBox control
// CExpandListBox : SmartPhone expandable ListBox control
// CExpandEdit : SmartPhone expandable Edit control
// CExpandCapEdit : SmartPhone expandable CapEdit control
//
// Global functions:
// AtlCreateMenuBar()
// AtlCreateEmptyMenuBar()
namespace WTL
{
///////////////////////////////////////////////////////////////////////////////
// MenuBar creation functions for property sheets and dialogs
// Frame windows use CreateSimpleCEMenuBar
inline HWND AtlCreateMenuBar(SHMENUBARINFO& mbi)
{
ATLASSERT(::IsWindow(mbi.hwndParent));
ATLVERIFY(::SHCreateMenuBar(&mbi) != FALSE);
return mbi.hwndMB;
};
inline HWND AtlCreateMenuBar(HWND hWnd, UINT nToolBarId = ATL_IDW_TOOLBAR, DWORD dwFlags = 0, int nBmpId = 0, int cBmpImages = 0, COLORREF clrBk = 0)
{
#if (_ATL_VER >= 0x0700)
SHMENUBARINFO mbi = { sizeof(mbi), hWnd, dwFlags, nToolBarId, ATL::_AtlBaseModule.GetResourceInstance(), nBmpId, cBmpImages, 0, clrBk };
#else // !(_ATL_VER >= 0x0700)
SHMENUBARINFO mbi = { sizeof(mbi), hWnd, dwFlags, nToolBarId, _Module.GetResourceInstance(), nBmpId, cBmpImages, 0, clrBk };
#endif // !(_ATL_VER >= 0x0700)
return AtlCreateMenuBar(mbi);
}
inline HWND AtlCreateEmptyMenuBar(HWND hWnd, bool bSip = true)
{
SHMENUBARINFO embi = { sizeof(SHMENUBARINFO), hWnd, SHCMBF_EMPTYBAR };
if (!bSip)
embi.dwFlags |= SHCMBF_HIDESIPBUTTON;
return AtlCreateMenuBar(embi);
}
// --- Standard PPC/SmartPhone dialogs ---
#ifndef _WTL_CE_NO_DIALOGS
///////////////////////////////////////////////////////////////////////////////
// CStdDialogBase - base class for standard PPC/SmartPhone dialogs
#define WTL_STD_SHIDIF SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN
#define WTL_SP_SHIDIF SHIDIF_SIZEDLGFULLSCREEN
template <class T, UINT t_shidiFlags, bool t_bModal = true>
class CStdDialogBase
{
public:
// Pocket PC only Dialog title handling
#ifdef WIN32_PLATFORM_PSPC
const int nTitleHeight;
CStdDialogBase() : nTitleHeight(24)
{ }
// Title painting
LRESULT OnPaintTitle(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
TCHAR sTitle[40];
// Preparation
CPaintDC dc(pT->m_hWnd);
CFont fontTitle = AtlCreateBoldFont();
CFontHandle fontOld = dc.SelectFont(fontTitle);
dc.SetTextColor(RGB(0, 0, 156));
int nLen = pT->GetWindowText(sTitle, 40);
int nWidth = dc.GetDeviceCaps(HORZRES);
// Display title text
RECT rTitle = { 8, 0, nWidth, nTitleHeight };
dc.DrawText(sTitle, nLen, &rTitle, DT_VCENTER | DT_SINGLELINE);
dc.SelectFont(fontOld);
// Draw bottom line
CPenHandle penOld = dc.SelectStockPen(BLACK_PEN);
POINT line[2] = { { 0, nTitleHeight }, { nWidth, nTitleHeight } };
dc.Polyline(line, 2);
dc.SelectPen(penOld);
return bHandled = FALSE;
}
// Title preparation: move the dialog controls down to make room for title
void DialogTitleInit()
{
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
ATL::CWindow wCtl = pT->GetWindow(GW_CHILD);
while (wCtl.IsWindow())
{
RECT rCtl = { 0 };
wCtl.GetWindowRect(&rCtl);
::MapWindowPoints(NULL, pT->m_hWnd, (LPPOINT)&rCtl, 2);
::OffsetRect(&rCtl, 0, nTitleHeight);
wCtl.MoveWindow(&rCtl, FALSE);
wCtl = wCtl.GetWindow(GW_HWNDNEXT);
}
}
#endif // WIN32_PLATFORM_PSPC
#ifdef WIN32_PLATFORM_WFSP
// SmartPhone VK_TBACK key standard management
LRESULT OnHotKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
UINT uModif = (UINT)LOWORD(lParam);
UINT uVirtKey = (UINT)HIWORD(lParam);
if(uVirtKey == VK_TBACK)
{
ATL::CWindow wCtrl = GetFocus();
if (wCtrl.IsWindow())
{
TCHAR szClassName[8] = {0};
ATLVERIFY(::GetClassName(wCtrl.m_hWnd, szClassName, 8));
if (!_tcscmp(szClassName, _T("Edit")) || !_tcscmp(szClassName, WC_CAPEDIT))
{
::SHSendBackToFocusWindow(uMsg, wParam, lParam);
}
else
{
if (uModif & MOD_KEYUP)
pT->PostMessage(WM_COMMAND, IDCANCEL, 0);
}
}
}
return 1;
}
// Menu dialog ending
LRESULT OnMenuClose(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
pT->PostMessage(WM_COMMAND, wID == ID_MENU_CANCEL ? IDCANCEL : IDOK);
return 0;
}
void SetStaticBold()
{
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
CFontHandle fontBold = AtlCreateBoldFont(pT->GetFont());
ATL::CWindow wCtl = pT->GetWindow(GW_CHILD);
while (wCtl.IsWindow())
{
if ((short int)wCtl.GetDlgCtrlID() == IDC_STATIC)
wCtl.SetFont(fontBold);
wCtl = wCtl.GetWindow(GW_HWNDNEXT);
}
}
#endif // WIN32_PLATFORM_WFSP
// Platform dependant initialization
void StdPlatformInit()
{
#ifdef WIN32_PLATFORM_PSPC // Pocket PC title initialization
DialogTitleInit();
#elif defined(WIN32_PLATFORM_WFSP) // SmartPhone MenuBar and VK_TBACK key initialization
T* pT = static_cast<T*>(this);
HWND hMenuBar = NULL;
if (t_shidiFlags & SHIDIF_DONEBUTTON)
hMenuBar = AtlCreateMenuBar(pT->m_hWnd, ATL_IDM_MENU_DONE, SHCMBF_HMENU);
else
hMenuBar = ::SHFindMenuBar(pT->m_hWnd);
if(hMenuBar != NULL)
::SendMessage(hMenuBar, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
SetStaticBold();
#endif
}
// Shell dialog layout initialization
void StdShidInit()
{
T* pT = static_cast<T*>(this);
SHINITDLGINFO shidi = { SHIDIM_FLAGS, pT->m_hWnd, t_shidiFlags };
::SHInitDialog(&shidi);
}
// IDC_INFOSTATIC background setting
LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (::GetDlgCtrlID((HWND)lParam) == IDC_INFOSTATIC)
{
::SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)::GetSysColorBrush(COLOR_INFOBK);
}
return bHandled = FALSE;
}
// Standard dialog ending: may be used with any command
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
if (t_bModal)
::EndDialog(pT->m_hWnd, wID);
else
pT->DestroyWindow();
return 0;
}
};
///////////////////////////////////////////////////////////////////////////////
// CStdDialogImpl - implementation of standard PPC/SmartPhone dialog
template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true>
class ATL_NO_VTABLE CStdDialogImpl :
public ATL::CDialogImpl< T >,
public CStdDialogBase<T, t_shidiFlags, t_bModal>
{
public:
BEGIN_MSG_MAP(CStdDialogImpl)
#ifdef WIN32_PLATFORM_PSPC // Pocket PC title
MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
#elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
#endif
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
#ifdef _DEBUG // _DEBUG must be defined before atlwin.h inclusion
T* pT = static_cast<T*>(this);
ATLASSERT(t_bModal == pT->m_bModal);
#endif
StdPlatformInit();
StdShidInit();
return bHandled = FALSE;
}
};
///////////////////////////////////////////////////////////////////////////////
// CStdSimpleDialog - standard PPC/SmartPhone simple dialog with SHIDIF_xxx flags
template <WORD t_wDlgTemplateID, UINT t_shidiFlags = WTL_STD_SHIDIF>
class CStdSimpleDialog :
public ATL::CSimpleDialog<t_wDlgTemplateID, FALSE>,
public CStdDialogBase<CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>, t_shidiFlags>
{
public:
typedef CStdDialogBase<CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>, t_shidiFlags> baseClass;
BEGIN_MSG_MAP(CStdSimpleDialog)
#ifdef WIN32_PLATFORM_PSPC // Pocket PC title
MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
#elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
#endif
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, baseClass::OnCloseCmd)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
StdPlatformInit();
StdShidInit();
return bHandled = FALSE;
}
};
///////////////////////////////////////////////////////////////////////////////
// CStdDialogResizeBase - base class for orientation aware standard PPC dialogs
template <class T, UINT t_shidiFlags, bool t_bModal = true>
class CStdDialogResizeBase :
public CStdDialogBase<T, t_shidiFlags, t_bModal>,
public CDialogResize< T >
{
public:
// Note: BEGIN_DLGRESIZE_MAP is required in the derived class.
};
///////////////////////////////////////////////////////////////////////////////
// CStdDialogResizeImpl - implementation of orientation aware standard PPC dialog
template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true>
class ATL_NO_VTABLE CStdDialogResizeImpl :
public ATL::CDialogImpl< T >,
public CStdDialogResizeBase<T, t_shidiFlags, t_bModal>
{
public:
BEGIN_MSG_MAP(CStdResizeDialogImpl)
#ifdef WIN32_PLATFORM_PSPC // Pocket PC title
MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
#elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
#endif
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
CHAIN_MSG_MAP(CDialogResize< T >)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
#ifdef _DEBUG // _DEBUG must be defined before atlwin.h inclusion
T* pT = static_cast<T*>(this);
ATLASSERT(t_bModal == pT->m_bModal);
#endif
StdPlatformInit();
DlgResize_Init(FALSE);
StdShidInit();
return bHandled = FALSE;
}
};
///////////////////////////////////////////////////////////////////////////////
// CStdSimpleDialogResizeImpl - implementation of standard PPC resizing simple dialog with SHIDIF_xxx flags
// Usage:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -