Add ICU message format support
[chromium-blink-merge.git] / third_party / wtl / include / atlwince.h
blob31ba35aaae73a4628ef4661195a468b75c49183e
1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. All rights reserved.
3 //
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
9 #ifndef __ATLWINCE_H__
10 #define __ATLWINCE_H__
12 #pragma once
14 #ifndef __cplusplus
15 #error ATL requires C++ compilation (use a .cpp suffix)
16 #endif
18 #ifndef __ATLAPP_H__
19 #error atlwince.h requires atlapp.h to be included first
20 #endif
22 #ifndef __ATLWIN_H__
23 #error atlwince.h requires atlwin.h to be included first
24 #endif
26 #ifndef _WIN32_WCE
27 #error atlwince.h compiles under Windows CE only
28 #elif (_WIN32_WCE < 300)
29 #error atlwince.h requires Windows CE 3.0 or higher.
30 #endif
32 #if defined(WIN32_PLATFORM_WFSP) && _MSC_VER < 1400 // EVC compiling SmartPhone code
33 #if (WIN32_PLATFORM_WFSP < 200)
34 #error atlwince.h requires Smartphone 2003 or higher
35 #endif
36 #endif // WIN32_PLATFORM_WFSP
38 #if defined(WIN32_PLATFORM_PSPC) && _MSC_VER < 1400 // EVC compiling Pocket PC code
39 #if (WIN32_PLATFORM_PSPC < 310)
40 #error atlwince.h requires Pocket PC 2002 or higher
41 #endif
42 #endif // WIN32_PLATFORM_PSPC
44 #if !defined(_AYGSHELL_H_) && !defined(__AYGSHELL_H__)
45 #error atlwince.h requires aygshell.h to be included first
46 #else
47 #if defined(WIN32_PLATFORM_WFSP) && !defined(_TPCSHELL_H_)
48 #error SmartPhone dialog classes require tpcshell.h to be included first
49 #endif
50 #endif
52 #if (_MSC_VER >= 1400) // VS2005
53 #include <DeviceResolutionAware.h>
54 #define _WTL_CE_DRA
55 #endif // (_MSC_VER >= 1400)
57 #if !defined(_WTL_CE_NO_DIALOGS) && !defined(__ATLFRAME_H__)
58 #error Orientation aware dialog classes require atlframe.h to be included first
59 #endif
61 #if !defined(_WTL_CE_NO_APPWINDOW) && !defined(__ATLFRAME_H__)
62 #error Application window class require atlframe.h to be included first
63 #endif
65 #if !defined(_WTL_CE_NO_ZOOMSCROLL) && !defined(__ATLSCRL_H__)
66 #error ZoomScroll implementation requires atlscrl.h to be included first
67 #endif
69 #if !defined(_WTL_CE_NO_ZOOMSCROLL)
70 #if !(defined(__ATLTYPES_H__) || (defined(__ATLMISC_H__) && !defined(_WTL_NO_WTYPES)))
71 #error ZoomScroll requires _WTL_NO_WTYPES not to be defined and either atlmisc.h or atltypes.h to be included first
72 #endif // !(defined(__ATLTYPES_H__) || (defined(__ATLMISC_H__) && !defined(_WTL_NO_WTYPES)))
73 #endif // !defined(_WTL_CE_NO_ZOOMSCROLL)
75 #if !defined(WIN32_PLATFORM_WFSP) && !defined(WIN32_PLATFORM_PSPC)
76 #define _WTL_CE_NO_CONTROLS
77 #endif // !defined(WIN32_PLATFORM_WFSP) && !defined(WIN32_PLATFORM_PSPC)
79 #ifndef _WTL_CE_NO_CONTROLS
80 #ifndef __ATLCTRLS_H__
81 #error The PPC/SmartPhone controls classes require atlctrls.h to be included first
82 #endif
84 #include <htmlctrl.h>
85 #pragma comment(lib, "htmlview.lib")
87 #include <voicectl.h>
88 #pragma comment(lib, "voicectl.lib")
90 #ifdef WIN32_PLATFORM_PSPC
91 #include <richink.h>
92 #pragma comment(lib, "richink.lib")
94 #include <inkx.h>
95 #pragma comment(lib, "inkx.lib")
97 #include <doclist.h>
98 #pragma comment(lib, "doclist.lib")
99 #endif
100 #endif
103 ///////////////////////////////////////////////////////////////////////////////
104 // Classes in this file:
106 // CStdDialogBase<T, t_shidiFlags, t_bModal> : Standard PPC/SmartPhone dialog base class
107 // CStdDialogImplBase - Base implementation of standard dialog
108 // CStdDialogImpl<T, t_shidiFlags, t_bModal> : Standard dialog implementation
109 // CStdIndirectDialogImpl - implementation of standard indirect PPC/SmartPhone dialog
110 // CStdAxDialogImpl<T, t_shidiFlags, t_bModal> : Standard AxDialog implementation
111 // CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags> : Standard simple dialog
112 // CStdDialogResizeImplBase - Base implementation of orientation resizing standard dialog
113 // CStdDialogResizeImpl<T, t_shidiFlags, t_bModal> : Orientation resizing standard dialog implementation
114 // CStdAxDialogResizeImpl - implementation of orientation resizing standard AxDialog
115 // CStdSimpleDialogResizeImpl<T, t_wDlgTemplateID, t_shidiFlags> : Standard resizing simple dialog implementation
116 // CStdOrientedDialogBase - Oriented PPC standard dialog base class
117 // CStdOrientedDialogImplBase - Oriented PPC standard dialog base implementation
118 // CStdOrientedDialogImpl<T, t_shidiFlags, t_bModal> : Oriented PPC standard dialog implementation
119 // CStdAxOrientedDialogImpl - Oriented PPC standard AxDialog implementation
120 // CStdSimpleOrientedDialog<t_wDlgTemplateID, t_wDlgLandscapeID, t_shidiFlags> : Standard simple orientable dialog
122 // CAppInfoBase : Helper for application state save/restore to registry
123 // CAppInfoT<T> : CAppInfoBase constructed from a CAppWindow<T>
124 // CAppWindowBase<T> : Base class for PPC/SmartPhone well-behaved application window or dialog
125 // CAppWindow<T> : PPC/SmartPhone well-behaved application window class
126 // CAppDialog<T> : PPC/SmartPhone well-behaved application dialog class
127 // CAppStdDialogImplBase - Base implementation of standard application dialogs
128 // CAppStdDialogImpl<T, t_shidiFlags, t_bModal> : Implementation of standard application dialog
129 // CAppStdDialogResizeImpl - implementation of orientation resizing standard application dialog
130 // CAppStdAxDialogImpl - Implementation of standard application AxDialog
131 // CAppStdAxDialogResizeImpl - implementation of orientation resizing standard application AxDialog
132 // CAppStdOrientedDialogImpl - implementation of oriented PPC standard application dialog
133 // CAppStdAxOrientedDialogImpl - implementation of oriented PPC standard application AxDialog
135 // CFullScreenFrame<T, t_bHasSip> : Full screen frame class
137 // CZoomScrollImpl<T> : WinCE zooming implementation
139 // CBottomTabViewImpl<T, TBase, TWinTraits> - CBottomTabView
140 // CHtmlCtrlT<TBase> - CHtmlCtrl
141 // CRichInkCtrlT<TBase> - CRichInkCtrl
142 // CInkXCtrlT<TBase> - CInkXCtrl
143 // CVoiceRecorderCtrlT<TBase> - CVoiceRecorderCtrl
144 // CDocListCtrlT<TBase> - CDocListCtrl
145 // CCapEditT<TBase> - CCapEdit
146 // CTTStaticT<TBase> - CTTStatic
147 // CTTButtonT<TBase> - CTTButton
149 // CSpinCtrlT<TBase> - CSpinCtrl : SmartPhone specific UpDown control
150 // CSpinned<TBase, t_bExpandOnly> : SmartPhone association of control and Spin
151 // CSpinListBox : SmartPhone spinned ListBox control
152 // CExpandListBox : SmartPhone expandable ListBox control
153 // CExpandEdit : SmartPhone expandable Edit control
154 // CExpandCapEdit : SmartPhone expandable CapEdit control
156 // Global functions:
157 // AtlCreateMenuBar()
158 // AtlCreateEmptyMenuBar()
159 // AtlIsEditFocus()
160 // AtlActivateBackKey()
162 namespace WTL
165 ///////////////////////////////////////////////////////////////////////////////
166 // MenuBar creation functions for property sheets and dialogs
167 // Frame windows use CreateSimpleCEMenuBar
169 inline HWND AtlCreateMenuBar(SHMENUBARINFO& mbi)
171 ATLASSERT(::IsWindow(mbi.hwndParent));
172 ATLVERIFY(::SHCreateMenuBar(&mbi) != FALSE);
173 return mbi.hwndMB;
176 inline HWND AtlCreateMenuBar(HWND hWnd, UINT nToolBarId = ATL_IDW_TOOLBAR, DWORD dwFlags = 0, int nBmpId = 0, int cBmpImages = 0, COLORREF clrBk = 0)
178 SHMENUBARINFO mbi = { sizeof(mbi), hWnd, dwFlags, nToolBarId, ModuleHelper::GetResourceInstance(), nBmpId, cBmpImages, 0, clrBk };
179 return AtlCreateMenuBar(mbi);
182 inline HWND AtlCreateEmptyMenuBar(HWND hWnd, bool bSip = true)
184 SHMENUBARINFO embi = { sizeof(SHMENUBARINFO), hWnd, SHCMBF_EMPTYBAR };
185 if (!bSip)
186 embi.dwFlags |= SHCMBF_HIDESIPBUTTON;
188 return AtlCreateMenuBar(embi);
191 ///////////////////////////////////////////////////////////////////////////////
192 // Helper functions for SmartPhone back key handling
194 inline bool AtlIsEditFocus()
196 ATL::CWindow wCtrl = GetFocus();
197 if (wCtrl.IsWindow())
199 TCHAR szClassName[8] = {0};
200 ATLVERIFY(::GetClassName(wCtrl.m_hWnd, szClassName, 8));
201 return !_tcscmp(szClassName, _T("Edit")) || !_tcscmp(szClassName, WC_CAPEDIT);
203 return false;
206 #if defined WIN32_PLATFORM_WFSP
207 inline void AtlActivateBackKey(HWND hMenuBar)
209 ATLASSERT(::IsWindow(hMenuBar));
210 ::SendMessage(hMenuBar, SHCMBM_OVERRIDEKEY, VK_TBACK,
211 MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
213 #endif // WIN32_PLATFORM_WFSP
215 // --- Standard PPC/SmartPhone dialogs ---
217 #ifndef _WTL_CE_NO_DIALOGS
219 ///////////////////////////////////////////////////////////////////////////////
220 // CStdDialogBase - base class for standard PPC/SmartPhone dialogs
222 #define WTL_STD_SHIDIF SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN
223 #define WTL_SP_SHIDIF SHIDIF_SIZEDLGFULLSCREEN
225 // Title setting macros
226 #define WTL_DLG_TITLEHEIGHT(iHeight) static const int GetTitleHeight(){return iHeight;}
227 #define WTL_DLG_NOTITLE WTL_DLG_TITLEHEIGHT(0)
229 ///////////////////////////////////////////////////////////////////////////////
230 // CStdDialogBase - Base class for standard PPC/SmartPhone dialog
232 template <class T, UINT t_shidiFlags, bool t_bModal = true>
233 class CStdDialogBase
235 public:
236 #ifdef WIN32_PLATFORM_PSPC
237 // Pocket PC only Dialog title handling
238 const int nTitleHeight;
240 CStdDialogBase() : nTitleHeight(T::GetTitleHeight())
243 // Overloads
244 BOOL GetClientRect(LPRECT lpRect)
246 T* pT = static_cast<T*>(this);
247 ATLASSERT(pT->IsWindow());
248 BOOL bRes = ::GetClientRect(pT->m_hWnd, lpRect);
249 lpRect->top += nTitleHeight;
250 return bRes;
253 BOOL SetWindowText(LPCTSTR lpszString)
255 T* pT = static_cast<T*>(this);
256 ATLASSERT(pT->IsWindow());
257 BOOL bRes = ::SetWindowText(pT->m_hWnd, lpszString);
258 if (nTitleHeight != 0)
259 pT->DoPaintTitle();
260 return bRes;
263 // Overrideables
264 static const int GetTitleHeight()
266 #ifdef _WTL_CE_DRA
267 return DRA::SCALEY(24);
268 #else // !_WTL_CE_DRA
269 CWindowDC dc(NULL);
270 return dc.GetDeviceCaps(LOGPIXELSY) >> 2; // LOGPIXELSY * 24 / 96,
271 #endif // !_WTL_CE_DRA
274 // Title painting
275 bool DoPaintTitle()
277 T* pT = static_cast<T*>(this);
278 ATLASSERT(pT->IsWindow());
279 TCHAR sTitle[48];
281 // Preparation
282 CPaintDC dc(pT->m_hWnd);
283 CFont fontTitle = AtlCreateBoldFont();
284 CFontHandle fontOld = dc.SelectFont(fontTitle);
285 dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHT));
286 int nLen = pT->GetWindowText(sTitle, 48);
287 int nWidth = dc.GetDeviceCaps(HORZRES);
289 // Display title text
290 RECT rTitle = { 0, 0, nWidth, nTitleHeight };
291 dc.FillRect(&rTitle, COLOR_3DHIGHLIGHT);
292 #ifdef _WTL_CE_DRA
293 rTitle.left = DRA::SCALEX(8);
294 #else // !_WTL_CE_DRA
295 rTitle.left = nTitleHeight / 3; // 8 == 24 / 3
296 #endif // !_WTL_CE_DRA
297 dc.DrawText(sTitle, nLen, &rTitle, DT_VCENTER | DT_SINGLELINE);
298 dc.SelectFont(fontOld);
300 // Draw bottom line, 2 pixels thick if HI_RES_AWARE
301 CPenHandle penOld = dc.SelectStockPen(BLACK_PEN);
302 POINT line[4] = {{0, nTitleHeight}, {nWidth, nTitleHeight}, {0, nTitleHeight - 1}, {nWidth, nTitleHeight - 1}};
304 #ifdef _WTL_CE_DRA
305 int nSeg = DRA::SCALEY(1);
306 #else // !_WTL_CE_DRA
307 int nSeg = nTitleHeight / 24;
308 #endif // !_WTL_CE_DRA
310 dc.Polyline(line, nSeg <= 2 ? nSeg * 2 : 4);
311 dc.SelectPen(penOld);
313 return false;
316 // Title preparation: move the dialog controls down to make room for title
317 void DialogTitleInit()
319 T* pT = static_cast<T*>(this);
320 ATLASSERT(pT->IsWindow());
322 ATL::CWindow wCtl = pT->GetWindow(GW_CHILD);
323 while (wCtl.IsWindow())
325 RECT rCtl = { 0 };
326 wCtl.GetWindowRect(&rCtl);
327 ::MapWindowPoints(NULL, pT->m_hWnd, (LPPOINT)&rCtl, 2);
328 ::OffsetRect(&rCtl, 0, nTitleHeight);
329 wCtl.MoveWindow(&rCtl, FALSE);
330 wCtl = wCtl.GetWindow(GW_HWNDNEXT);
334 // SIP management
335 void DoSipInfo()
337 T* pT = static_cast<T*>(this);
338 ATLASSERT(pT->IsWindow());
340 SIPINFO si = {sizeof(SIPINFO)};
341 SipGetInfo(&si);
342 if ((si.fdwFlags & SIPF_ON) ^ SIPF_ON)
343 si.rcVisibleDesktop.bottom = si.rcSipRect.bottom;
344 pT->MoveWindow(&si.rcVisibleDesktop, FALSE);
347 // Title painting handler
348 LRESULT OnPaintTitle(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
350 T* pT = static_cast<T*>(this);
351 return bHandled = nTitleHeight ? pT->DoPaintTitle() : FALSE;
354 // SIP handler
355 LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
357 T* pT = static_cast<T*>(this);
358 if (wParam == SPI_SETSIPINFO)
360 pT->DoSipInfo();
361 return TRUE;
363 return bHandled = FALSE;
366 #elif defined WIN32_PLATFORM_WFSP
367 // SmartPhone VK_TBACK key standard management
368 LRESULT OnHotKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
370 T* pT = static_cast<T*>(this);
371 const UINT uModif = (UINT)LOWORD(lParam);
372 const UINT uVirtKey = (UINT)HIWORD(lParam);
374 if(uVirtKey == VK_TBACK)
375 if (AtlIsEditFocus())
376 ::SHSendBackToFocusWindow(uMsg, wParam, lParam);
377 else if (uModif & MOD_KEYUP)
378 pT->StdCloseDialog(IDCANCEL);
379 return 1;
382 // SmartPhone MenuBar and VK_TBACK key initialization
383 void StdSPInit()
385 T* pT = static_cast<T*>(this);
386 HWND hMenuBar = ::SHFindMenuBar(pT->m_hWnd);
388 if (!hMenuBar && (t_shidiFlags & SHIDIF_DONEBUTTON))
389 hMenuBar = CreateMenuBar(ATL_IDM_MENU_DONE);
391 if(hMenuBar != NULL)
392 AtlActivateBackKey(hMenuBar);
395 void SetStaticBold()
397 T* pT = static_cast<T*>(this);
398 ATLASSERT(pT->IsWindow());
400 CFontHandle fontBold = AtlCreateBoldFont(pT->GetFont());
402 ATL::CWindow wCtl = pT->GetWindow(GW_CHILD);
404 while (wCtl.IsWindow())
406 if ((short int)wCtl.GetDlgCtrlID() == IDC_STATIC)
407 wCtl.SetFont(fontBold);
408 wCtl = wCtl.GetWindow(GW_HWNDNEXT);
411 #endif // WIN32_PLATFORM_WFSP
413 // Platform dependant initialization
414 void StdPlatformInit()
416 T* pT = static_cast<T*>(this);
417 #ifdef WIN32_PLATFORM_PSPC // Pocket PC title initialization
418 if (nTitleHeight != 0)
419 pT->DialogTitleInit();
420 #elif defined(WIN32_PLATFORM_WFSP)
421 pT->StdSPInit();
422 SetStaticBold();
423 #endif // WIN32_PLATFORM_WFSP
426 // Menu bar creation
427 HWND CreateMenuBar(UINT uiMB = T::IDD, int nBmpImages = 0)
429 T* pT = static_cast<T*>(this);
430 return AtlCreateMenuBar(pT->m_hWnd, uiMB, 0, nBmpImages ? uiMB : 0, nBmpImages);
433 // Dialog closing
434 void StdCloseDialog(WORD wID)
436 T* pT = static_cast<T*>(this);
437 if (t_bModal)
438 ::EndDialog(pT->m_hWnd, wID);
439 else
440 pT->DestroyWindow();
443 // Shell dialog layout initialization
444 void StdShidInit()
446 T* pT = static_cast<T*>(this);
447 SHINITDLGINFO shidi = { SHIDIM_FLAGS, pT->m_hWnd, t_shidiFlags };
448 ::SHInitDialog(&shidi);
451 // IDC_INFOSTATIC background setting
452 LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
454 if (::GetDlgCtrlID((HWND)lParam) == IDC_INFOSTATIC)
456 ::SetBkMode((HDC)wParam, TRANSPARENT);
457 return (LRESULT)::GetSysColorBrush(COLOR_INFOBK);
459 return bHandled = FALSE;
462 // Menu dialog ending
463 LRESULT OnMenuClose(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
465 T* pT = static_cast<T*>(this);
466 pT->StdCloseDialog((WORD)(wID - ID_MENU_OK + IDOK));
467 return 0;
470 // Standard dialog ending: may be used with any command
471 LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
473 T* pT = static_cast<T*>(this);
474 pT->StdCloseDialog(wID);
475 return 0;
480 ///////////////////////////////////////////////////////////////////////////////
481 // CStdDialogImplBase - Base implementation of standard PPC/SmartPhone dialog
483 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true, class TBase = ATL::CDialogImpl< T > >
484 class ATL_NO_VTABLE CStdDialogImplBase :
485 public TBase,
486 public CStdDialogBase<T, t_shidiFlags, t_bModal>
488 public:
489 #ifdef WIN32_PLATFORM_PSPC
490 BOOL GetClientRect(LPRECT lpRect)
492 return CStdDialogBase<T, t_shidiFlags, t_bModal>::GetClientRect(lpRect);
495 BOOL SetWindowText(LPCTSTR lpszString)
497 return CStdDialogBase<T, t_shidiFlags, t_bModal>::SetWindowText(lpszString);
499 #endif
501 BEGIN_MSG_MAP(CStdDialogImplBase)
502 #ifdef WIN32_PLATFORM_PSPC // Pocket PC title and SIP
503 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
504 MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
505 #elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
506 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
507 #endif
508 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
509 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
510 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
511 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
512 END_MSG_MAP()
514 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
516 #ifdef _DEBUG
517 T* pT = static_cast<T*>(this);
518 ATLASSERT(t_bModal == pT->m_bModal);
519 #endif
520 StdPlatformInit();
521 StdShidInit();
522 return bHandled = FALSE;
526 ///////////////////////////////////////////////////////////////////////////////
527 // CStdDialogImpl - implementation of standard PPC/SmartPhone dialog
529 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
530 class ATL_NO_VTABLE CStdDialogImpl : public CStdDialogImplBase< T, t_shidiFlags, t_bModal>
533 ///////////////////////////////////////////////////////////////////////////////
534 // CStdIndirectDialogImpl - implementation of standard indirect PPC/SmartPhone dialog
536 #if defined __ATLDLGS_H__
538 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true>
539 class ATL_NO_VTABLE CStdIndirectDialogImpl :
540 public CIndirectDialogImpl< T, CMemDlgTemplate, CStdDialogImpl<T, t_shidiFlags, t_bModal> >
542 public:
543 typedef CIndirectDialogImpl< T, CMemDlgTemplate, CStdDialogImpl<T, t_shidiFlags, t_bModal> > _baseClass;
544 typedef CStdDialogImpl<T, t_shidiFlags, t_bModal> _baseStd;
546 INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow(), LPARAM dwInitParam = NULL)
548 ATLASSERT(t_bModal);
550 if (!m_Template.IsValid())
551 CreateTemplate();
553 if (m_Template.IsTemplateEx())
555 if (m_Template.GetTemplateExPtr()->style & DS_CENTER)
557 ATLASSERT(m_Template.GetTemplateExPtr()->style ^ WS_CHILD);
558 GetTemplateExPtr()->style |= WS_POPUP;
561 else
563 if (m_Template.GetTemplatePtr()->style & DS_CENTER)
565 ATLASSERT(m_Template.GetTemplatePtr()->style ^ WS_CHILD);
566 m_Template.GetTemplatePtr()->style |= WS_POPUP;
570 return _baseClass::DoModal(hWndParent, dwInitParam);
573 HWND Create(HWND hWndParent, LPARAM dwInitParam = NULL)
575 ATLASSERT(!t_bModal);
577 if (!m_Template.IsValid())
578 CreateTemplate();
580 if (m_Template.IsTemplateEx())
582 if (GetTemplateExPtr()->style & DS_CENTER)
584 ATLASSERT(GetTemplateExPtr()->style ^ WS_CHILD);
585 GetTemplateExPtr()->style |= WS_POPUP;
588 else
590 if (GetTemplatePtr()->style & DS_CENTER)
592 ATLASSERT(GetTemplatePtr()->style ^ WS_CHILD);
593 GetTemplatePtr()->style |= WS_POPUP;
597 return _baseClass::Create(hWndParent, dwInitParam);
600 BEGIN_MSG_MAP(CStdIndirectDialogImpl)
601 CHAIN_MSG_MAP(_baseStd)
602 END_MSG_MAP()
606 #endif // defined __ATLDLGS_H__
608 #ifndef _ATL_NO_HOSTING
610 ///////////////////////////////////////////////////////////////////////////////
611 // CStdAxDialogImpl - implementation of standard PPC/SmartPhone AxDialog
613 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
614 class ATL_NO_VTABLE CStdAxDialogImpl : public CStdDialogImplBase< T, t_shidiFlags, t_bModal, ATL::CAxDialogImpl< T > >
616 #endif // _ATL_NO_HOSTING
618 ///////////////////////////////////////////////////////////////////////////////
619 // CStdSimpleDialog - standard PPC/SmartPhone simple dialog with SHIDIF_xxx flags
621 template <WORD t_wDlgTemplateID, UINT t_shidiFlags = WTL_STD_SHIDIF>
622 class CStdSimpleDialog :
623 public ATL::CSimpleDialog<t_wDlgTemplateID, FALSE>,
624 public CStdDialogBase<CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>, t_shidiFlags>
626 public:
627 typedef CStdDialogBase<CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>, t_shidiFlags> baseClass;
629 #ifdef WIN32_PLATFORM_PSPC
630 BOOL GetClientRect(LPRECT lpRect)
632 return baseClass::GetClientRect(lpRect);
635 BOOL SetWindowText(LPCTSTR lpszString)
637 return baseClass::SetWindowText(lpszString);
639 #endif
641 BEGIN_MSG_MAP(CStdSimpleDialog)
642 #ifdef WIN32_PLATFORM_PSPC // Pocket PC title and SIP
643 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
644 MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
645 #elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
646 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
647 #endif
648 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
649 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
650 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
651 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, baseClass::OnCloseCmd)
652 END_MSG_MAP()
654 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
656 StdPlatformInit();
657 StdShidInit();
658 return bHandled = FALSE;
662 ///////////////////////////////////////////////////////////////////////////////
663 // CStdDialogResizeImplBase - Base implementation of orientation resizing standard PPC/SmartPhone dialog
665 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true, class TBase = ATL::CDialogImpl<T> >
666 class ATL_NO_VTABLE CStdDialogResizeImplBase :
667 public CStdDialogImplBase< T, t_shidiFlags, t_bModal, TBase>,
668 public CDialogResize<T>
670 public:
671 // Note: BEGIN_DLGRESIZE_MAP is required in the derived class.
673 BEGIN_MSG_MAP(CStdResizeDialogImplBase)
674 #ifdef WIN32_PLATFORM_PSPC // Pocket PC title
675 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
676 #elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
677 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
678 #endif
679 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
680 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
681 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
682 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
683 CHAIN_MSG_MAP(CDialogResize< T >)
684 END_MSG_MAP()
686 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
688 #ifdef _DEBUG
689 T* pT = static_cast<T*>(this);
690 ATLASSERT(t_bModal == pT->m_bModal);
691 #endif
692 StdPlatformInit();
693 DlgResize_Init(FALSE);
694 StdShidInit();
695 return bHandled = FALSE;
699 ///////////////////////////////////////////////////////////////////////////////
700 // CStdDialogResizeImpl - implementation of orientation resizing standard PPC/SmartPhone dialog
702 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
703 class ATL_NO_VTABLE CStdDialogResizeImpl : public CStdDialogResizeImplBase< T, t_shidiFlags, t_bModal>
706 #ifndef _ATL_NO_HOSTING
708 ///////////////////////////////////////////////////////////////////////////////
709 // CStdAxDialogResizeImpl - implementation of orientation resizing standard PPC/SmartPhone AxDialog
711 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
712 class ATL_NO_VTABLE CStdAxDialogResizeImpl : public CStdDialogResizeImplBase< T, t_shidiFlags, t_bModal, ATL::CAxDialogImpl<T> >
714 #endif // _ATL_NO_HOSTING
716 ///////////////////////////////////////////////////////////////////////////////
717 // CStdSimpleDialogResizeImpl - implementation of standard resizing simple dialog with SHIDIF_xxx flags
719 // Usage:
720 // class CMyDlg : public CStdSimpleDialogResize<CMyDlg,
721 // IDD_MYDLG, SHIDIF_DONEBUTTON | SHIDIF_FULLSCREENNOMENUBAR>
722 // {
723 // public:
724 // BEGIN_DLGRESIZE_MAP(CMyDlg)
725 // ...
726 // END_DLGRESIZE_MAP()
727 // };
729 template <class T, WORD t_wDlgTemplateID, UINT t_shidiFlags = WTL_STD_SHIDIF>
730 class ATL_NO_VTABLE CStdSimpleDialogResizeImpl :
731 public CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>,
732 public CDialogResize< T >
734 public:
735 typedef CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>::baseClass baseClass;
737 BEGIN_MSG_MAP(CStdSimpleDialogResizeImpl)
738 #ifdef WIN32_PLATFORM_PSPC // Pocket PC title
739 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
740 #elif defined(WIN32_PLATFORM_WFSP) // SmartPhone VK_TBACK key
741 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
742 #endif
743 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
744 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
745 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, baseClass::OnCloseCmd)
746 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
747 CHAIN_MSG_MAP(CDialogResize< T >)
748 END_MSG_MAP()
750 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
752 StdPlatformInit();
753 DlgResize_Init(FALSE);
754 StdShidInit();
755 return bHandled = FALSE;
759 #if defined(_WTL_CE_DRA) && defined(WIN32_PLATFORM_PSPC)
761 ///////////////////////////////////////////////////////////////////////////////
762 // CStdOrientedDialogBase - Oriented PPC standard dialog base class
764 template <class T>
765 class CStdOrientedDialogBase
767 public:
768 // Operation
769 BOOL SetOrientation(DRA::DisplayMode mode)
771 T* pT = static_cast<T*>(this);
772 ATLASSERT(pT->IsWindow());
773 ATLASSERT(mode == DRA::GetDisplayMode());
775 // Derived dialog must enumerate TWO dialog templates with the same control ids and types ie:
776 // enum { IDD = IDD_MYDLG, IDD_LANDSCAPE = IDD_MYDLG_L };
777 UINT iResource = (mode == DRA::Landscape)? T::IDD_LANDSCAPE : T::IDD;
779 BOOL bRes = DRA::RelayoutDialog(ModuleHelper::GetResourceInstance(), pT->m_hWnd, MAKEINTRESOURCE(iResource));
780 pT->OnOrientation(mode);
781 return bRes;
784 // Override
785 void OnOrientation(DRA::DisplayMode /*mode*/)
788 // Message handlers
789 LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
791 T* pT = static_cast<T*>(this);
792 ATLASSERT(pT->IsWindow());
793 if (wParam == SETTINGCHANGE_RESET)
795 SetOrientation(DRA::GetDisplayMode());
796 pT->StdPlatformInit();
797 pT->StdShidInit();
799 else if (wParam == SPI_SETSIPINFO)
801 pT->DoSipInfo();
802 return TRUE;
804 return bHandled = FALSE;
808 ///////////////////////////////////////////////////////////////////////////////
809 // CStdOrientedDialogImplBase - Oriented PPC standard dialog base implementation
811 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true, class TBase = ATL::CDialogImpl<T> >
812 class ATL_NO_VTABLE CStdOrientedDialogImplBase :
813 public CStdDialogImplBase< T, t_shidiFlags, t_bModal, TBase>,
814 public CStdOrientedDialogBase<T>
816 public:
817 BEGIN_MSG_MAP(CStdOrientedDialogImpl)
818 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
819 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
820 MESSAGE_HANDLER(WM_SETTINGCHANGE, CStdOrientedDialogBase<T>::OnSettingChange)
821 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
822 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd)
823 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
824 END_MSG_MAP()
826 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
828 T* pT = static_cast<T*>(this);
829 #ifdef _DEBUG
830 ATLASSERT(t_bModal == pT->m_bModal);
831 #endif
832 if (DRA::GetDisplayMode() == DRA::Landscape)
833 SetOrientation(DRA::Landscape);
834 pT->StdPlatformInit();
835 pT->StdShidInit();
836 return bHandled = FALSE;
840 ///////////////////////////////////////////////////////////////////////////////
841 // CStdOrientedDialogImpl - Oriented PPC standard dialog implementation
843 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
844 class ATL_NO_VTABLE CStdOrientedDialogImpl : public CStdOrientedDialogImplBase< T, t_shidiFlags, t_bModal>
847 #ifndef _ATL_NO_HOSTING
848 ///////////////////////////////////////////////////////////////////////////////
849 // CStdAxOrientedDialogImpl - Oriented PPC standard AxDialog implementation
851 template <class T, UINT t_shidiFlags = WTL_STD_SHIDIF, bool t_bModal = true >
852 class ATL_NO_VTABLE CStdAxOrientedDialogImpl : public CStdOrientedDialogImplBase< T, t_shidiFlags, t_bModal, ATL::CAxDialogImpl<T> >
854 #endif // _ATL_NO_HOSTING
856 ///////////////////////////////////////////////////////////////////////////////
857 // CStdSimpleOrientedDialog - Standard simple orientable dialog
859 template <WORD t_wDlgTemplateID, WORD t_wDlgLandscapeID, UINT t_shidiFlags = WTL_STD_SHIDIF>
860 class CStdSimpleOrientedDialog :
861 public CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>,
862 public CStdOrientedDialogBase<CStdSimpleOrientedDialog<t_wDlgTemplateID, t_wDlgLandscapeID, t_shidiFlags> >
864 public:
865 typedef CStdSimpleDialog<t_wDlgTemplateID, t_shidiFlags>::baseClass baseClass;
866 typedef CStdOrientedDialogBase<CStdSimpleOrientedDialog<t_wDlgTemplateID, t_wDlgLandscapeID, t_shidiFlags> > baseOriented;
868 enum {IDD = t_wDlgTemplateID, IDD_LANDSCAPE = t_wDlgLandscapeID};
870 BEGIN_MSG_MAP(CStdSimpleDialog)
871 MESSAGE_HANDLER(WM_PAINT, OnPaintTitle)
872 MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
873 MESSAGE_HANDLER(WM_SETTINGCHANGE, baseOriented::OnSettingChange)
874 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
875 COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, baseClass::OnCloseCmd)
876 COMMAND_RANGE_HANDLER(ID_MENU_OK, ID_MENU_CANCEL, OnMenuClose)
877 END_MSG_MAP()
879 LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
881 if (DRA::GetDisplayMode() == DRA::Landscape)
882 SetOrientation(DRA::Landscape);
883 StdPlatformInit();
884 StdShidInit();
885 return bHandled = FALSE;
889 #endif // _WTL_CE_DRA
892 #endif // _WTL_CE_NO_DIALOGS
895 // --- PPC/SmartPhone application window and helpers ---
897 #ifndef _WTL_CE_NO_APPWINDOW
899 ///////////////////////////////////////////////////////////////////////////////
900 // CAppInfoBase - Helper for application state save/restore to registry
902 class CAppInfoBase
904 public:
905 ATL::CRegKey m_Key;
907 CAppInfoBase(ATL::_U_STRINGorID sAppKey)
909 m_Key.Create(HKEY_CURRENT_USER, sAppKey.m_lpstr);
910 ATLASSERT(m_Key.m_hKey);
913 template <class V>
914 LONG Save(V& val, ATL::_U_STRINGorID sName)
916 return ::RegSetValueEx(m_Key, sName.m_lpstr, 0, REG_BINARY, (LPBYTE)&val, sizeof(V));
919 template <class V>
920 LONG Save(int nb, V& val0, ATL::_U_STRINGorID sName)
922 return ::RegSetValueEx(m_Key, sName.m_lpstr, 0, REG_BINARY, (LPBYTE)&val0, nb * sizeof(V));
925 template <class V>
926 LONG Restore(V& val, ATL::_U_STRINGorID sName)
928 DWORD valtype;
929 DWORD bufSize = sizeof(V);
930 return ::RegQueryValueEx(m_Key, sName.m_lpstr, 0, &valtype, (LPBYTE)&val, &bufSize);
933 template <class V>
934 LONG Restore(int nb, V& val0, ATL::_U_STRINGorID sName)
936 DWORD valtype;
937 DWORD bufSize = nb * sizeof(V);
938 return ::RegQueryValueEx(m_Key, sName.m_lpstr, 0, &valtype, (LPBYTE)&val0, &bufSize);
941 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
942 #if (_ATL_VER < 0x0800)
943 LONG Save(_CSTRING_NS::CString& sval, ATL::_U_STRINGorID sName)
945 return m_Key.SetValue(sval, sName.m_lpstr);
948 LONG Restore(_CSTRING_NS::CString& sval, ATL::_U_STRINGorID sName)
950 DWORD size = MAX_PATH;
951 LONG res = m_Key.QueryValue(sval.GetBuffer(size), sName.m_lpstr, &size);
952 sval.ReleaseBuffer();
953 return res;
955 #else // !(_ATL_VER < 0x0800)
956 LONG Save(_CSTRING_NS::CString& sval, ATL::_U_STRINGorID sName)
958 return m_Key.SetStringValue(sName.m_lpstr, sval);
961 LONG Restore(_CSTRING_NS::CString& sval, ATL::_U_STRINGorID sName)
963 DWORD size = MAX_PATH;
964 LONG res = m_Key.QueryStringValue(sName.m_lpstr, sval.GetBuffer(size), &size);
965 sval.ReleaseBuffer();
966 return res;
968 #endif // !(_ATL_VER < 0x0800)
969 #else
970 #pragma message("Warning: CAppInfoBase compiles without CString support. Do not use CString in Save or Restore.")
971 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
973 #if (_ATL_VER < 0x0800)
974 LONG Save(LPCTSTR sval, ATL::_U_STRINGorID sName)
976 return m_Key.SetValue(sval, sName.m_lpstr);
979 LONG Restore(LPTSTR sval, ATL::_U_STRINGorID sName, DWORD *plength)
981 return m_Key.QueryValue(sval, sName.m_lpstr, plength);
983 #else // !(_ATL_VER < 0x0800)
984 LONG Save(LPCTSTR sval, ATL::_U_STRINGorID sName)
986 return m_Key.SetStringValue(sName.m_lpstr, sval);
989 LONG Restore(LPTSTR sval, ATL::_U_STRINGorID sName, DWORD *plength)
991 return m_Key.QueryStringValue(sName.m_lpstr, sval, plength);
993 #endif // !(_ATL_VER < 0x0800)
995 LONG Delete(ATL::_U_STRINGorID sName)
997 return m_Key.DeleteValue(sName.m_lpstr);
1002 ///////////////////////////////////////////////////////////////////////////////
1003 // CAppInfoT - CAppInfoBase constructed from a class with T::GetAppKey()
1005 // Macro for declaring AppKey
1006 #define DECLARE_APPKEY(uAppKey) \
1007 static LPCTSTR GetAppKey() \
1009 static LPCTSTR sAppKey = ATL::_U_STRINGorID(uAppKey).m_lpstr; \
1010 return sAppKey; \
1013 template <class T>
1014 class CAppInfoT : public CAppInfoBase
1016 public:
1017 CAppInfoT() : CAppInfoBase(T::GetAppKey()){}
1021 ///////////////////////////////////////////////////////////////////////////////
1022 // CAppWindowBase - Base class for PPC/SmartPhone "well-behaved" application window or dialog
1024 // Macros for declaring frame WNDCLASS and AppKey
1025 #define DECLARE_APP_FRAME_CLASS(WndClassName, uCommonResourceID, uAppKey) \
1026 DECLARE_FRAME_WND_CLASS(WndClassName, uCommonResourceID) \
1027 DECLARE_APPKEY(uAppKey)
1029 #define DECLARE_APP_FRAME_CLASS_EX(WndClassName, uCommonResourceID, style, bkgnd, uAppKey) \
1030 DECLARE_FRAME_WND_CLASS_EX(WndClassName, uCommonResourceID, style, bkgnd) \
1031 DECLARE_APPKEY(uAppKey)
1033 template <class T>
1034 class CAppWindowBase
1036 public:
1037 typedef class CAppInfoT< T > CAppInfo;
1039 #ifndef WIN32_PLATFORM_WFSP
1040 SHACTIVATEINFO m_sai; // NoOp on SmartPhones
1041 #endif // WIN32_PLATFORM_WFSP
1043 bool m_bHibernate;
1045 CAppWindowBase< T >() : m_bHibernate(false)
1047 #ifndef WIN32_PLATFORM_WFSP
1048 SHACTIVATEINFO sai = { sizeof(SHACTIVATEINFO) };
1049 m_sai = sai;
1050 #endif // WIN32_PLATFORM_WFSP
1053 // Same as WTL 7.1 AppWizard generated ActivatePreviousInstance + SendMessage WM_COPYDATA
1054 static HRESULT ActivatePreviousInstance(HINSTANCE hInstance, LPCTSTR lpstrCmdLine, bool bDialog)
1056 // requires T does DECLARE_APP_FRAME_CLASS, DECLARE_APP_FRAME_CLASS_EX or DECLARE_APP_DLG_CLASS
1057 CFrameWndClassInfo& classInfo = T::GetWndClassInfo();
1059 ATLVERIFY(::LoadString(hInstance, classInfo.m_uCommonResourceID, classInfo.m_szAutoName, sizeof(classInfo.m_szAutoName)/sizeof(classInfo.m_szAutoName[0])) != 0);
1061 classInfo.m_wc.lpszClassName = classInfo.m_szAutoName;
1063 const TCHAR* pszClass = classInfo.m_wc.lpszClassName;
1065 if(NULL == pszClass || '\0' == *pszClass)
1067 return E_FAIL;
1070 const DWORD dRetryInterval = 100;
1071 const int iMaxRetries = 25;
1073 for(int i = 0; i < iMaxRetries; ++i)
1075 HANDLE hMutex = CreateMutex(NULL, FALSE, pszClass);
1077 DWORD dw = GetLastError();
1079 if(NULL == hMutex)
1081 HRESULT hr;
1083 switch(dw)
1085 case ERROR_INVALID_HANDLE:
1086 // A non-mutext object with this name already exists.
1087 hr = E_INVALIDARG;
1088 break;
1089 default:
1090 // This should never happen...
1091 hr = E_FAIL;
1094 return hr;
1097 // If the mutex already exists, then there should be another instance running
1098 if(dw == ERROR_ALREADY_EXISTS)
1100 CloseHandle(hMutex);
1102 HWND hwnd = NULL;
1103 if (bDialog)
1104 hwnd = FindWindow(NULL, pszClass);
1105 else
1106 hwnd = FindWindow(pszClass, NULL);
1108 if(hwnd == NULL)
1110 Sleep(dRetryInterval);
1111 continue;
1113 else
1115 // Transmit our params to previous instance
1116 if (lpstrCmdLine && *lpstrCmdLine)
1118 COPYDATASTRUCT cd = { NULL, sizeof(TCHAR) * (wcslen(lpstrCmdLine) + 1), (PVOID)lpstrCmdLine };
1119 ::SendMessage(hwnd, WM_COPYDATA, NULL, (LPARAM)&cd);
1121 // Set the previous instance as the foreground window
1122 if(0 != SetForegroundWindow(reinterpret_cast<HWND>(reinterpret_cast<ULONG>(hwnd) | 0x1)))
1123 return S_FALSE;
1126 else
1128 return S_OK;
1131 return S_OK;
1134 // Operations overriden in derived class
1135 bool AppHibernate(bool /*bHibernate*/)
1137 return false;
1140 bool AppNewInstance(LPCTSTR /*lpstrCmdLine*/)
1142 return false;
1145 void AppSave()
1149 #ifdef WIN32_PLATFORM_WFSP
1150 void AppBackKey()
1152 ::SHNavigateBack();
1154 #endif
1156 // Message map and handlers
1157 BEGIN_MSG_MAP(CAppWindowBase)
1158 MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
1159 #ifdef WIN32_PLATFORM_WFSP
1160 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
1161 #else
1162 MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
1163 #endif // WIN32_PLATFORM_WFSP
1164 MESSAGE_HANDLER(WM_HIBERNATE, OnHibernate)
1165 MESSAGE_HANDLER(WM_COPYDATA, OnNewInstance)
1166 MESSAGE_HANDLER(WM_CLOSE, OnClose)
1167 END_MSG_MAP()
1169 LRESULT OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1171 T* pT = static_cast<T*>(this);
1172 if (m_bHibernate)
1173 m_bHibernate = pT->AppHibernate(false);
1174 #ifndef WIN32_PLATFORM_WFSP
1175 ::SHHandleWMActivate(pT->m_hWnd, wParam, lParam, &m_sai, 0);
1176 #else
1177 wParam;
1178 lParam;
1179 #endif // WIN32_PLATFORM_WFSP
1180 return bHandled = FALSE;
1183 #ifdef WIN32_PLATFORM_WFSP
1184 // SmartPhone VK_TBACK key standard management
1185 LRESULT OnHotKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
1187 T* pT = static_cast<T*>(this);
1188 const UINT uModif = (UINT)LOWORD(lParam);
1189 const UINT uVirtKey = (UINT)HIWORD(lParam);
1190 if(uVirtKey == VK_TBACK)
1191 if (AtlIsEditFocus())
1192 ::SHSendBackToFocusWindow(uMsg, wParam, lParam);
1193 else if (uModif & MOD_KEYUP)
1194 pT->AppBackKey();
1195 return 1;
1198 #else // !WIN32_PLATFORM_WFSP
1199 // PPC SIP handling
1200 LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1202 T* pT = static_cast<T*>(this);
1203 bHandled = FALSE;
1204 return ::SHHandleWMSettingChange(pT->m_hWnd, wParam, lParam, &m_sai);
1206 #endif // !WIN32_PLATFORM_WFSP
1208 LRESULT OnHibernate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
1210 T* pT = static_cast<T*>(this);
1211 return m_bHibernate = pT->AppHibernate(true);
1214 LRESULT OnNewInstance(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
1216 T* pT = static_cast<T*>(this);
1217 PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)lParam;
1218 return pT->AppNewInstance((LPCTSTR)pcds->lpData);
1221 LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
1223 T* pT = static_cast<T*>(this);
1224 pT->AppSave();
1225 bHandled = FALSE;
1226 return 1;
1231 ///////////////////////////////////////////////////////////////////////////////
1232 // CAppWindow - PPC/SmartPhone "well-behaved" application window class
1234 template <class T>
1235 class CAppWindow : public CAppWindowBase< T >
1237 public:
1238 // Same as WTL 7.1 AppWizard generated Run + lpstrCmdLine in CreateEx
1239 static int AppRun(LPTSTR lpstrCmdLine = NULL, int nCmdShow = SW_SHOWNORMAL)
1241 CMessageLoop theLoop;
1242 _Module.AddMessageLoop(&theLoop);
1244 T wndMain;
1246 if(wndMain.CreateEx(NULL, NULL, 0, 0, lpstrCmdLine) == NULL)
1248 ATLTRACE2(atlTraceUI, 0, _T("Main window creation failed!\n"));
1249 return 0;
1252 wndMain.ShowWindow(nCmdShow);
1254 int nRet = theLoop.Run();
1256 _Module.RemoveMessageLoop();
1257 return nRet;
1260 static HRESULT ActivatePreviousInstance(HINSTANCE hInstance, LPCTSTR lpstrCmdLine)
1262 return CAppWindowBase< T >::ActivatePreviousInstance(hInstance, lpstrCmdLine, false);
1267 #ifndef _WTL_CE_NO_DIALOGS
1269 ///////////////////////////////////////////////////////////////////////////////
1270 // CAppDialog - PPC/SmartPhone "well-behaved" dialog application class
1272 // Macro for declaring dialog WNDCLASS and AppKey
1273 #define DECLARE_APP_DLG_CLASS(WndClassName, uCommonResourceID, uAppKey) \
1274 static WTL::CFrameWndClassInfo& GetWndClassInfo() \
1276 static WTL::CFrameWndClassInfo wc = \
1278 { 0, (WNDPROC)StartDialogProc, \
1279 0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, WndClassName }, \
1280 NULL, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
1281 }; \
1282 return wc; \
1283 }; \
1284 DECLARE_APPKEY(uAppKey)
1286 template <class T>
1287 class CAppDialog : public CAppWindowBase< T >
1289 public:
1290 static int AppRun(LPTSTR lpstrCmdLine = NULL, int nCmdShow = SW_SHOWNORMAL)
1292 CMessageLoop theLoop;
1293 _Module.AddMessageLoop(&theLoop);
1295 T dlgMain;
1297 if(dlgMain.Create(NULL, (LPARAM)lpstrCmdLine) == NULL)
1299 ATLTRACE2(atlTraceUI, 0, _T("Main dialog creation failed!\n"));
1300 return 0;
1303 dlgMain.ShowWindow(nCmdShow);
1305 int nRet = theLoop.Run();
1307 _Module.RemoveMessageLoop();
1308 return nRet;
1311 static HRESULT ActivatePreviousInstance(HINSTANCE hInstance, LPCTSTR lpstrCmdLine)
1313 return CAppWindowBase< T >::ActivatePreviousInstance(hInstance, lpstrCmdLine, true);
1317 // PPC/SmartPhone standard application dialogs
1319 #ifdef WIN32_PLATFORM_WFSP
1320 #define WTL_APP_SHIDIF WTL_SP_SHIDIF
1321 #else
1322 #define WTL_APP_SHIDIF WTL_STD_SHIDIF
1323 #endif
1325 ///////////////////////////////////////////////////////////////////////////////
1326 // CAppStdDialogImplBase - Base implementation of standard application dialogs
1328 template <class T, class TImplBase, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1329 class ATL_NO_VTABLE CAppStdDialogImplBase :
1330 public TImplBase,
1331 public CAppDialog< T >
1333 public:
1334 WTL_DLG_NOTITLE;
1336 void StdCloseDialog(int nVal)
1338 T* pT = static_cast<T*>(this);
1339 if (nVal != IDCANCEL)
1340 pT->AppSave();
1341 if (t_bModal == false)
1343 pT->DestroyWindow();
1344 ::PostQuitMessage(nVal);
1346 else
1347 ::EndDialog(pT->m_hWnd, nVal);
1350 BEGIN_MSG_MAP(CAppStdDialogImplBase)
1351 MESSAGE_HANDLER(WM_CLOSE, OnSystemClose)
1352 CHAIN_MSG_MAP(TImplBase)
1353 CHAIN_MSG_MAP(CAppDialog< T >)
1354 END_MSG_MAP()
1356 LRESULT OnSystemClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
1358 T* pT = static_cast<T*>(this);
1359 pT->StdCloseDialog(IDCANCEL);
1360 return 0;
1364 ///////////////////////////////////////////////////////////////////////////////
1365 // CAppStdDialogImpl - Implementation of standard application dialog
1367 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1368 class ATL_NO_VTABLE CAppStdDialogImpl :
1369 public CAppStdDialogImplBase<T, CStdDialogImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1372 ///////////////////////////////////////////////////////////////////////////////
1373 // CAppStdDialogResizeImpl - implementation of orientation resizing standard application dialog
1375 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1376 class ATL_NO_VTABLE CAppStdDialogResizeImpl :
1377 public CAppStdDialogImplBase<T, CStdDialogResizeImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1380 #ifndef _ATL_NO_HOSTING
1381 ///////////////////////////////////////////////////////////////////////////////
1382 // CAppStdAxDialogImpl - Implementation of standard application AxDialog
1384 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1385 class ATL_NO_VTABLE CAppStdAxDialogImpl :
1386 public CAppStdDialogImplBase<T, CStdAxDialogImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1389 ///////////////////////////////////////////////////////////////////////////////
1390 // CAppStdAxDialogResizeImpl - implementation of orientation resizing standard application AxDialog
1392 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1393 class ATL_NO_VTABLE CAppStdAxDialogResizeImpl :
1394 public CAppStdDialogImplBase<T, CStdAxDialogResizeImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1396 #endif // _ATL_NO_HOSTING
1398 #if defined(_WTL_CE_DRA) && defined(WIN32_PLATFORM_PSPC)
1399 ///////////////////////////////////////////////////////////////////////////////
1400 // CAppStdOrientedDialogImpl - implementation of oriented PPC standard application dialog
1402 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1403 class ATL_NO_VTABLE CAppStdOrientedDialogImpl :
1404 public CAppStdDialogImplBase<T, CStdOrientedDialogImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1407 #ifndef _ATL_NO_HOSTING
1408 ///////////////////////////////////////////////////////////////////////////////
1409 // CAppStdAxOrientedDialogImpl - implementation of oriented PPC standard application AxDialog
1411 template <class T, UINT t_shidiFlags = WTL_APP_SHIDIF, bool t_bModal = false>
1412 class ATL_NO_VTABLE CAppStdAxOrientedDialogImpl :
1413 public CAppStdDialogImplBase<T, CStdAxOrientedDialogImpl<T, t_shidiFlags, t_bModal>, t_shidiFlags, t_bModal>
1415 #endif // _ATL_NO_HOSTING
1417 #endif // defined(_WTL_CE_DRA) && defined(WIN32_PLATFORM_PSPC)
1419 #endif // _WTL_CE_NO_DIALOGS
1421 #endif // _WTL_CE_NO_APPWINDOW
1424 // --- Full screen support ---
1426 #ifndef _WTL_CE_NO_FULLSCREEN
1428 ///////////////////////////////////////////////////////////////////////////////
1429 // CFullScreenFrame - full screen frame implementation
1431 template <class T, bool t_bHasSip = true>
1432 class CFullScreenFrame
1434 public:
1435 bool m_bFullScreen;
1437 CFullScreenFrame() : m_bFullScreen(false)
1440 // Operation
1441 void SetFullScreen(bool bFull)
1443 m_bFullScreen = bFull;
1444 ShowTaskBar(!bFull, false);
1445 ShowMenuBar(!bFull);
1448 // Manage TaskBar for modal dialogs and property sheets
1449 template <class D>
1450 int FSDoModal(D& dlg)
1452 T* pT = static_cast<T*>(this);
1453 pT; // avoid level 4 warning
1454 ATLASSERT(pT->IsWindow());
1455 if (m_bFullScreen) // Show taskbar if hidden
1456 ShowTaskBar(true, false);
1457 int iRet = dlg.DoModal();
1458 if (m_bFullScreen) // Hide taskbar if restored
1459 ShowTaskBar(false);
1460 return iRet;
1463 // Implementation
1464 void ShowMenuBar(bool bShow)
1466 T* pT = static_cast<T*>(this);
1467 ATLASSERT(pT->IsWindow());
1468 ATL::CWindow MenuBar = pT->m_hWndCECommandBar;
1469 ATLASSERT(MenuBar.IsWindow());
1470 MenuBar.ShowWindow(bShow ? SW_SHOWNORMAL : SW_HIDE);
1471 pT->SizeToMenuBar();
1474 void ShowTaskBar(bool bShow, bool bRepaint = true)
1476 T* pT = static_cast<T*>(this);
1477 ATLASSERT(pT->IsWindow());
1478 RECT rect = { 0 };
1479 SystemParametersInfo(SPI_GETWORKAREA, NULL, &rect, FALSE);
1480 if (!bShow)
1481 rect.top = 0;
1483 #ifdef WIN32_PLATFORM_PSPC // Pocket PC code
1484 UINT uShow = t_bHasSip ? SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON : SHFS_SHOWTASKBAR | SHFS_HIDESIPBUTTON;
1485 SHFullScreen(pT->m_hWnd, bShow ? uShow : SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
1486 #elif _WIN32_WCE > 0x500 // Smartphone 2005 code
1487 SHFullScreen(pT->m_hWnd, bShow ? SHFS_SHOWTASKBAR : SHFS_HIDETASKBAR);
1488 #else // Smartphone 2003
1489 HWND hTaskBar = FindWindow(_T("tray"), NULL);
1490 ATLASSERT(::IsWindow(hTaskBar));
1491 ::ShowWindow(hTaskBar, bShow ? SW_SHOW : SW_HIDE);
1492 #endif // WIN32_PLATFORM_PSPC
1494 pT->MoveWindow(&rect, bRepaint);
1497 // Message map and handler
1498 BEGIN_MSG_MAP(CFullScreenFrame)
1499 MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
1500 MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
1501 END_MSG_MAP()
1503 LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
1505 #ifndef SETTINGCHANGE_RESET // not defined for PPC 2002
1506 #define SETTINGCHANGE_RESET SPI_SETWORKAREA
1507 #endif
1508 if (m_bFullScreen && (wParam & SETTINGCHANGE_RESET))
1509 SetFullScreen(m_bFullScreen);
1510 return bHandled = FALSE;
1513 LRESULT OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
1515 if (m_bFullScreen)
1517 ShowTaskBar(!wParam);
1518 ShowMenuBar(!wParam);
1520 return bHandled = FALSE;
1524 #endif // _WTL_CE_NO_FULLSCREEN
1527 // --- WinCE zoom support ---
1529 #ifndef _WTL_CE_NO_ZOOMSCROLL
1531 ///////////////////////////////////////////////////////////////////////////////
1532 // CZoomScrollImpl - WinCE zooming implementation on top of CScrollImpl
1534 template <class T>
1535 class CZoomScrollImpl: public CScrollImpl< T >
1537 public:
1538 // Data members
1539 _WTYPES_NS::CSize m_sizeTrue;
1540 double m_fzoom;
1542 // Creation
1543 CZoomScrollImpl() : m_sizeTrue(0), m_fzoom(1.)
1546 // Zoom operations and access
1547 void SetZoomScrollSize(_WTYPES_NS::CSize sizeTrue, double fzoom = 1., BOOL bRedraw = TRUE)
1549 ATLASSERT(fzoom > 0.);
1550 m_sizeTrue = sizeTrue;
1551 m_fzoom = fzoom;
1553 CScrollImpl< T >::SetScrollSize(sizeTrue / fzoom, bRedraw);
1556 void SetZoomScrollSize(int cx, int cy, double fzoom=1., BOOL bRedraw = TRUE)
1558 SetZoomScrollSize(_WTYPES_NS::CSize(cx, cy), fzoom, bRedraw);
1561 void SetZoom(double fzoom, BOOL bRedraw = TRUE)
1563 _WTYPES_NS::CPoint ptCenter = WndtoTrue(m_sizeClient / 2);
1564 _WTYPES_NS::CSize sizePage = GetScrollPage();
1565 _WTYPES_NS::CSize sizeLine = GetScrollLine();
1567 SetZoomScrollSize(GetScrollSize(), fzoom, bRedraw);
1569 SetScrollLine(sizeLine);
1570 SetScrollPage(sizePage);
1571 _WTYPES_NS::CPoint ptOffset = ptCenter - (m_sizeClient / 2) * fzoom;
1572 SetScrollOffset(ptOffset, bRedraw);
1575 double GetZoom()
1577 return m_fzoom;
1580 // CScrollImpl overrides
1581 void SetScrollOffset(int x, int y, BOOL bRedraw = TRUE)
1583 CScrollImpl< T >::SetScrollOffset((int)(x / m_fzoom), (int)(y / m_fzoom), bRedraw);
1586 void SetScrollOffset(POINT ptOffset, BOOL bRedraw = TRUE)
1588 SetScrollOffset(ptOffset.x, ptOffset.y, bRedraw);
1591 void GetScrollOffset(POINT& ptOffset)
1593 ptOffset.x = (LONG)(m_ptOffset.x * m_fzoom);
1594 ptOffset.y = (LONG)(m_ptOffset.y * m_fzoom);
1597 void SetScrollSize(int cx, int cy, BOOL bRedraw = TRUE)
1599 SetZoomScrollSize(cx, cy, GetZoom(), bRedraw);
1602 void SetScrollSize(SIZE sizeTrue, BOOL bRedraw = TRUE)
1604 SetZoomScrollSize(sizeTrue, GetZoom(), bRedraw);
1607 void GetScrollSize(SIZE& sizeTrue) const
1609 sizeTrue = m_sizeTrue;
1612 void SetScrollPage(int cxPage, int cyPage)
1614 SetScrollPage(_WTYPES_NS::CSize(cxPage, cyPage));
1617 void SetScrollPage(SIZE sizePage)
1619 CScrollImpl< T >::SetScrollPage(sizePage / m_fzoom);
1622 void GetScrollPage(SIZE& sizePage) const
1624 sizePage = m_sizePage * m_fzoom;
1627 void SetScrollLine(int cxLine, int cyLine)
1629 SetScrollLine(_WTYPES_NS::CSize(cxLine, cyLine));
1632 void SetScrollLine(SIZE sizeLine)
1634 CScrollImpl< T >::SetScrollLine(sizeLine / m_fzoom);
1637 void GetScrollLine(SIZE& sizeLine) const
1639 sizeLine = m_sizeLine * m_fzoom;
1642 // Data access complements
1643 _WTYPES_NS::CSize GetScrollSize()
1645 return m_sizeTrue;
1648 _WTYPES_NS::CSize GetScrollPage()
1650 return m_sizePage * m_fzoom;
1653 _WTYPES_NS::CSize GetScrollLine()
1655 return m_sizeLine * m_fzoom;
1658 _WTYPES_NS::CPoint GetScrollOffset()
1660 return (_WTYPES_NS::CSize)m_ptOffset * m_fzoom;
1663 // Helper coordinate functions
1664 _WTYPES_NS::CPoint WndtoTrue(CPoint ptW)
1666 return (_WTYPES_NS::CSize)ptW * GetZoom() + GetScrollOffset();
1669 void WndtoTrue(LPPOINT aptW, int nPts) // in place coord transformation
1671 for (int i = 0 ; i < nPts ; i++)
1672 aptW[i] = WndtoTrue(aptW[i]);
1675 void WndtoTrue(LPRECT prectW) // in place coord transformation
1677 WndtoTrue((LPPOINT)prectW, 2);
1680 _WTYPES_NS::CPoint TruetoWnd(CPoint ptT)
1682 return (ptT - GetScrollOffset()) / GetZoom();
1685 void TruetoWnd(LPPOINT aptT, int nPts) // in place coord transformation
1687 for (int i = 0 ; i < nPts ; i++)
1688 aptT[i] = TruetoWnd(aptT[i]);
1691 void TruetoWnd(LPRECT prectT) // in place coord transformation
1693 TruetoWnd((LPPOINT)prectT, 2);
1696 // Drawing operations : assume adequate setting of data members
1697 BOOL Draw(HBITMAP hbm, HDC hdestDC, DWORD dwROP = SRCCOPY)
1699 CDC memDC = CreateCompatibleDC(hdestDC);
1700 CBitmapHandle bmpOld = memDC.SelectBitmap(hbm);
1701 BOOL bRes = Draw(memDC, hdestDC, dwROP);
1702 memDC.SelectBitmap(bmpOld);
1703 return bRes;
1706 BOOL Draw(HDC hsourceDC, HDC hdestDC, DWORD dwROP = SRCCOPY)
1708 CDCHandle destDC = hdestDC;
1709 destDC.SetViewportOrg(0,0);
1710 _WTYPES_NS::CPoint ptOffset = GetScrollOffset();
1711 _WTYPES_NS::CSize sizeZClient = m_sizeClient * GetZoom();
1712 return destDC.StretchBlt(0, 0, m_sizeClient.cx, m_sizeClient.cy, hsourceDC, ptOffset.x, ptOffset.y, sizeZClient.cx, sizeZClient.cy, dwROP);
1715 #ifdef _IMAGING_H
1716 BOOL Draw(IImage* pIImage, HDC hdestDC)
1718 CDCHandle destDC = hdestDC;
1719 destDC.SetViewportOrg(0,0);
1720 return SUCCEEDED(pIImage->Draw(destDC, _WTYPES_NS::CRect(-_WTYPES_NS::CPoint(m_ptOffset), m_sizeAll), NULL));
1722 #endif
1724 // Message map and handlers
1725 BEGIN_MSG_MAP(CZoomScrollImpl< T >)
1726 MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
1727 CHAIN_MSG_MAP(CScrollImpl< T >)
1728 END_MSG_MAP()
1730 LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
1732 T* pT = static_cast<T*>(this);
1733 ATLASSERT(::IsWindow(pT->m_hWnd));
1734 if ((GetScrollExtendedStyle() & SCRL_ERASEBACKGROUND))
1736 _WTYPES_NS::CRect rect;
1737 pT->GetClientRect(rect);
1738 _WTYPES_NS::CSize sizeClient=rect.Size();
1740 if (m_sizeAll.cx < sizeClient.cx || m_sizeAll.cy < sizeClient.cy)
1742 CDCHandle hdc = (HDC)wParam;
1743 HBRUSH hbr = GetSysColorBrush((int)T::GetWndClassInfo().m_wc.hbrBackground - 1);
1745 if (m_sizeAll.cx < sizeClient.cx)
1747 _WTYPES_NS::CRect rectBG(_WTYPES_NS::CPoint(m_sizeAll.cx, 0), sizeClient);
1748 hdc.FillRect(rectBG, hbr);
1751 if (m_sizeAll.cy < sizeClient.cy)
1753 _WTYPES_NS::CRect rectBG(_WTYPES_NS::CPoint(0, m_sizeAll.cy), sizeClient);
1754 hdc.FillRect(rectBG, hbr);
1758 else
1760 bHandled = FALSE;
1763 return 1;
1767 #endif // _WTL_CE_NO_ZOOMSCROLL
1769 #ifndef _WTL_CE_NO_CONTROLS
1771 // --- PPC bottom TabView control ---
1773 #if defined(__ATLCTRLX_H__) && defined(WIN32_PLATFORM_PSPC)
1775 ///////////////////////////////////////////////////////////////////////////////
1776 // CBottomTabViewImpl
1778 template <class T, class TBase = ATL::CWindow, class TWinTraits = ATL::CControlWinTraits>
1779 class ATL_NO_VTABLE CBottomTabViewImpl : public CTabViewImpl<T, TBase, TWinTraits>
1781 public:
1782 DECLARE_WND_CLASS_EX(NULL, 0, COLOR_APPWORKSPACE)
1784 // Implementation overrideables
1785 bool CreateTabControl()
1787 m_tab.Create(m_hWnd, rcDefault, NULL, WS_CHILD | TCS_BOTTOM, 0, m_nTabID);
1789 ATLASSERT(m_tab.m_hWnd != NULL);
1790 if(m_tab.m_hWnd == NULL)
1791 return false;
1793 m_tab.SendMessage(CCM_SETVERSION, COMCTL32_VERSION);
1794 m_tab.SetItemExtra(sizeof(TABVIEWPAGE));
1796 T* pT = static_cast<T*>(this);
1797 m_cyTabHeight = pT->CalcTabHeight();
1799 return true;
1802 int CalcTabHeight()
1804 int nCount = m_tab.GetItemCount();
1805 TCITEMEXTRA tcix = { 0 };
1806 tcix.tciheader.mask = TCIF_TEXT;
1807 tcix.tciheader.pszText = _T("NS");
1808 int nIndex = m_tab.InsertItem(nCount, tcix);
1810 RECT rect = { 0 };
1811 SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
1812 RECT rcWnd = rect;
1814 m_tab.AdjustRect(FALSE, &rect);
1815 rcWnd.top = rect.bottom;
1816 ::AdjustWindowRectEx(&rcWnd, m_tab.GetStyle(), FALSE, m_tab.GetExStyle());
1817 m_tab.DeleteItem(nIndex);
1819 return rcWnd.bottom - rcWnd.top;
1822 void UpdateLayout()
1824 RECT rect;
1825 GetClientRect(&rect);
1827 if(m_tab.IsWindow() && ((m_tab.GetStyle() & WS_VISIBLE) != 0))
1828 m_tab.SetWindowPos(NULL, 0, rect.bottom - m_cyTabHeight, rect.right - rect.left, m_cyTabHeight, SWP_NOZORDER /*| SWP_SHOWWINDOW*/);
1830 if(m_nActivePage != -1)
1831 ::SetWindowPos(GetPageHWND(m_nActivePage), NULL, 0, 0, rect.right - rect.left, rect.bottom - m_cyTabHeight, SWP_NOZORDER);
1836 class CBottomTabView : public CBottomTabViewImpl<CBottomTabView>
1838 public:
1839 DECLARE_WND_CLASS_EX(_T("WTL_BottomTabView"), 0, COLOR_APPWORKSPACE)
1842 #endif // defined(__ATLCTRLX_H__) && defined(WIN32_PLATFORM_PSPC)
1845 // --- PPC/SmartPhone controls ---
1847 ////////////////////////////////////////////////////////////////////////////////
1848 // These are wrapper classes for the Pocket PC 2002/2003 and SmartPhone 2003 controls
1849 // To implement a window based on a control, use following:
1850 // Example: Implementing a window based on a Html control
1852 // class CMyHtml : CWindowImpl<CMyHtml, CHtmlCtrl>
1853 // {
1854 // public:
1855 // BEGIN_MSG_MAP(CMyHtml)
1856 // // put your message handler entries here
1857 // END_MSG_MAP()
1858 // };
1859 ///////////////////////////////////////////////////////////////////////////////
1861 ///////////////////////////////////////////////////////////////////////////////
1862 // CHtmlCtrl
1864 template <class TBase>
1865 class CHtmlCtrlT : public TBase
1867 public:
1868 // Constructors
1869 CHtmlCtrlT(HWND hWnd = NULL) : TBase(hWnd)
1872 CHtmlCtrlT< TBase >& operator =(HWND hWnd)
1874 m_hWnd = hWnd;
1875 return *this;
1878 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1879 DWORD dwStyle = 0, DWORD dwExStyle = 0,
1880 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1882 HWND hWnd = TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1883 ATLASSERT(hWnd != NULL); // Did you remember to call InitHTMLControl(hInstance) ??
1884 return hWnd;
1887 // Attributes
1888 static LPCTSTR GetWndClassName()
1890 return WC_HTML;
1893 #if (_WIN32_WCE >= 400)
1894 void AddStyle(LPCWSTR pszStyle)
1896 ATLASSERT(::IsWindow(m_hWnd));
1897 ::SendMessage(m_hWnd, DTM_ADDSTYLE, 0, (LPARAM)pszStyle);
1899 #endif // (_WIN32_WCE >= 400)
1901 void AddText(BOOL bPlainText, LPCSTR pszText)
1903 ATLASSERT(::IsWindow(m_hWnd));
1904 ::SendMessage(m_hWnd, DTM_ADDTEXT, (WPARAM)bPlainText, (LPARAM)pszText);
1907 void AddHTML(LPCSTR pszHTML)
1909 ATLASSERT(::IsWindow(m_hWnd));
1910 ::SendMessage(m_hWnd, DTM_ADDTEXT, (WPARAM)FALSE, (LPARAM)pszHTML);
1913 void AddText(BOOL bPlainText, LPCWSTR pszText)
1915 ATLASSERT(::IsWindow(m_hWnd));
1916 ::SendMessage(m_hWnd, DTM_ADDTEXTW, (WPARAM)bPlainText, (LPARAM)pszText);
1919 void AddHTML(LPCWSTR pszHTML)
1921 ATLASSERT(::IsWindow(m_hWnd));
1922 ::SendMessage(m_hWnd, DTM_ADDTEXTW, (WPARAM)FALSE, (LPARAM)pszHTML);
1925 void Anchor(LPCSTR pszAnchor)
1927 ATLASSERT(::IsWindow(m_hWnd));
1928 ::SendMessage(m_hWnd, DTM_ANCHOR, 0, (LPARAM)pszAnchor);
1931 void Anchor(LPCWSTR pszAnchor)
1933 ATLASSERT(::IsWindow(m_hWnd));
1934 ::SendMessage(m_hWnd, DTM_ANCHORW, 0, (LPARAM)pszAnchor);
1937 #if (_WIN32_WCE >= 420)
1938 void GetBrowserDispatch(IDispatch** ppDispatch)
1940 ATLASSERT(::IsWindow(m_hWnd));
1941 ATLASSERT(ppDispatch);
1942 ATLASSERT(*ppDispatch==NULL);
1943 ::SendMessage(m_hWnd, DTM_BROWSERDISPATCH, 0, (LPARAM)ppDispatch);
1945 void GetDocumentDispatch(IDispatch** ppDispatch)
1947 ATLASSERT(::IsWindow(m_hWnd));
1948 ATLASSERT(ppDispatch);
1949 ATLASSERT(*ppDispatch==NULL);
1950 ::SendMessage(m_hWnd, DTM_DOCUMENTDISPATCH , 0, (LPARAM)ppDispatch);
1952 #endif // (_WIN32_WCE >= 420)
1954 void Clear()
1956 ATLASSERT(::IsWindow(m_hWnd));
1957 ::SendMessage(m_hWnd, DTM_CLEAR, 0, 0L);
1960 void EnableClearType(BOOL bEnable = TRUE)
1962 ATLASSERT(::IsWindow(m_hWnd));
1963 ::SendMessage(m_hWnd, DTM_ENABLECLEARTYPE, 0, (LPARAM)bEnable);
1966 void EnableContextMenu(BOOL bEnable = TRUE)
1968 ATLASSERT(::IsWindow(m_hWnd));
1969 ::SendMessage(m_hWnd, DTM_ENABLECONTEXTMENU, 0, (LPARAM)bEnable);
1972 void EnableScripting(BOOL bEnable = TRUE)
1974 ATLASSERT(::IsWindow(m_hWnd));
1975 ::SendMessage(m_hWnd, DTM_ENABLESCRIPTING, 0, (LPARAM)bEnable);
1978 void EnableShrink(BOOL bEnable = TRUE)
1980 ATLASSERT(::IsWindow(m_hWnd));
1981 ::SendMessage(m_hWnd, DTM_ENABLESHRINK, 0, (LPARAM)bEnable);
1984 void EndOfSource()
1986 ATLASSERT(::IsWindow(m_hWnd));
1987 ::SendMessage(m_hWnd, DTM_ENDOFSOURCE, 0, 0L);
1990 void ImageFail(DWORD dwCookie)
1992 ATLASSERT(::IsWindow(m_hWnd));
1993 ::SendMessage(m_hWnd, DTM_IMAGEFAIL, 0, (LPARAM)dwCookie);
1996 int GetLayoutHeight() const
1998 ATLASSERT(::IsWindow(m_hWnd));
1999 return (int)::SendMessage(m_hWnd, DTM_LAYOUTHEIGHT, 0, 0L);
2002 int GetLayoutWidth() const
2004 ATLASSERT(::IsWindow(m_hWnd));
2005 return (int)::SendMessage(m_hWnd, DTM_LAYOUTWIDTH, 0, 0L);
2008 void Navigate(LPCTSTR pstrURL, UINT uFlags = 0)
2010 ATLASSERT(::IsWindow(m_hWnd));
2011 ATLASSERT(pstrURL);
2012 ::SendMessage(m_hWnd, DTM_NAVIGATE, (WPARAM)uFlags, (LPARAM)pstrURL);
2015 void SelectAll()
2017 ATLASSERT(::IsWindow(m_hWnd));
2018 ::SendMessage(m_hWnd, DTM_SELECTALL, 0, 0L);
2021 void SetImage(INLINEIMAGEINFO* pImageInfo)
2023 ATLASSERT(::IsWindow(m_hWnd));
2024 ATLASSERT(pImageInfo);
2025 ::SendMessage(m_hWnd, DTM_SETIMAGE, 0, (LPARAM)pImageInfo);
2028 void ZoomLevel(int iLevel)
2030 ATLASSERT(::IsWindow(m_hWnd));
2031 ::SendMessage(m_hWnd, DTM_ZOOMLEVEL, 0, (LPARAM)iLevel);
2034 #if (_WIN32_WCE >= 400)
2035 void Stop()
2037 ATLASSERT(::IsWindow(m_hWnd));
2038 ::SendMessage(m_hWnd, DTM_STOP, 0, 0L);
2040 #endif // (_WIN32_WCE >= 400)
2042 void GetScriptDispatch(IDispatch** ppDispatch)
2044 ATLASSERT(::IsWindow(m_hWnd));
2045 ATLASSERT(ppDispatch);
2046 ATLASSERT(*ppDispatch==NULL);
2047 ::SendMessage(m_hWnd, DTM_SCRIPTDISPATCH, 0, (LPARAM)ppDispatch);
2051 typedef CHtmlCtrlT<ATL::CWindow> CHtmlCtrl;
2054 #ifdef WIN32_PLATFORM_PSPC
2056 ///////////////////////////////////////////////////////////////////////////////
2057 // CRichInkCtrl
2059 template <class TBase>
2060 class CRichInkCtrlT : public TBase
2062 public:
2063 // Constructors
2064 CRichInkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2067 CRichInkCtrlT< TBase >& operator =(HWND hWnd)
2069 m_hWnd = hWnd;
2070 return *this;
2073 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2074 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2075 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2077 HWND hWnd = TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2078 ATLASSERT(hWnd != NULL); // Did you remember to call InitRichInkDLL() ??
2079 return hWnd;
2082 // Attributes
2083 static LPCTSTR GetWndClassName()
2085 return WC_RICHINK;
2088 BOOL CanPaste(UINT uFormat = 0) const
2090 ATLASSERT(::IsWindow(m_hWnd));
2091 return (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, (WPARAM)uFormat, 0L);
2094 BOOL CanRedo() const
2096 ATLASSERT(::IsWindow(m_hWnd));
2097 return (BOOL)::SendMessage(m_hWnd, EM_CANREDO, 0, 0L);
2100 BOOL CanUndo() const
2102 ATLASSERT(::IsWindow(m_hWnd));
2103 return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
2106 void ClearAll(BOOL bRepaint = TRUE) const
2108 ATLASSERT(::IsWindow(m_hWnd));
2109 ::SendMessage(m_hWnd, EM_CLEARALL, (WPARAM)bRepaint, 0L);
2112 BOOL GetModify() const
2114 ATLASSERT(::IsWindow(m_hWnd));
2115 return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
2118 UINT GetPageStyle() const
2120 ATLASSERT(::IsWindow(m_hWnd));
2121 return (UINT)::SendMessage(m_hWnd, EM_GETPAGESTYLE, 0, 0L);
2124 UINT GetPenMode() const
2126 ATLASSERT(::IsWindow(m_hWnd));
2127 return (UINT)::SendMessage(m_hWnd, EM_GETPENMODE, 0, 0L);
2130 UINT GetViewStyle() const
2132 ATLASSERT(::IsWindow(m_hWnd));
2133 return (UINT)::SendMessage(m_hWnd, EM_GETVIEW, 0, 0L);
2136 UINT GetWrapMode() const
2138 ATLASSERT(::IsWindow(m_hWnd));
2139 return (UINT)::SendMessage(m_hWnd, EM_GETWRAPMODE, 0, 0L);
2142 UINT GetZoomPercent() const
2144 ATLASSERT(::IsWindow(m_hWnd));
2145 return (UINT)::SendMessage(m_hWnd, EM_GETZOOMPERCENT, 0, 0L);
2148 void InsertLinks(LPWSTR lpString, int cchLength = -1)
2150 ATLASSERT(::IsWindow(m_hWnd));
2151 if(cchLength == -1)
2152 cchLength = lstrlen(lpString);
2153 ::SendMessage(m_hWnd, EM_INSERTLINKS, (WPARAM)cchLength, (LPARAM)lpString);
2156 void RedoEvent()
2158 ATLASSERT(::IsWindow(m_hWnd));
2159 ::SendMessage(m_hWnd, EM_REDOEVENT, 0, 0L);
2162 UINT SetInkLayer(UINT uLayer)
2164 ATLASSERT(::IsWindow(m_hWnd));
2165 return (UINT)::SendMessage(m_hWnd, EM_SETINKLAYER, (WPARAM)uLayer, 0L);
2168 void SetPageStyle(UINT uStyle)
2170 ATLASSERT(::IsWindow(m_hWnd));
2171 ::SendMessage(m_hWnd, EM_SETPAGESTYLE, (WPARAM)uStyle, 0L);
2174 void SetPenMode(UINT uMode)
2176 ATLASSERT(::IsWindow(m_hWnd));
2177 ::SendMessage(m_hWnd, EM_SETPENMODE, (WPARAM)uMode, 0L);
2180 void SetViewStyle(UINT uStyle)
2182 ATLASSERT(::IsWindow(m_hWnd));
2183 ::SendMessage(m_hWnd, EM_SETVIEW, (WPARAM)uStyle, 0L);
2186 void SetViewAttributes(VIEWATTRIBUTES* pAttribs)
2188 ATLASSERT(::IsWindow(m_hWnd));
2189 ATLASSERT(pAttribs);
2190 ::SendMessage(m_hWnd, EM_SETVIEWATTRIBUTES, 0, (LPARAM)pAttribs);
2193 void SetWrapMode(UINT uMode)
2195 ATLASSERT(::IsWindow(m_hWnd));
2196 ::SendMessage(m_hWnd, EM_SETWRAPMODE, (WPARAM)uMode, 0L);
2199 void SetZoomPercent(UINT uPercent)
2201 ATLASSERT(::IsWindow(m_hWnd));
2202 ::SendMessage(m_hWnd, EM_SETZOOMPERCENT, (WPARAM)uPercent, 0L);
2205 LONG StreamIn(UINT uFormat, EDITSTREAM& es)
2207 ATLASSERT(::IsWindow(m_hWnd));
2208 return (LONG)::SendMessage(m_hWnd, EM_STREAMIN, (WPARAM)uFormat, (LPARAM)&es);
2211 LONG StreamOut(UINT uFormat, EDITSTREAM& es)
2213 ATLASSERT(::IsWindow(m_hWnd));
2214 return (LONG)::SendMessage(m_hWnd, EM_STREAMOUT, (WPARAM)uFormat, (LPARAM)&es);
2217 void UndoEvent()
2219 ATLASSERT(::IsWindow(m_hWnd));
2220 ::SendMessage(m_hWnd, EM_UNDOEVENT, 0, 0L);
2223 // Standard EM_xxx messages
2224 DWORD GetSel() const
2226 ATLASSERT(::IsWindow(m_hWnd));
2227 return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
2230 void GetSel(int& nStartChar, int& nEndChar) const
2232 ATLASSERT(::IsWindow(m_hWnd));
2233 ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
2236 void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
2238 ATLASSERT(::IsWindow(m_hWnd));
2239 ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM)bCanUndo, (LPARAM)lpszNewText);
2242 void SetModify(BOOL bModified = TRUE)
2244 ATLASSERT(::IsWindow(m_hWnd));
2245 ::SendMessage(m_hWnd, EM_SETMODIFY, (WPARAM)bModified, 0L);
2248 int GetTextLength() const
2250 ATLASSERT(::IsWindow(m_hWnd));
2251 return (int)::SendMessage(m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
2254 // Clipboard operations
2255 void Clear()
2257 ATLASSERT(::IsWindow(m_hWnd));
2258 ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
2261 void Copy()
2263 ATLASSERT(::IsWindow(m_hWnd));
2264 ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
2267 void Cut()
2269 ATLASSERT(::IsWindow(m_hWnd));
2270 ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
2273 void Paste()
2275 ATLASSERT(::IsWindow(m_hWnd));
2276 ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
2280 typedef CRichInkCtrlT<ATL::CWindow> CRichInkCtrl;
2283 ///////////////////////////////////////////////////////////////////////////////
2284 // CInkXCtrl
2286 template <class TBase>
2287 class CInkXCtrlT : public TBase
2289 public:
2290 // Constructors
2291 CInkXCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2294 CInkXCtrlT< TBase >& operator =(HWND hWnd)
2296 m_hWnd = hWnd;
2297 return *this;
2300 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2301 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2302 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2304 HWND hWnd = TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2305 ATLASSERT(hWnd != NULL); // Did you remember to call InitInkX() ??
2306 return hWnd;
2309 // Attributes
2310 static LPCTSTR GetWndClassName()
2312 return WC_INKX;
2315 static UINT GetHotRecordingMessage()
2317 return ::RegisterWindowMessage(szHotRecording);
2320 void ClearAll()
2322 ATLASSERT(::IsWindow(m_hWnd));
2323 ::SendMessage(m_hWnd, IM_CLEARALL, 0, 0L);
2326 int GetData(BYTE* lpBuffer, INT cbBuffer) const
2328 ATLASSERT(::IsWindow(m_hWnd));
2329 ATLASSERT(lpBuffer);
2330 return (int)::SendMessage(m_hWnd, IM_GETDATA, (WPARAM)cbBuffer, (LPARAM)lpBuffer);
2333 int GetDataLen() const
2335 ATLASSERT(::IsWindow(m_hWnd));
2336 return (int)::SendMessage(m_hWnd, IM_GETDATALEN, 0, 0L);
2339 CRichInkCtrl GetRichInk() const
2341 ATLASSERT(::IsWindow(m_hWnd));
2342 return (HWND)::SendMessage(m_hWnd, IM_GETRICHINK, 0, 0L);
2345 BOOL IsRecording() const
2347 ATLASSERT(::IsWindow(m_hWnd));
2348 return (BOOL)::SendMessage(m_hWnd, IM_RECORDING, 0, 0L);
2351 void ReInit()
2353 ATLASSERT(::IsWindow(m_hWnd));
2354 ::SendMessage(m_hWnd, IM_REINIT, 0, 0L);
2357 void SetData(const BYTE* lpInkData, INT cbInkData)
2359 ATLASSERT(::IsWindow(m_hWnd));
2360 ATLASSERT(lpInkData);
2361 ::SendMessage(m_hWnd, IM_SETDATA, (WPARAM)cbInkData, (LPARAM)lpInkData);
2364 void VoicePlay()
2366 ATLASSERT(::IsWindow(m_hWnd));
2367 ::SendMessage(m_hWnd, IM_VOICE_PLAY, 0, 0L);
2370 BOOL IsVoicePlaying() const
2372 ATLASSERT(::IsWindow(m_hWnd));
2373 return (BOOL)::SendMessage(m_hWnd, IM_VOICE_PLAYING, 0, 0L);
2376 BOOL VoiceRecord()
2378 ATLASSERT(::IsWindow(m_hWnd));
2379 return (BOOL)::SendMessage(m_hWnd, IM_VOICE_RECORD, 0, 0L);
2382 void VoiceStop()
2384 ATLASSERT(::IsWindow(m_hWnd));
2385 ::SendMessage(m_hWnd, IM_VOICE_STOP, 0, 0L);
2388 void ShowVoiceBar(BOOL bShow = TRUE)
2390 ATLASSERT(::IsWindow(m_hWnd));
2391 ::SendMessage(m_hWnd, IM_VOICEBAR, (WPARAM)bShow, 0L);
2395 typedef CInkXCtrlT<ATL::CWindow> CInkXCtrl;
2397 #endif // WIN32_PLATFORM_PSPC
2400 ///////////////////////////////////////////////////////////////////////////////
2401 // CVoiceRecorderCtrl
2403 template <class TBase>
2404 class CVoiceRecorderCtrlT : public TBase
2406 public:
2407 // Constructors
2408 CVoiceRecorderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2411 CVoiceRecorderCtrlT< TBase >& operator =(HWND hWnd)
2413 m_hWnd = hWnd;
2414 return *this;
2417 HWND Create(HWND hWndParent, const POINT pt, LPTSTR pstrFileName, UINT nID, DWORD dwStyle = 0)
2419 ATLASSERT(pstrFileName != NULL);
2420 CM_VOICE_RECORDER cmvr = { 0 };
2421 cmvr.cb = sizeof(CM_VOICE_RECORDER);
2422 cmvr.dwStyle = dwStyle;
2423 cmvr.xPos = pt.x;
2424 cmvr.yPos = pt.y;
2425 cmvr.hwndParent = hWndParent;
2426 cmvr.id = nID;
2427 cmvr.lpszRecordFileName = pstrFileName;
2428 m_hWnd = VoiceRecorder_Create(&cmvr);
2429 return m_hWnd;
2432 HWND Create(LPCM_VOICE_RECORDER pAttribs)
2434 ATLASSERT(pAttribs);
2435 m_hWnd = VoiceRecorder_Create(pAttribs);
2436 return m_hWnd;
2439 // Attributes
2440 void Record()
2442 ATLASSERT(::IsWindow(m_hWnd));
2443 ::SendMessage(m_hWnd, VRM_RECORD, 0, 0L);
2446 void Play()
2448 ATLASSERT(::IsWindow(m_hWnd));
2449 ::SendMessage(m_hWnd, VRM_PLAY, 0, 0L);
2452 void Stop()
2454 ATLASSERT(::IsWindow(m_hWnd));
2455 ::SendMessage(m_hWnd, VRM_STOP, 0, 0L);
2458 void Cancel()
2460 ATLASSERT(::IsWindow(m_hWnd));
2461 ::SendMessage(m_hWnd, VRM_CANCEL, 0, 0L);
2464 void Done()
2466 ATLASSERT(::IsWindow(m_hWnd));
2467 ::SendMessage(m_hWnd, VRM_OK, 0, 0L);
2471 typedef CVoiceRecorderCtrlT<ATL::CWindow> CVoiceRecorderCtrl;
2474 #ifdef WIN32_PLATFORM_PSPC
2476 ///////////////////////////////////////////////////////////////////////////////
2477 // CDocListCtrl
2479 template <class TBase>
2480 class CDocListCtrlT : public TBase
2482 public:
2483 // Attributes
2484 DOCLISTCREATE m_dlc;
2485 TCHAR m_szPath[MAX_PATH];
2487 // Constructors
2488 CDocListCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2491 CDocListCtrlT< TBase >& operator =(HWND hWnd)
2493 m_hWnd = hWnd;
2494 return *this;
2497 HWND Create(HWND hWndParent, WORD wId, LPCTSTR pszFolder = NULL, LPCTSTR pstrFilter = NULL,
2498 WORD wFilterIndex = 0, DWORD dwFlags = DLF_SHOWEXTENSION)
2500 ATLASSERT(pstrFilter != NULL); // It seems to need a filter badly!!
2501 ::ZeroMemory(&m_dlc, sizeof(DOCLISTCREATE));
2502 ::ZeroMemory(m_szPath, sizeof(m_szPath));
2503 if(pszFolder != NULL)
2504 ::lstrcpyn(m_szPath, pszFolder, MAX_PATH - 1);
2505 m_dlc.dwStructSize = sizeof(DOCLISTCREATE);
2506 m_dlc.hwndParent = hWndParent;
2507 m_dlc.pszFolder = m_szPath;
2508 m_dlc.pstrFilter = pstrFilter;
2509 m_dlc.wFilterIndex = wFilterIndex;
2510 m_dlc.wId = wId;
2511 m_dlc.dwFlags = dwFlags;
2512 m_hWnd = DocList_Create(&m_dlc);
2513 return m_hWnd;
2516 HWND Create(DOCLISTCREATE* pDlc)
2518 m_dlc = *pDlc;
2519 m_hWnd = DocList_Create(&m_dlc);
2520 return m_hWnd;
2523 // Attributes
2524 void DeleteSel()
2526 ATLASSERT(::IsWindow(m_hWnd));
2527 ::SendMessage(m_hWnd, DLM_DELETESEL, 0, 0L);
2530 void DisableUpdates()
2532 ATLASSERT(::IsWindow(m_hWnd));
2533 ::SendMessage(m_hWnd, DLM_DISABLEUPDATES, 0, 0L);
2536 void EnableUpdates()
2538 ATLASSERT(::IsWindow(m_hWnd));
2539 ::SendMessage(m_hWnd, DLM_ENABLEUPDATES, 0, 0L);
2542 int GetFilterIndex() const
2544 ATLASSERT(::IsWindow(m_hWnd));
2545 return (int)::SendMessage(m_hWnd, DLM_GETFILTERINDEX, 0, 0L);
2548 int GetItemCount() const
2550 ATLASSERT(::IsWindow(m_hWnd));
2551 return (int)::SendMessage(m_hWnd, DLM_GETITEMCOUNT, 0, 0L);
2554 int GetNextItem(int iIndex, DWORD dwRelation = LVNI_ALL) const
2556 ATLASSERT(::IsWindow(m_hWnd));
2557 return (int)::SendMessage(m_hWnd, DLM_GETNEXTITEM, (WPARAM)iIndex, (LPARAM)dwRelation);
2560 int GetFirstItem(DWORD dwRelation = LVNI_ALL) const
2562 ATLASSERT(::IsWindow(m_hWnd));
2563 return (int)::SendMessage(m_hWnd, DLM_GETNEXTITEM, (WPARAM)-1, (LPARAM)dwRelation);
2566 BOOL GetNextWave(int* pIndex) const
2568 ATLASSERT(::IsWindow(m_hWnd));
2569 ATLASSERT(pIndex);
2570 return (BOOL)::SendMessage(m_hWnd, DLM_GETNEXTWAVE, 0, (LPARAM)pIndex);
2573 BOOL GetPrevWave(int* pIndex) const
2575 ATLASSERT(::IsWindow(m_hWnd));
2576 ATLASSERT(pIndex);
2577 return (BOOL)::SendMessage(m_hWnd, DLM_GETPREVWAVE, 0, (LPARAM)pIndex);
2580 int GetSelCount() const
2582 ATLASSERT(::IsWindow(m_hWnd));
2583 return (int)::SendMessage(m_hWnd, DLM_GETSELCOUNT, 0, 0L);
2586 BOOL GetSelPathName(LPTSTR pstrPath, int cchMax) const
2588 ATLASSERT(::IsWindow(m_hWnd));
2589 ATLASSERT(pstrPath);
2590 return (BOOL)::SendMessage(m_hWnd, DLM_GETSELPATHNAME, (WPARAM)cchMax, (LPARAM)pstrPath);
2593 void ReceiveIR(LPCTSTR pstrPath) const
2595 ATLASSERT(::IsWindow(m_hWnd));
2596 ATLASSERT(pstrPath);
2597 ::SendMessage(m_hWnd, DLM_RECEIVEIR, 0, (LPARAM)pstrPath);
2600 void Refresh()
2602 ATLASSERT(::IsWindow(m_hWnd));
2603 ::SendMessage(m_hWnd, DLM_REFRESH, 0, 0L);
2606 BOOL RenameMoveSelectedItems()
2608 ATLASSERT(::IsWindow(m_hWnd));
2609 return (BOOL)::SendMessage(m_hWnd, DLM_RENAMEMOVE, 0, 0L);
2612 int SelectAll()
2614 ATLASSERT(::IsWindow(m_hWnd));
2615 return (int)::SendMessage(m_hWnd, DLM_SELECTALL, 0, 0L);
2618 HRESULT SelectItem(LPCTSTR pstrPath, BOOL bVisible = TRUE)
2620 ATLASSERT(::IsWindow(m_hWnd));
2621 ATLASSERT(pstrPath);
2622 return (HRESULT)::SendMessage(m_hWnd, DLM_SELECTITEM, (WPARAM)bVisible, (LPARAM)pstrPath);
2625 void SendEMail(LPCTSTR pstrAttachment)
2627 ATLASSERT(::IsWindow(m_hWnd));
2628 ::SendMessage(m_hWnd, DLM_SENDEMAIL, 0, (LPARAM)pstrAttachment);
2631 void SendIR(LPCTSTR pstrPath)
2633 ATLASSERT(::IsWindow(m_hWnd));
2634 ::SendMessage(m_hWnd, DLM_SENDIR, 0, (LPARAM)pstrPath);
2637 HRESULT SetFilterIndex(int iIndex)
2639 ATLASSERT(::IsWindow(m_hWnd));
2640 return (HRESULT)::SendMessage(m_hWnd, DLM_SETFILTERINDEX, (WPARAM)iIndex, 0L);
2643 void SetFolder(LPCTSTR pstrPath)
2645 ATLASSERT(::IsWindow(m_hWnd));
2646 ATLASSERT(pstrPath);
2647 ::SendMessage(m_hWnd, DLM_SETFOLDER, 0, (LPARAM)pstrPath);
2650 BOOL SetItemState(int iIndex, const LVITEM* pItem)
2652 ATLASSERT(::IsWindow(m_hWnd));
2653 ATLASSERT(pItem);
2654 return (BOOL)::SendMessage(m_hWnd, DLM_SETITEMSTATE, (WPARAM)iIndex, (LPARAM)pItem);
2657 BOOL SetItemState(int iIndex, UINT uState, UINT uMask)
2659 ATLASSERT(::IsWindow(m_hWnd));
2660 LV_ITEM lvi = { 0 };
2661 lvi.stateMask = uMask;
2662 lvi.state = uState;
2663 return (BOOL)::SendMessage(m_hWnd, DLM_SETITEMSTATE, (WPARAM)iIndex, (LPARAM)&lvi);
2666 void SetOneItem(int iIndex, LPCVOID pPA)
2668 ATLASSERT(::IsWindow(m_hWnd));
2669 ::SendMessage(m_hWnd, DLM_SETONEITEM, (WPARAM)iIndex, (LPARAM)pPA);
2672 void SetSelect(int iIndex)
2674 ATLASSERT(::IsWindow(m_hWnd));
2675 ::SendMessage(m_hWnd, DLM_SETSELECT, (WPARAM)iIndex, 0L);
2678 void SetSelPathName(LPCTSTR pstrPath)
2680 ATLASSERT(::IsWindow(m_hWnd));
2681 ATLASSERT(pstrPath);
2682 ::SendMessage(m_hWnd, DLM_SETSELPATHNAME, 0, (LPARAM)pstrPath);
2685 BOOL SetSortOrder()
2687 ATLASSERT(::IsWindow(m_hWnd));
2688 return (BOOL)::SendMessage(m_hWnd, DLM_SETSORTORDER, 0, 0L);
2691 HRESULT Update()
2693 ATLASSERT(::IsWindow(m_hWnd));
2694 return (HRESULT)::SendMessage(m_hWnd, DLM_UPDATE, 0, 0L);
2697 BOOL ValidateFolder()
2699 ATLASSERT(::IsWindow(m_hWnd));
2700 return (BOOL)::SendMessage(m_hWnd, DLM_VALIDATEFOLDER, 0, 0L);
2703 // Functions
2704 BOOL GetFirstSelectedWaveFile(int* pIndex, LPTSTR szPath, const size_t cchPath)
2706 ATLASSERT(::IsWindow(m_hWnd));
2707 return DocList_GetFirstSelectedWaveFile(m_hWnd, pIndex, szPath, cchPath);
2710 BOOL GetNextSelectedWaveFile(int* pIndex, LPTSTR szPath, const size_t cchPath)
2712 ATLASSERT(::IsWindow(m_hWnd));
2713 return DocList_GetNextSelectedWaveFile(m_hWnd, pIndex, szPath, cchPath);
2717 typedef CDocListCtrlT<ATL::CWindow> CDocListCtrl;
2719 #endif // WIN32_PLATFORM_PSPC
2722 ///////////////////////////////////////////////////////////////////////////////
2723 // CCapEdit
2725 template <class TBase>
2726 class CCapEditT : public TBase
2728 public:
2729 // Constructors
2730 CCapEditT(HWND hWnd = NULL) : TBase(hWnd)
2733 CCapEditT< TBase >& operator =(HWND hWnd)
2735 m_hWnd = hWnd;
2736 return *this;
2739 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2740 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2741 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2743 HWND hWnd = /*TBase*/CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2744 ATLASSERT(hWnd != NULL); // Did you remember to call SHInitExtraControls() ??
2745 return hWnd;
2748 // Attributes
2749 static LPCTSTR GetWndClassName()
2751 return WC_CAPEDIT;
2755 typedef CCapEditT<WTL::CEdit> CCapEdit;
2757 ///////////////////////////////////////////////////////////////////////////////
2758 // CTTStatic
2760 #ifndef WIN32_PLATFORM_WFSP // Tooltips not supported on SmartPhone
2762 template <class TBase>
2763 class CTTStaticT : public TBase
2765 public:
2766 // Constructors
2767 CTTStaticT(HWND hWnd = NULL) : TBase(hWnd)
2770 CTTStaticT< TBase >& operator =(HWND hWnd)
2772 m_hWnd = hWnd;
2773 return *this;
2776 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2777 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2778 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2780 HWND hWnd = TBase::Create(hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2781 ATLASSERT(hWnd != NULL); // Did you remember to call SHInitExtraControls() ??
2782 return hWnd;
2785 // Attributes
2786 static LPCTSTR GetWndClassName()
2788 return WC_TSTATIC;
2791 // Operations
2792 BOOL SetToolTipText(LPCTSTR pstrTipText)
2794 ATLASSERT(::IsWindow(m_hWnd));
2795 ATLASSERT(pstrTipText);
2796 ATLASSERT(lstrlen(pstrTipText)<= 253);
2797 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
2798 LPTSTR pstr = buff.Allocate(lstrlen(pstrTipText) + 3);
2799 if(pstr == NULL)
2800 return FALSE;
2801 ::lstrcpy(pstr, _T("~~"));
2802 ::lstrcat(pstr, pstrTipText);
2803 return SetWindowText(pstr);
2807 typedef CTTStaticT<WTL::CStatic> CTTStatic;
2810 ///////////////////////////////////////////////////////////////////////////////
2811 // CTTButton
2813 template <class TBase>
2814 class CTTButtonT : public TBase
2816 public:
2817 // Constructors
2818 CTTButtonT(HWND hWnd = NULL) : TBase(hWnd)
2821 CTTButtonT< TBase >& operator =(HWND hWnd)
2823 m_hWnd = hWnd;
2824 return *this;
2827 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2828 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2829 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2831 HWND hWnd = TBase::Create(hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2832 ATLASSERT(hWnd != NULL); // Did you remember to call SHInitExtraControls() ??
2833 return hWnd;
2836 // Attributes
2837 static LPCTSTR GetWndClassName()
2839 return WC_TBUTTON;
2842 // Operations
2843 BOOL SetToolTipText(LPCTSTR pstrTipText)
2845 ATLASSERT(::IsWindow(m_hWnd));
2846 ATLASSERT(pstrTipText);
2847 ATLASSERT(lstrlen(pstrTipText)<= 253);
2848 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
2849 LPTSTR pstr = buff.Allocate(lstrlen(pstrTipText) + 3);
2850 if(pstr == NULL)
2851 return FALSE;
2852 ::lstrcpy(pstr, _T("~~"));
2853 ::lstrcat(pstr, pstrTipText);
2854 return SetWindowText(pstr);
2858 typedef CTTButtonT<WTL::CButton> CTTButton;
2860 #endif // !WIN32_PLATFORM_WFSP
2863 // --- SmartPhone specific controls ---
2865 #ifdef WIN32_PLATFORM_WFSP
2867 ///////////////////////////////////////////////////////////////////////////////
2868 // CSpinCtrlT - CSpinCtrl : SmartPhone adapted UpDown control
2870 template <class TBase>
2871 class CSpinCtrlT : public CUpDownCtrlT< TBase >
2873 public:
2874 // Constructors
2875 CSpinCtrlT(HWND hWnd = NULL) : CUpDownCtrlT< TBase >(hWnd)
2878 CSpinCtrlT< TBase >& operator =(HWND hWnd)
2880 m_hWnd = hWnd;
2881 return *this;
2884 HWND Create(HWND hWndParent, HWND hBuddy, DWORD dwStyle, int nID, LPCTSTR szExpandedName = NULL)
2886 ATLASSERT(::IsWindow(hWndParent));
2887 CUpDownCtrlT< TBase >::Create(hWndParent, NULL, szExpandedName, dwStyle, 0, nID, NULL);
2888 ATLASSERT(m_hWnd != NULL); // Did you remember to call AtlInitCommonControls(ICC_UPDOWN_CLASS)?
2889 if (hBuddy != NULL)
2891 ATLASSERT(::IsWindow(hBuddy));
2892 SetBuddy(hBuddy);
2894 return m_hWnd;
2898 typedef CSpinCtrlT<ATL::CWindow> CSpinCtrl;
2901 ///////////////////////////////////////////////////////////////////////////////
2902 // CSpinned - SmartPhone association of control and Spin
2904 template <class TBase, bool t_bExpandOnly>
2905 class CSpinned : public TBase
2907 public:
2908 CSpinCtrl m_SpinCtrl;
2909 DWORD m_dwSpinnedStyle;
2911 // Constructors
2912 CSpinned(HWND hWnd = NULL) : TBase(hWnd)
2914 m_dwSpinnedStyle = WS_VISIBLE | UDS_ALIGNRIGHT | UDS_EXPANDABLE;
2916 if (t_bExpandOnly == true)
2917 m_dwSpinnedStyle |= UDS_NOSCROLL;
2918 else
2919 m_dwSpinnedStyle |= UDS_HORZ | UDS_ARROWKEYS | UDS_SETBUDDYINT | UDS_WRAP;
2921 if (hWnd != NULL)
2922 AttachOrCreateSpinCtrl();
2925 CSpinned<TBase, t_bExpandOnly>& operator =(HWND hWnd)
2927 Attach(hWnd);
2928 return *this;
2931 void Attach(HWND hWnd)
2933 ATLASSERT(!IsWindow());
2934 TBase* pT = static_cast<TBase*>(this);
2935 pT->m_hWnd = hWnd;
2936 if (hWnd != NULL)
2937 AttachOrCreateSpinCtrl();
2940 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szExpandedName = NULL,
2941 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2942 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2945 TBase* pT = static_cast<TBase*>(this);
2946 TBase::Create(hWndParent, rect, NULL, dwStyle, dwExStyle, MenuOrID, lpCreateParam);
2947 ATLASSERT(pT->m_hWnd != NULL);
2949 m_SpinCtrl.Create(hWndParent, pT->m_hWnd, m_dwSpinnedStyle, ATL_IDW_SPIN_ID + (int)MenuOrID.m_hMenu, szExpandedName);
2951 ATLASSERT(m_SpinCtrl.m_hWnd != NULL); // Did you remember to call AtlInitCommonControls(ICC_UPDOWN_CLASS)?
2953 return pT->m_hWnd;
2956 // Attributes
2957 CSpinCtrl& GetSpinCtrl()
2959 return m_SpinCtrl;
2962 // Implementation
2963 // Attach our existing SpinCtrl or create one
2964 bool AttachOrCreateSpinCtrl()
2966 TBase* pT = static_cast<TBase*>(this);
2968 HWND hSpin = ::GetDlgItem(pT->GetParent(), ATL_IDW_SPIN_ID + pT->GetDlgCtrlID());
2970 if (hSpin != NULL)
2972 m_SpinCtrl.Attach(hSpin);
2973 #ifdef DEBUG
2974 TCHAR sClassName[16];
2975 ::GetClassName(hSpin, sClassName, 16);
2976 ATLASSERT(!_tcscmp(sClassName, UPDOWN_CLASS));
2977 ATLASSERT(m_SpinCtrl.GetBuddy().m_hWnd == pT->m_hWnd);
2978 #endif // DEBUG
2980 else
2982 m_SpinCtrl.Create(pT->GetParent(), pT->m_hWnd, m_dwSpinnedStyle, ATL_IDW_SPIN_ID + pT->GetDlgCtrlID());
2985 return m_SpinCtrl.m_hWnd != NULL;
2990 ///////////////////////////////////////////////////////////////////////////////
2991 // CSpinListBox - SmartPhone spinned ListBox control
2992 // CExpandListBox - SmartPhone expandable ListBox control
2993 // CExpandEdit - SmartPhone expandable Edit control
2994 // CExpandCapEdit - SmartPhone expandable CapEdit control
2996 typedef CSpinned<CListBox, false> CSpinListBox;
2997 typedef CSpinned<CListBox, true> CExpandListBox;
2998 typedef CSpinned<CEdit, true> CExpandEdit;
2999 typedef CSpinned<CCapEdit, true> CExpandCapEdit;
3001 #endif // WIN32_PLATFORM_WFSP
3003 #endif // _WTL_CE_NO_CONTROLS
3005 }; // namespace WTL
3007 #endif // __ATLWINCE_H__