atlwinx.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. // Windows Template Library - WTL version 10.0
  2. // Copyright (C) Microsoft Corporation, WTL Team. 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 Public License (http://opensource.org/licenses/MS-PL)
  7. // which can be found in the file MS-PL.txt at the root folder.
  8. #ifndef __ATLWINX_H__
  9. #define __ATLWINX_H__
  10. #pragma once
  11. #ifndef __ATLAPP_H__
  12. #error atlwinx.h requires atlapp.h to be included first
  13. #endif
  14. #include <atlwin.h>
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // Classes in this file:
  17. //
  18. // CWindowEx
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Additional macros needed for template classes
  21. #ifndef DECLARE_WND_CLASS_EX2
  22. #define DECLARE_WND_CLASS_EX2(WndClassName, EnclosingClass, style, bkgnd) \
  23. static ATL::CWndClassInfo& GetWndClassInfo() \
  24. { \
  25. static ATL::CWndClassInfo wc = \
  26. { \
  27. { sizeof(WNDCLASSEX), style, EnclosingClass::StartWindowProc, \
  28. 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, \
  29. NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
  30. }; \
  31. return wc; \
  32. }
  33. #endif // DECLARE_WND_CLASS_EX2
  34. #ifndef DECLARE_WND_SUPERCLASS2
  35. #define DECLARE_WND_SUPERCLASS2(WndClassName, EnclosingClass, OrigWndClassName) \
  36. static ATL::CWndClassInfo& GetWndClassInfo() \
  37. { \
  38. static ATL::CWndClassInfo wc = \
  39. { \
  40. { sizeof(WNDCLASSEX), 0, EnclosingClass::StartWindowProc, \
  41. 0, 0, NULL, NULL, NULL, NULL, NULL, WndClassName, NULL }, \
  42. OrigWndClassName, NULL, NULL, TRUE, 0, _T("") \
  43. }; \
  44. return wc; \
  45. }
  46. #endif // DECLARE_WND_SUPERCLASS2
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // Command Chaining Macros
  49. #define CHAIN_COMMANDS(theChainClass) \
  50. if(uMsg == WM_COMMAND) \
  51. CHAIN_MSG_MAP(theChainClass)
  52. #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
  53. if(uMsg == WM_COMMAND) \
  54. CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
  55. #define CHAIN_COMMANDS_MEMBER(theChainMember) \
  56. if(uMsg == WM_COMMAND) \
  57. CHAIN_MSG_MAP_MEMBER(theChainMember)
  58. #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
  59. if(uMsg == WM_COMMAND) \
  60. CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // Macros for parent message map to selectively reflect control messages
  63. // NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
  64. // (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
  65. // Since we can't modify ATL, we'll provide the needed additions
  66. // in a separate function (that is not a member of CWindowImplRoot)
  67. namespace WTL
  68. {
  69. inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
  70. UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
  71. {
  72. if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
  73. {
  74. // The notification message doesn't match the filter.
  75. bHandled = FALSE;
  76. return 1;
  77. }
  78. HWND hWndChild = NULL;
  79. UINT_PTR idFrom = 0;
  80. switch(uMsg)
  81. {
  82. case WM_COMMAND:
  83. if(lParam != NULL) // not from a menu
  84. {
  85. hWndChild = (HWND)lParam;
  86. idFrom = (UINT_PTR)LOWORD(wParam);
  87. }
  88. break;
  89. case WM_NOTIFY:
  90. hWndChild = ((LPNMHDR)lParam)->hwndFrom;
  91. idFrom = ((LPNMHDR)lParam)->idFrom;
  92. break;
  93. case WM_PARENTNOTIFY:
  94. switch(LOWORD(wParam))
  95. {
  96. case WM_CREATE:
  97. case WM_DESTROY:
  98. hWndChild = (HWND)lParam;
  99. idFrom = (UINT_PTR)HIWORD(wParam);
  100. break;
  101. default:
  102. hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
  103. idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
  104. break;
  105. }
  106. break;
  107. case WM_DRAWITEM:
  108. if(wParam) // not from a menu
  109. {
  110. hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
  111. idFrom = (UINT_PTR)wParam;
  112. }
  113. break;
  114. case WM_MEASUREITEM:
  115. if(wParam) // not from a menu
  116. {
  117. hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
  118. idFrom = (UINT_PTR)wParam;
  119. }
  120. break;
  121. case WM_COMPAREITEM:
  122. if(wParam) // not from a menu
  123. {
  124. hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
  125. idFrom = (UINT_PTR)wParam;
  126. }
  127. break;
  128. case WM_DELETEITEM:
  129. if(wParam) // not from a menu
  130. {
  131. hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
  132. idFrom = (UINT_PTR)wParam;
  133. }
  134. break;
  135. case WM_VKEYTOITEM:
  136. case WM_CHARTOITEM:
  137. case WM_HSCROLL:
  138. case WM_VSCROLL:
  139. hWndChild = (HWND)lParam;
  140. idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
  141. break;
  142. case WM_CTLCOLORBTN:
  143. case WM_CTLCOLORDLG:
  144. case WM_CTLCOLOREDIT:
  145. case WM_CTLCOLORLISTBOX:
  146. case WM_CTLCOLORMSGBOX:
  147. case WM_CTLCOLORSCROLLBAR:
  148. case WM_CTLCOLORSTATIC:
  149. hWndChild = (HWND)lParam;
  150. idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
  151. break;
  152. default:
  153. break;
  154. }
  155. if((hWndChild == NULL) ||
  156. ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
  157. {
  158. // Either hWndChild isn't valid, or
  159. // hWndChild doesn't match the filter.
  160. bHandled = FALSE;
  161. return 1;
  162. }
  163. if((idFromFilter != 0) && (idFromFilter != idFrom))
  164. {
  165. // The dialog control id doesn't match the filter.
  166. bHandled = FALSE;
  167. return 1;
  168. }
  169. ATLASSERT(::IsWindow(hWndChild));
  170. LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  171. if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
  172. {
  173. // Try to prevent problems with WM_CTLCOLOR* messages when
  174. // the message wasn't really handled
  175. bHandled = FALSE;
  176. }
  177. return lResult;
  178. }
  179. } // namespace WTL
  180. // Try to prevent problems with WM_CTLCOLOR* messages when
  181. // the message wasn't really handled
  182. #define REFLECT_NOTIFICATIONS_EX() \
  183. { \
  184. bHandled = TRUE; \
  185. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  186. if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
  187. bHandled = FALSE; \
  188. if(bHandled) \
  189. return TRUE; \
  190. }
  191. #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
  192. { \
  193. bHandled = TRUE; \
  194. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
  195. if(bHandled) \
  196. return TRUE; \
  197. }
  198. #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
  199. { \
  200. bHandled = TRUE; \
  201. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
  202. if(bHandled) \
  203. return TRUE; \
  204. }
  205. #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
  206. { \
  207. bHandled = TRUE; \
  208. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
  209. if(bHandled) \
  210. return TRUE; \
  211. }
  212. #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
  213. { \
  214. bHandled = TRUE; \
  215. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
  216. if(bHandled) \
  217. return TRUE; \
  218. }
  219. #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
  220. { \
  221. bHandled = TRUE; \
  222. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
  223. if(bHandled) \
  224. return TRUE; \
  225. }
  226. #define REFLECT_COMMAND(id, code) \
  227. if((uMsg == WM_COMMAND) && (id == LOWORD(wParam)) && (code == HIWORD(wParam))) \
  228. { \
  229. bHandled = TRUE; \
  230. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  231. if(bHandled) \
  232. return TRUE; \
  233. }
  234. #define REFLECT_COMMAND_ID(id) \
  235. if((uMsg == WM_COMMAND) && (id == LOWORD(wParam))) \
  236. { \
  237. bHandled = TRUE; \
  238. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  239. if(bHandled) \
  240. return TRUE; \
  241. }
  242. #define REFLECT_COMMAND_CODE(code) \
  243. if((uMsg == WM_COMMAND) && (code == HIWORD(wParam))) \
  244. { \
  245. bHandled = TRUE; \
  246. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  247. if(bHandled) \
  248. return TRUE; \
  249. }
  250. #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
  251. if((uMsg == WM_COMMAND) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
  252. { \
  253. bHandled = TRUE; \
  254. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  255. if(bHandled) \
  256. return TRUE; \
  257. }
  258. #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
  259. if((uMsg == WM_COMMAND) && (code == HIWORD(wParam)) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
  260. { \
  261. bHandled = TRUE; \
  262. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  263. if(bHandled) \
  264. return TRUE; \
  265. }
  266. #define REFLECT_NOTIFY(id, cd) \
  267. if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom) && (cd == ((LPNMHDR)lParam)->code)) \
  268. { \
  269. bHandled = TRUE; \
  270. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  271. if(bHandled) \
  272. return TRUE; \
  273. }
  274. #define REFLECT_NOTIFY_ID(id) \
  275. if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom)) \
  276. { \
  277. bHandled = TRUE; \
  278. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  279. if(bHandled) \
  280. return TRUE; \
  281. }
  282. #define REFLECT_NOTIFY_CODE(cd) \
  283. if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code)) \
  284. { \
  285. bHandled = TRUE; \
  286. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  287. if(bHandled) \
  288. return TRUE; \
  289. }
  290. #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
  291. if((uMsg == WM_NOTIFY) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
  292. { \
  293. bHandled = TRUE; \
  294. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  295. if(bHandled) \
  296. return TRUE; \
  297. }
  298. #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
  299. if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
  300. { \
  301. bHandled = TRUE; \
  302. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  303. if(bHandled) \
  304. return TRUE; \
  305. }
  306. ///////////////////////////////////////////////////////////////////////////////
  307. // GetClassLong/SetClassLong redefinition to avoid problems with class members
  308. #ifdef SetClassLongPtrA
  309. #undef SetClassLongPtrA
  310. inline LONG_PTR SetClassLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  311. {
  312. return ::SetClassLongA(hWnd, nIndex, LONG(dwNewLong));
  313. }
  314. #endif
  315. #ifdef SetClassLongPtrW
  316. #undef SetClassLongPtrW
  317. inline LONG_PTR SetClassLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  318. {
  319. return ::SetClassLongW(hWnd, nIndex, LONG(dwNewLong));
  320. }
  321. #endif
  322. #ifdef GetClassLongPtrA
  323. #undef GetClassLongPtrA
  324. inline LONG_PTR GetClassLongPtrA(HWND hWnd, int nIndex)
  325. {
  326. return ::GetClassLongA(hWnd, nIndex);
  327. }
  328. #endif
  329. #ifdef GetClassLongPtrW
  330. #undef GetClassLongPtrW
  331. inline LONG_PTR GetClassLongPtrW(HWND hWnd, int nIndex)
  332. {
  333. return ::GetClassLongW(hWnd, nIndex);
  334. }
  335. #endif
  336. ///////////////////////////////////////////////////////////////////////////////
  337. // CWindowEx - extension of ATL::CWindow
  338. namespace WTL
  339. {
  340. class CWindowEx : public ATL::CWindow
  341. {
  342. public:
  343. CWindowEx(HWND hWnd = NULL) : ATL::CWindow(hWnd)
  344. { }
  345. CWindowEx& operator =(HWND hWnd)
  346. {
  347. m_hWnd = hWnd;
  348. return *this;
  349. }
  350. operator HWND() const
  351. {
  352. return m_hWnd;
  353. }
  354. // Methods
  355. BOOL PrintWindow(HDC hDC, UINT uFlags = 0)
  356. {
  357. ATLASSERT(::IsWindow(m_hWnd));
  358. return ::PrintWindow(m_hWnd, hDC, uFlags);
  359. }
  360. BOOL DragDetect(POINT pt)
  361. {
  362. ATLASSERT(::IsWindow(m_hWnd));
  363. return ::DragDetect(m_hWnd, pt);
  364. }
  365. BOOL DragDetect()
  366. {
  367. ATLASSERT(::IsWindow(m_hWnd));
  368. POINT pt = {};
  369. ::GetCursorPos(&pt);
  370. return ::DragDetect(m_hWnd, pt);
  371. }
  372. CWindowEx GetAncestor(UINT uFlags) const
  373. {
  374. ATLASSERT(::IsWindow(m_hWnd));
  375. return CWindowEx(::GetAncestor(m_hWnd, uFlags));
  376. }
  377. // Note: Does not work properly on Vista Aero and above
  378. BOOL AnimateWindow(DWORD dwFlags, DWORD dwTime = 200)
  379. {
  380. ATLASSERT(::IsWindow(m_hWnd));
  381. return ::AnimateWindow(m_hWnd, dwTime, dwFlags);
  382. }
  383. BOOL FlashWindowEx(DWORD dwFlags, UINT uCount, DWORD dwTimeout = 0)
  384. {
  385. ATLASSERT(::IsWindow(m_hWnd));
  386. FLASHWINFO fi = { sizeof(FLASHWINFO) };
  387. fi.hwnd = m_hWnd;
  388. fi.dwFlags = dwFlags;
  389. fi.uCount = uCount;
  390. fi.dwTimeout = dwTimeout;
  391. return ::FlashWindowEx(&fi);
  392. }
  393. BOOL StopFlashWindowEx()
  394. {
  395. ATLASSERT(::IsWindow(m_hWnd));
  396. FLASHWINFO fi = { sizeof(FLASHWINFO) };
  397. fi.hwnd = m_hWnd;
  398. fi.dwFlags = FLASHW_STOP;
  399. return ::FlashWindowEx(&fi);
  400. }
  401. // Class long properties
  402. DWORD GetClassLong(int nIndex) const
  403. {
  404. ATLASSERT(::IsWindow(m_hWnd));
  405. return ::GetClassLong(m_hWnd, nIndex);
  406. }
  407. DWORD SetClassLong(int nIndex, LONG dwNewLong)
  408. {
  409. ATLASSERT(::IsWindow(m_hWnd));
  410. return ::SetClassLong(m_hWnd, nIndex, dwNewLong);
  411. }
  412. ULONG_PTR GetClassLongPtr(int nIndex) const
  413. {
  414. ATLASSERT(::IsWindow(m_hWnd));
  415. return ::GetClassLongPtr(m_hWnd, nIndex);
  416. }
  417. ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong)
  418. {
  419. ATLASSERT(::IsWindow(m_hWnd));
  420. return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);
  421. }
  422. // Layered windows
  423. BOOL SetLayeredWindowAttributes(COLORREF crlKey, BYTE byteAlpha, DWORD dwFlags)
  424. {
  425. ATLASSERT(::IsWindow(m_hWnd));
  426. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  427. return ::SetLayeredWindowAttributes(m_hWnd, crlKey, byteAlpha, dwFlags);
  428. }
  429. BOOL UpdateLayeredWindow(HDC hdcDst, LPPOINT pptDst, LPSIZE psize, HDC hdcSrc, LPPOINT pptSrc, COLORREF crlKey, BLENDFUNCTION* pblend, DWORD dwFlags)
  430. {
  431. ATLASSERT(::IsWindow(m_hWnd));
  432. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  433. return ::UpdateLayeredWindow(m_hWnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crlKey, pblend, dwFlags);
  434. }
  435. BOOL UpdateLayeredWindow(LPPOINT pptDst = NULL)
  436. {
  437. ATLASSERT(::IsWindow(m_hWnd));
  438. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  439. return ::UpdateLayeredWindow(m_hWnd, NULL, pptDst, NULL, NULL, NULL, CLR_NONE, NULL, 0);
  440. }
  441. BOOL GetLayeredWindowAttributes(COLORREF* pcrlKey, BYTE* pbyteAlpha, DWORD* pdwFlags) const
  442. {
  443. ATLASSERT(::IsWindow(m_hWnd));
  444. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  445. return ::GetLayeredWindowAttributes(m_hWnd, pcrlKey, pbyteAlpha, pdwFlags);
  446. }
  447. // Mouse tracking
  448. BOOL StartTrackMouseLeave()
  449. {
  450. ATLASSERT(::IsWindow(m_hWnd));
  451. TRACKMOUSEEVENT tme = {};
  452. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  453. tme.dwFlags = TME_LEAVE;
  454. tme.hwndTrack = m_hWnd;
  455. return ::TrackMouseEvent(&tme);
  456. }
  457. BOOL StartTrackMouse(DWORD dwFlags, DWORD dwHoverTime = HOVER_DEFAULT)
  458. {
  459. ATLASSERT(::IsWindow(m_hWnd));
  460. TRACKMOUSEEVENT tme = {};
  461. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  462. tme.dwFlags = dwFlags;
  463. tme.hwndTrack = m_hWnd;
  464. tme.dwHoverTime = dwHoverTime;
  465. return ::TrackMouseEvent(&tme);
  466. }
  467. BOOL CancelTrackMouse(DWORD dwType)
  468. {
  469. ATLASSERT(::IsWindow(m_hWnd));
  470. TRACKMOUSEEVENT tme = {};
  471. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  472. tme.dwFlags = TME_CANCEL | dwType;
  473. tme.hwndTrack = m_hWnd;
  474. return ::TrackMouseEvent(&tme);
  475. }
  476. // CString support
  477. #ifdef __ATLSTR_H__
  478. int GetWindowText(ATL::CString& strText) const
  479. {
  480. int nLength = GetWindowTextLength();
  481. LPTSTR pszText = strText.GetBuffer(nLength + 1);
  482. nLength = ::GetWindowText(m_hWnd, pszText, nLength + 1);
  483. strText.ReleaseBuffer(nLength);
  484. return nLength;
  485. }
  486. UINT GetDlgItemText(int nID, ATL::CString& strText) const
  487. {
  488. ATLASSERT(::IsWindow(m_hWnd));
  489. HWND hItem = GetDlgItem(nID);
  490. if(hItem != NULL)
  491. {
  492. int nLength = ::GetWindowTextLength(hItem);
  493. LPTSTR pszText = strText.GetBuffer(nLength + 1);
  494. nLength = ::GetWindowText(hItem, pszText, nLength + 1);
  495. strText.ReleaseBuffer(nLength);
  496. return nLength;
  497. }
  498. else
  499. {
  500. strText.Empty();
  501. return 0;
  502. }
  503. }
  504. #endif // __ATLSTR_H__
  505. };
  506. } // namespace WTL
  507. #endif // __ATLWINX_H__