📄 atlwince.h
字号:
// Windows Template Library - WTL version 8.0
// 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
// Microsoft Permissive License (Ms-PL) which can be found in the file
// Ms-PL.txt at the root of this distribution.
#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)
#if !(defined(__ATLTYPES_H__) || (defined(__ATLMISC_H__) && !defined(_WTL_NO_WTYPES)))
#error ZoomScroll requires _WTL_NO_WTYPES not to be defined and either atlmisc.h or atltypes.h to be included first
#endif // !(defined(__ATLTYPES_H__) || (defined(__ATLMISC_H__) && !defined(_WTL_NO_WTYPES)))
#endif // !defined(_WTL_CE_NO_ZOOMSCROLL)
#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 PPC/SmartPhone dialog base class
// CStdDialogImplBase - Base implementation of standard dialog
// CStdDialogImpl<T, t_shidiFlags, t_bModal> : Standard dialog implementation
// CStdIndirectDialogImpl - implementation of standard indirect PPC/SmartPhone dialog
// CStdAxDialogImpl<T, t_shidiFlags, t_bModal> : Standard AxDialog implementation
// CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags> : Standard simple dialog
// CStdDialogResizeImplBase - Base implementation of orientation resizing standard dialog
// CStdDialogResizeImpl<T, t_shidiFlags, t_bModal> : Orientation resizing standard dialog implementation
// CStdAxDialogResizeImpl - implementation of orientation resizing standard AxDialog
// CStdSimpleDialogResizeImpl<T, t_wDlgTemplateID, t_shidiFlags> : Standard resizing simple dialog implementation
// CStdOrientedDialogBase - Oriented PPC standard dialog base class
// CStdOrientedDialogImplBase - Oriented PPC standard dialog base implementation
// CStdOrientedDialogImpl<T, t_shidiFlags, t_bModal> : Oriented PPC standard dialog implementation
// CStdAxOrientedDialogImpl - Oriented PPC standard AxDialog 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 dialog class
// CAppStdDialogImplBase - Base implementation of standard application dialogs
// CAppStdDialogImpl<T, t_shidiFlags, t_bModal> : Implementation of standard application dialog
// CAppStdDialogResizeImpl - implementation of orientation resizing standard application dialog
// CAppStdAxDialogImpl - Implementation of standard application AxDialog
// CAppStdAxDialogResizeImpl - implementation of orientation resizing standard application AxDialog
// CAppStdOrientedDialogImpl - implementation of oriented PPC standard application dialog
// CAppStdAxOrientedDialogImpl - implementation of oriented PPC standard application AxDialog
//
// CFullScreenFrame<T, t_bHasSip> : Full screen frame class
//
// CZoomScrollImpl<T> : WinCE zooming implementation
//
// CBottomTabViewImpl<T, TBase, TWinTraits> - CBottomTabView
// 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()
// AtlIsEditFocus()
// AtlActivateBackKey()
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)
{
SHMENUBARINFO mbi = { sizeof(mbi), hWnd, dwFlags, nToolBarId, ModuleHelper::GetResourceInstance(), nBmpId, cBmpImages, 0, clrBk };
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);
}
///////////////////////////////////////////////////////////////////////////////
// Helper functions for SmartPhone back key handling
inline bool AtlIsEditFocus()
{
ATL::CWindow wCtrl = GetFocus();
if (wCtrl.IsWindow())
{
TCHAR szClassName[8] = {0};
ATLVERIFY(::GetClassName(wCtrl.m_hWnd, szClassName, 8));
return !_tcscmp(szClassName, _T("Edit")) || !_tcscmp(szClassName, WC_CAPEDIT);
}
return false;
}
#if defined WIN32_PLATFORM_WFSP
inline void AtlActivateBackKey(HWND hMenuBar)
{
ATLASSERT(::IsWindow(hMenuBar));
::SendMessage(hMenuBar, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
}
#endif // WIN32_PLATFORM_WFSP
// --- 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
// Title setting macros
#define WTL_DLG_TITLEHEIGHT(iHeight) static const int GetTitleHeight(){return iHeight;}
#define WTL_DLG_NOTITLE WTL_DLG_TITLEHEIGHT(0)
///////////////////////////////////////////////////////////////////////////////
// CStdDialogBase - Base class for standard PPC/SmartPhone dialog
template <class T, UINT t_shidiFlags, bool t_bModal = true>
class CStdDialogBase
{
public:
#ifdef WIN32_PLATFORM_PSPC
// Pocket PC only Dialog title handling
const int nTitleHeight;
CStdDialogBase() : nTitleHeight(T::GetTitleHeight())
{ }
// Overloads
BOOL GetClientRect(LPRECT lpRect)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
BOOL bRes = ::GetClientRect(pT->m_hWnd, lpRect);
lpRect->top += nTitleHeight;
return bRes;
}
BOOL SetWindowText(LPCTSTR lpszString)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
BOOL bRes = ::SetWindowText(pT->m_hWnd, lpszString);
if (nTitleHeight != 0)
pT->DoPaintTitle();
return bRes;
}
// Overrideables
static const int GetTitleHeight()
{
#ifdef _WTL_CE_DRA
return DRA::SCALEY(24);
#else // !_WTL_CE_DRA
CWindowDC dc(NULL);
return dc.GetDeviceCaps(LOGPIXELSY) >> 2; // LOGPIXELSY * 24 / 96,
#endif // !_WTL_CE_DRA
}
// Title painting
bool DoPaintTitle()
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
TCHAR sTitle[48];
// Preparation
CPaintDC dc(pT->m_hWnd);
CFont fontTitle = AtlCreateBoldFont();
CFontHandle fontOld = dc.SelectFont(fontTitle);
dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHT));
int nLen = pT->GetWindowText(sTitle, 48);
int nWidth = dc.GetDeviceCaps(HORZRES);
// Display title text
RECT rTitle = { 0, 0, nWidth, nTitleHeight };
dc.FillRect(&rTitle, COLOR_3DHIGHLIGHT);
#ifdef _WTL_CE_DRA
rTitle.left = DRA::SCALEX(8);
#else // !_WTL_CE_DRA
rTitle.left = nTitleHeight / 3; // 8 == 24 / 3
#endif // !_WTL_CE_DRA
dc.DrawText(sTitle, nLen, &rTitle, DT_VCENTER | DT_SINGLELINE);
dc.SelectFont(fontOld);
// Draw bottom line, 2 pixels thick if HI_RES_AWARE
CPenHandle penOld = dc.SelectStockPen(BLACK_PEN);
POINT line[4] = {{0, nTitleHeight}, {nWidth, nTitleHeight}, {0, nTitleHeight - 1}, {nWidth, nTitleHeight - 1}};
#ifdef _WTL_CE_DRA
int nSeg = DRA::SCALEY(1);
#else // !_WTL_CE_DRA
int nSeg = nTitleHeight / 24;
#endif // !_WTL_CE_DRA
dc.Polyline(line, nSeg <= 2 ? nSeg * 2 : 4);
dc.SelectPen(penOld);
return false;
}
// Title preparation: move the dialog controls down to make room for title
void DialogTitleInit()
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
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);
}
}
// SIP management
void DoSipInfo()
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
SIPINFO si = {sizeof(SIPINFO)};
SipGetInfo(&si);
if ((si.fdwFlags & SIPF_ON) ^ SIPF_ON)
si.rcVisibleDesktop.bottom = si.rcSipRect.bottom;
pT->MoveWindow(&si.rcVisibleDesktop, FALSE);
}
// Title painting handler
LRESULT OnPaintTitle(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
return bHandled = nTitleHeight ? pT->DoPaintTitle() : FALSE;
}
// SIP handler
LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
if (wParam == SPI_SETSIPINFO)
{
pT->DoSipInfo();
return TRUE;
}
return bHandled = FALSE;
}
#elif defined 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);
const UINT uModif = (UINT)LOWORD(lParam);
const UINT uVirtKey = (UINT)HIWORD(lParam);
if(uVirtKey == VK_TBACK)
if (AtlIsEditFocus())
::SHSendBackToFocusWindow(uMsg, wParam, lParam);
else if (uModif & MOD_KEYUP)
pT->StdCloseDialog(IDCANCEL);
return 1;
}
// SmartPhone MenuBar and VK_TBACK key initialization
void StdSPInit()
{
T* pT = static_cast<T*>(this);
HWND hMenuBar = ::SHFindMenuBar(pT->m_hWnd);
if (!hMenuBar && (t_shidiFlags & SHIDIF_DONEBUTTON))
hMenuBar = CreateMenuBar(ATL_IDM_MENU_DONE);
if(hMenuBar != NULL)
AtlActivateBackKey(hMenuBar);
}
void SetStaticBold()
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->IsWindow());
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()
{
T* pT = static_cast<T*>(this);
#ifdef WIN32_PLATFORM_PSPC // Pocket PC title initialization
if (nTitleHeight != 0)
pT->DialogTitleInit();
#elif defined(WIN32_PLATFORM_WFSP)
pT->StdSPInit();
SetStaticBold();
#endif // WIN32_PLATFORM_WFSP
}
// Menu bar creation
HWND CreateMenuBar(UINT uiMB = T::IDD, int nBmpImages = 0)
{
T* pT = static_cast<T*>(this);
return AtlCreateMenuBar(pT->m_hWnd, uiMB, 0, nBmpImages ? uiMB : 0, nBmpImages);
}
// Dialog closing
void StdCloseDialog(WORD wID)
{
T* pT = static_cast<T*>(this);
if (t_bModal)
::EndDialog(pT->m_hWnd, wID);
else
pT->DestroyWindow();
}
// Shell dialog layout initialization
void StdShidInit()
{
T* pT = static_cast<T*>(this);
SHINITDLGINFO shidi = { SHIDIM_FLAGS, pT->m_hWnd, t_shidiFlags };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -