atlwinx.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. case WM_CTLCOLORBTN:
  140. case WM_CTLCOLORDLG:
  141. case WM_CTLCOLOREDIT:
  142. case WM_CTLCOLORLISTBOX:
  143. case WM_CTLCOLORMSGBOX:
  144. case WM_CTLCOLORSCROLLBAR:
  145. case WM_CTLCOLORSTATIC:
  146. hWndChild = (HWND)lParam;
  147. idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
  148. break;
  149. default:
  150. break;
  151. }
  152. if((hWndChild == NULL) ||
  153. ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
  154. {
  155. // Either hWndChild isn't valid, or
  156. // hWndChild doesn't match the filter.
  157. bHandled = FALSE;
  158. return 1;
  159. }
  160. if((idFromFilter != 0) && (idFromFilter != idFrom))
  161. {
  162. // The dialog control id doesn't match the filter.
  163. bHandled = FALSE;
  164. return 1;
  165. }
  166. ATLASSERT(::IsWindow(hWndChild));
  167. LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  168. if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
  169. {
  170. // Try to prevent problems with WM_CTLCOLOR* messages when
  171. // the message wasn't really handled
  172. bHandled = FALSE;
  173. }
  174. return lResult;
  175. }
  176. } // namespace WTL
  177. // Try to prevent problems with WM_CTLCOLOR* messages when
  178. // the message wasn't really handled
  179. #define REFLECT_NOTIFICATIONS_EX() \
  180. { \
  181. bHandled = TRUE; \
  182. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  183. if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
  184. bHandled = FALSE; \
  185. if(bHandled) \
  186. return TRUE; \
  187. }
  188. #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
  189. { \
  190. bHandled = TRUE; \
  191. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
  192. if(bHandled) \
  193. return TRUE; \
  194. }
  195. #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
  196. { \
  197. bHandled = TRUE; \
  198. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
  199. if(bHandled) \
  200. return TRUE; \
  201. }
  202. #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
  203. { \
  204. bHandled = TRUE; \
  205. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
  206. if(bHandled) \
  207. return TRUE; \
  208. }
  209. #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
  210. { \
  211. bHandled = TRUE; \
  212. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
  213. if(bHandled) \
  214. return TRUE; \
  215. }
  216. #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
  217. { \
  218. bHandled = TRUE; \
  219. lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
  220. if(bHandled) \
  221. return TRUE; \
  222. }
  223. #define REFLECT_COMMAND(id, code) \
  224. if((uMsg == WM_COMMAND) && (id == LOWORD(wParam)) && (code == HIWORD(wParam))) \
  225. { \
  226. bHandled = TRUE; \
  227. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  228. if(bHandled) \
  229. return TRUE; \
  230. }
  231. #define REFLECT_COMMAND_ID(id) \
  232. if((uMsg == WM_COMMAND) && (id == LOWORD(wParam))) \
  233. { \
  234. bHandled = TRUE; \
  235. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  236. if(bHandled) \
  237. return TRUE; \
  238. }
  239. #define REFLECT_COMMAND_CODE(code) \
  240. if((uMsg == WM_COMMAND) && (code == HIWORD(wParam))) \
  241. { \
  242. bHandled = TRUE; \
  243. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  244. if(bHandled) \
  245. return TRUE; \
  246. }
  247. #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
  248. if((uMsg == WM_COMMAND) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
  249. { \
  250. bHandled = TRUE; \
  251. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  252. if(bHandled) \
  253. return TRUE; \
  254. }
  255. #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
  256. if((uMsg == WM_COMMAND) && (code == HIWORD(wParam)) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
  257. { \
  258. bHandled = TRUE; \
  259. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  260. if(bHandled) \
  261. return TRUE; \
  262. }
  263. #define REFLECT_NOTIFY(id, cd) \
  264. if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom) && (cd == ((LPNMHDR)lParam)->code)) \
  265. { \
  266. bHandled = TRUE; \
  267. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  268. if(bHandled) \
  269. return TRUE; \
  270. }
  271. #define REFLECT_NOTIFY_ID(id) \
  272. if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom)) \
  273. { \
  274. bHandled = TRUE; \
  275. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  276. if(bHandled) \
  277. return TRUE; \
  278. }
  279. #define REFLECT_NOTIFY_CODE(cd) \
  280. if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code)) \
  281. { \
  282. bHandled = TRUE; \
  283. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  284. if(bHandled) \
  285. return TRUE; \
  286. }
  287. #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
  288. if((uMsg == WM_NOTIFY) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
  289. { \
  290. bHandled = TRUE; \
  291. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  292. if(bHandled) \
  293. return TRUE; \
  294. }
  295. #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
  296. if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
  297. { \
  298. bHandled = TRUE; \
  299. lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
  300. if(bHandled) \
  301. return TRUE; \
  302. }
  303. ///////////////////////////////////////////////////////////////////////////////
  304. // GetClassLong/SetClassLong redefinition to avoid problems with class members
  305. #ifdef SetClassLongPtrA
  306. #undef SetClassLongPtrA
  307. inline LONG_PTR SetClassLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  308. {
  309. return ::SetClassLongA(hWnd, nIndex, LONG(dwNewLong));
  310. }
  311. #endif
  312. #ifdef SetClassLongPtrW
  313. #undef SetClassLongPtrW
  314. inline LONG_PTR SetClassLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  315. {
  316. return ::SetClassLongW(hWnd, nIndex, LONG(dwNewLong));
  317. }
  318. #endif
  319. #ifdef GetClassLongPtrA
  320. #undef GetClassLongPtrA
  321. inline LONG_PTR GetClassLongPtrA(HWND hWnd, int nIndex)
  322. {
  323. return ::GetClassLongA(hWnd, nIndex);
  324. }
  325. #endif
  326. #ifdef GetClassLongPtrW
  327. #undef GetClassLongPtrW
  328. inline LONG_PTR GetClassLongPtrW(HWND hWnd, int nIndex)
  329. {
  330. return ::GetClassLongW(hWnd, nIndex);
  331. }
  332. #endif
  333. ///////////////////////////////////////////////////////////////////////////////
  334. // CWindowEx - extension of ATL::CWindow
  335. namespace WTL
  336. {
  337. class CWindowEx : public ATL::CWindow
  338. {
  339. public:
  340. CWindowEx(HWND hWnd = NULL) : ATL::CWindow(hWnd)
  341. { }
  342. CWindowEx& operator =(HWND hWnd)
  343. {
  344. m_hWnd = hWnd;
  345. return *this;
  346. }
  347. operator HWND() const
  348. {
  349. return m_hWnd;
  350. }
  351. // Methods
  352. BOOL PrintWindow(HDC hDC, UINT uFlags = 0)
  353. {
  354. ATLASSERT(::IsWindow(m_hWnd));
  355. return ::PrintWindow(m_hWnd, hDC, uFlags);
  356. }
  357. BOOL DragDetect(POINT pt)
  358. {
  359. ATLASSERT(::IsWindow(m_hWnd));
  360. return ::DragDetect(m_hWnd, pt);
  361. }
  362. BOOL DragDetect()
  363. {
  364. ATLASSERT(::IsWindow(m_hWnd));
  365. POINT pt = {};
  366. ::GetCursorPos(&pt);
  367. return ::DragDetect(m_hWnd, pt);
  368. }
  369. CWindowEx GetAncestor(UINT uFlags) const
  370. {
  371. ATLASSERT(::IsWindow(m_hWnd));
  372. return CWindowEx(::GetAncestor(m_hWnd, uFlags));
  373. }
  374. // Note: Does not work properly on Vista Aero and above
  375. BOOL AnimateWindow(DWORD dwFlags, DWORD dwTime = 200)
  376. {
  377. ATLASSERT(::IsWindow(m_hWnd));
  378. return ::AnimateWindow(m_hWnd, dwTime, dwFlags);
  379. }
  380. BOOL FlashWindowEx(DWORD dwFlags, UINT uCount, DWORD dwTimeout = 0)
  381. {
  382. ATLASSERT(::IsWindow(m_hWnd));
  383. FLASHWINFO fi = { sizeof(FLASHWINFO) };
  384. fi.hwnd = m_hWnd;
  385. fi.dwFlags = dwFlags;
  386. fi.uCount = uCount;
  387. fi.dwTimeout = dwTimeout;
  388. return ::FlashWindowEx(&fi);
  389. }
  390. BOOL StopFlashWindowEx()
  391. {
  392. ATLASSERT(::IsWindow(m_hWnd));
  393. FLASHWINFO fi = { sizeof(FLASHWINFO) };
  394. fi.hwnd = m_hWnd;
  395. fi.dwFlags = FLASHW_STOP;
  396. return ::FlashWindowEx(&fi);
  397. }
  398. // Class long properties
  399. DWORD GetClassLong(int nIndex) const
  400. {
  401. ATLASSERT(::IsWindow(m_hWnd));
  402. return ::GetClassLong(m_hWnd, nIndex);
  403. }
  404. DWORD SetClassLong(int nIndex, LONG dwNewLong)
  405. {
  406. ATLASSERT(::IsWindow(m_hWnd));
  407. return ::SetClassLong(m_hWnd, nIndex, dwNewLong);
  408. }
  409. ULONG_PTR GetClassLongPtr(int nIndex) const
  410. {
  411. ATLASSERT(::IsWindow(m_hWnd));
  412. return ::GetClassLongPtr(m_hWnd, nIndex);
  413. }
  414. ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong)
  415. {
  416. ATLASSERT(::IsWindow(m_hWnd));
  417. return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);
  418. }
  419. // Layered windows
  420. BOOL SetLayeredWindowAttributes(COLORREF crlKey, BYTE byteAlpha, DWORD dwFlags)
  421. {
  422. ATLASSERT(::IsWindow(m_hWnd));
  423. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  424. return ::SetLayeredWindowAttributes(m_hWnd, crlKey, byteAlpha, dwFlags);
  425. }
  426. BOOL UpdateLayeredWindow(HDC hdcDst, LPPOINT pptDst, LPSIZE psize, HDC hdcSrc, LPPOINT pptSrc, COLORREF crlKey, BLENDFUNCTION* pblend, DWORD dwFlags)
  427. {
  428. ATLASSERT(::IsWindow(m_hWnd));
  429. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  430. return ::UpdateLayeredWindow(m_hWnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crlKey, pblend, dwFlags);
  431. }
  432. BOOL UpdateLayeredWindow(LPPOINT pptDst = NULL)
  433. {
  434. ATLASSERT(::IsWindow(m_hWnd));
  435. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  436. return ::UpdateLayeredWindow(m_hWnd, NULL, pptDst, NULL, NULL, NULL, CLR_NONE, NULL, 0);
  437. }
  438. BOOL GetLayeredWindowAttributes(COLORREF* pcrlKey, BYTE* pbyteAlpha, DWORD* pdwFlags) const
  439. {
  440. ATLASSERT(::IsWindow(m_hWnd));
  441. ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
  442. return ::GetLayeredWindowAttributes(m_hWnd, pcrlKey, pbyteAlpha, pdwFlags);
  443. }
  444. // Mouse tracking
  445. BOOL StartTrackMouseLeave()
  446. {
  447. ATLASSERT(::IsWindow(m_hWnd));
  448. TRACKMOUSEEVENT tme = {};
  449. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  450. tme.dwFlags = TME_LEAVE;
  451. tme.hwndTrack = m_hWnd;
  452. return ::TrackMouseEvent(&tme);
  453. }
  454. BOOL StartTrackMouse(DWORD dwFlags, DWORD dwHoverTime = HOVER_DEFAULT)
  455. {
  456. ATLASSERT(::IsWindow(m_hWnd));
  457. TRACKMOUSEEVENT tme = {};
  458. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  459. tme.dwFlags = dwFlags;
  460. tme.hwndTrack = m_hWnd;
  461. tme.dwHoverTime = dwHoverTime;
  462. return ::TrackMouseEvent(&tme);
  463. }
  464. BOOL CancelTrackMouse(DWORD dwType)
  465. {
  466. ATLASSERT(::IsWindow(m_hWnd));
  467. TRACKMOUSEEVENT tme = {};
  468. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  469. tme.dwFlags = TME_CANCEL | dwType;
  470. tme.hwndTrack = m_hWnd;
  471. return ::TrackMouseEvent(&tme);
  472. }
  473. // CString support
  474. #ifdef __ATLSTR_H__
  475. int GetWindowText(ATL::CString& strText) const
  476. {
  477. int nLength = GetWindowTextLength();
  478. LPTSTR pszText = strText.GetBuffer(nLength + 1);
  479. nLength = ::GetWindowText(m_hWnd, pszText, nLength + 1);
  480. strText.ReleaseBuffer(nLength);
  481. return nLength;
  482. }
  483. UINT GetDlgItemText(int nID, ATL::CString& strText) const
  484. {
  485. ATLASSERT(::IsWindow(m_hWnd));
  486. HWND hItem = GetDlgItem(nID);
  487. if(hItem != NULL)
  488. {
  489. int nLength = ::GetWindowTextLength(hItem);
  490. LPTSTR pszText = strText.GetBuffer(nLength + 1);
  491. nLength = ::GetWindowText(hItem, pszText, nLength + 1);
  492. strText.ReleaseBuffer(nLength);
  493. return nLength;
  494. }
  495. else
  496. {
  497. strText.Empty();
  498. return 0;
  499. }
  500. }
  501. #endif // __ATLSTR_H__
  502. // Dialog window only
  503. UINT DlgGetDefID() const
  504. {
  505. ATLASSERT(::IsWindow(m_hWnd));
  506. LRESULT lRet = ::SendMessage(m_hWnd, DM_GETDEFID, 0, 0L);
  507. UINT uID = 0U;
  508. if(HIWORD(lRet) == DC_HASDEFID)
  509. uID = LOWORD(lRet);
  510. return uID;
  511. }
  512. void DlgSetDefID(UINT uID)
  513. {
  514. ATLASSERT(::IsWindow(m_hWnd));
  515. ::SendMessage(m_hWnd, DM_SETDEFID, uID, 0L);
  516. }
  517. void DlgReposition()
  518. {
  519. ATLASSERT(::IsWindow(m_hWnd));
  520. ::SendMessage(m_hWnd, DM_REPOSITION, 0, 0L);
  521. }
  522. };
  523. } // namespace WTL
  524. #endif // __ATLWINX_H__