summaryrefslogtreecommitdiffstats
path: root/Examples/WhisperDesktop/Utils/WTL/atlwinx.h
blob: b89c513782be1e29f7f7a1b05e13c3e143d1a721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.

#ifndef __ATLWINX_H__
#define __ATLWINX_H__

#pragma once

#ifndef __ATLAPP_H__
	#error atlwinx.h requires atlapp.h to be included first
#endif

#include <atlwin.h>


///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CWindowEx


/////////////////////////////////////////////////////////////////////////////
// Additional macros needed for template classes

#ifndef DECLARE_WND_CLASS_EX2
  #define DECLARE_WND_CLASS_EX2(WndClassName, EnclosingClass, style, bkgnd) \
  static ATL::CWndClassInfo& GetWndClassInfo() \
  { \
	static ATL::CWndClassInfo wc = \
	{ \
		{ sizeof(WNDCLASSEX), style, EnclosingClass::StartWindowProc, \
		  0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, \
		  NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
	}; \
	return wc; \
  }
#endif // DECLARE_WND_CLASS_EX2

#ifndef DECLARE_WND_SUPERCLASS2
  #define DECLARE_WND_SUPERCLASS2(WndClassName, EnclosingClass, OrigWndClassName) \
  static ATL::CWndClassInfo& GetWndClassInfo() \
  { \
	static ATL::CWndClassInfo wc = \
	{ \
		{ sizeof(WNDCLASSEX), 0, EnclosingClass::StartWindowProc, \
		  0, 0, NULL, NULL, NULL, NULL, NULL, WndClassName, NULL }, \
		  OrigWndClassName, NULL, NULL, TRUE, 0, _T("") \
	}; \
	return wc; \
  }
#endif // DECLARE_WND_SUPERCLASS2


///////////////////////////////////////////////////////////////////////////////
// Command Chaining Macros

#define CHAIN_COMMANDS(theChainClass) \
	if(uMsg == WM_COMMAND) \
		CHAIN_MSG_MAP(theChainClass)

#define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
	if(uMsg == WM_COMMAND) \
		CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)

#define CHAIN_COMMANDS_MEMBER(theChainMember) \
	if(uMsg == WM_COMMAND) \
		CHAIN_MSG_MAP_MEMBER(theChainMember)

#define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
	if(uMsg == WM_COMMAND) \
		CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)


///////////////////////////////////////////////////////////////////////////////
// Macros for parent message map to selectively reflect control messages

// NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
//  (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
//  Since we can't modify ATL, we'll provide the needed additions
//  in a separate function (that is not a member of CWindowImplRoot)

namespace WTL
{

inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
                                               UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
{
	if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
	{
		// The notification message doesn't match the filter.
		bHandled = FALSE;
		return 1;
	}

	HWND hWndChild = NULL;
	UINT_PTR idFrom = 0;

	switch(uMsg)
	{
	case WM_COMMAND:
		if(lParam != NULL)	// not from a menu
		{
			hWndChild = (HWND)lParam;
			idFrom = (UINT_PTR)LOWORD(wParam);
		}
		break;
	case WM_NOTIFY:
		hWndChild = ((LPNMHDR)lParam)->hwndFrom;
		idFrom = ((LPNMHDR)lParam)->idFrom;
		break;
	case WM_PARENTNOTIFY:
		switch(LOWORD(wParam))
		{
		case WM_CREATE:
		case WM_DESTROY:
			hWndChild = (HWND)lParam;
			idFrom = (UINT_PTR)HIWORD(wParam);
			break;
		default:
			hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
			idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
			break;
		}
		break;
	case WM_DRAWITEM:
		if(wParam)	// not from a menu
		{
			hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
			idFrom = (UINT_PTR)wParam;
		}
		break;
	case WM_MEASUREITEM:
		if(wParam)	// not from a menu
		{
			hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
			idFrom = (UINT_PTR)wParam;
		}
		break;
	case WM_COMPAREITEM:
		if(wParam)	// not from a menu
		{
			hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
			idFrom = (UINT_PTR)wParam;
		}
		break;
	case WM_DELETEITEM:
		if(wParam)	// not from a menu
		{
			hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
			idFrom = (UINT_PTR)wParam;
		}
		break;
	case WM_VKEYTOITEM:
	case WM_CHARTOITEM:
	case WM_HSCROLL:
	case WM_VSCROLL:
	case WM_CTLCOLORBTN:
	case WM_CTLCOLORDLG:
	case WM_CTLCOLOREDIT:
	case WM_CTLCOLORLISTBOX:
	case WM_CTLCOLORMSGBOX:
	case WM_CTLCOLORSCROLLBAR:
	case WM_CTLCOLORSTATIC:
		hWndChild = (HWND)lParam;
		idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
		break;
	default:
		break;
	}

	if((hWndChild == NULL) ||
		((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
	{
		// Either hWndChild isn't valid, or
		// hWndChild doesn't match the filter.
		bHandled = FALSE;
		return 1;
	}

	if((idFromFilter != 0) && (idFromFilter != idFrom))
	{
		// The dialog control id doesn't match the filter.
		bHandled = FALSE;
		return 1;
	}

	ATLASSERT(::IsWindow(hWndChild));
	LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
	if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
	{
		// Try to prevent problems with WM_CTLCOLOR* messages when
		// the message wasn't really handled
		bHandled = FALSE;
	}

	return lResult;
}

} // namespace WTL

// Try to prevent problems with WM_CTLCOLOR* messages when
// the message wasn't really handled
#define REFLECT_NOTIFICATIONS_EX() \
{ \
	bHandled = TRUE; \
	lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
	if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
		bHandled = FALSE; \
	if(bHandled) \
		return TRUE; \
}

#define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
	{ \
		bHandled = TRUE; \
		lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
	{ \
		bHandled = TRUE; \
		lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
	{ \
		bHandled = TRUE; \
		lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
	{ \
		bHandled = TRUE; \
		lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
	{ \
		bHandled = TRUE; \
		lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_COMMAND(id, code) \
	if((uMsg == WM_COMMAND) && (id == LOWORD(wParam)) && (code == HIWORD(wParam))) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_COMMAND_ID(id) \
	if((uMsg == WM_COMMAND) && (id == LOWORD(wParam))) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_COMMAND_CODE(code) \
	if((uMsg == WM_COMMAND) && (code == HIWORD(wParam))) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_COMMAND_RANGE(idFirst, idLast) \
	if((uMsg == WM_COMMAND) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
	if((uMsg == WM_COMMAND) && (code == HIWORD(wParam)) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFY(id, cd) \
	if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom) && (cd == ((LPNMHDR)lParam)->code)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFY_ID(id) \
	if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFY_CODE(cd) \
	if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
	if((uMsg == WM_NOTIFY) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}

#define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
	if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
	{ \
		bHandled = TRUE; \
		lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
		if(bHandled) \
			return TRUE; \
	}


///////////////////////////////////////////////////////////////////////////////
// GetClassLong/SetClassLong redefinition to avoid problems with class members

#ifdef SetClassLongPtrA
  #undef SetClassLongPtrA
  inline LONG_PTR SetClassLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  {
	return ::SetClassLongA(hWnd, nIndex, LONG(dwNewLong));
  }
#endif

#ifdef SetClassLongPtrW
  #undef SetClassLongPtrW
  inline LONG_PTR SetClassLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  {
	return ::SetClassLongW(hWnd, nIndex, LONG(dwNewLong));
  }
#endif

#ifdef GetClassLongPtrA
  #undef GetClassLongPtrA
  inline LONG_PTR GetClassLongPtrA(HWND hWnd, int nIndex)
  {
	return ::GetClassLongA(hWnd, nIndex);
  }
#endif

#ifdef GetClassLongPtrW
  #undef GetClassLongPtrW
  inline LONG_PTR GetClassLongPtrW(HWND hWnd, int nIndex)
  {
	return ::GetClassLongW(hWnd, nIndex);
  }
#endif


///////////////////////////////////////////////////////////////////////////////
// CWindowEx - extension of ATL::CWindow

namespace WTL
{

class CWindowEx : public ATL::CWindow
{
public:
	CWindowEx(HWND hWnd = NULL) : ATL::CWindow(hWnd)
	{ }

	CWindowEx& operator =(HWND hWnd)
	{
		m_hWnd = hWnd;
		return *this;
	}

	operator HWND() const
	{
		return m_hWnd;
	}

// Methods
	BOOL PrintWindow(HDC hDC, UINT uFlags = 0)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::PrintWindow(m_hWnd, hDC, uFlags);
	}

	BOOL DragDetect(POINT pt)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::DragDetect(m_hWnd, pt);
	}

	BOOL DragDetect()
	{
		ATLASSERT(::IsWindow(m_hWnd));

		POINT pt = {};
		::GetCursorPos(&pt);
		return ::DragDetect(m_hWnd, pt);
	}

	CWindowEx GetAncestor(UINT uFlags) const
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return CWindowEx(::GetAncestor(m_hWnd, uFlags));
	}

	// Note: Does not work properly on Vista Aero and above
	BOOL AnimateWindow(DWORD dwFlags, DWORD dwTime = 200)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::AnimateWindow(m_hWnd, dwTime, dwFlags);
	}

	BOOL FlashWindowEx(DWORD dwFlags, UINT uCount, DWORD dwTimeout = 0)
	{
		ATLASSERT(::IsWindow(m_hWnd));

		FLASHWINFO fi = { sizeof(FLASHWINFO) };
		fi.hwnd = m_hWnd;
		fi.dwFlags = dwFlags;
		fi.uCount = uCount;
		fi.dwTimeout = dwTimeout;
		return ::FlashWindowEx(&fi);
	}

	BOOL StopFlashWindowEx()
	{
		ATLASSERT(::IsWindow(m_hWnd));

		FLASHWINFO fi = { sizeof(FLASHWINFO) };
		fi.hwnd = m_hWnd;
		fi.dwFlags = FLASHW_STOP;
		return ::FlashWindowEx(&fi);
	}

// Class long properties
	DWORD GetClassLong(int nIndex) const
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::GetClassLong(m_hWnd, nIndex);
	}

	DWORD SetClassLong(int nIndex, LONG dwNewLong)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::SetClassLong(m_hWnd, nIndex, dwNewLong);
	}

	ULONG_PTR GetClassLongPtr(int nIndex) const
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::GetClassLongPtr(m_hWnd, nIndex);
	}

	ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);
	}

// Layered windows
	BOOL SetLayeredWindowAttributes(COLORREF crlKey, BYTE byteAlpha, DWORD dwFlags)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);

		return ::SetLayeredWindowAttributes(m_hWnd, crlKey, byteAlpha, dwFlags);
	}

	BOOL UpdateLayeredWindow(HDC hdcDst, LPPOINT pptDst, LPSIZE psize, HDC hdcSrc, LPPOINT pptSrc, COLORREF crlKey, BLENDFUNCTION* pblend, DWORD dwFlags)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);

		return ::UpdateLayeredWindow(m_hWnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crlKey, pblend, dwFlags);
	}

	BOOL UpdateLayeredWindow(LPPOINT pptDst = NULL)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);

		return ::UpdateLayeredWindow(m_hWnd, NULL, pptDst, NULL, NULL, NULL, CLR_NONE, NULL, 0);
	}

	BOOL GetLayeredWindowAttributes(COLORREF* pcrlKey, BYTE* pbyteAlpha, DWORD* pdwFlags) const
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);

		return ::GetLayeredWindowAttributes(m_hWnd, pcrlKey, pbyteAlpha, pdwFlags);
	}

// Mouse tracking
	BOOL StartTrackMouseLeave()
	{
		ATLASSERT(::IsWindow(m_hWnd));

		TRACKMOUSEEVENT tme = {};
		tme.cbSize = sizeof(TRACKMOUSEEVENT);
		tme.dwFlags = TME_LEAVE;
		tme.hwndTrack = m_hWnd;
		return ::TrackMouseEvent(&tme);
	}

	BOOL StartTrackMouse(DWORD dwFlags, DWORD dwHoverTime = HOVER_DEFAULT)
	{
		ATLASSERT(::IsWindow(m_hWnd));

		TRACKMOUSEEVENT tme = {};
		tme.cbSize = sizeof(TRACKMOUSEEVENT);
		tme.dwFlags = dwFlags;
		tme.hwndTrack = m_hWnd;
		tme.dwHoverTime = dwHoverTime;
		return ::TrackMouseEvent(&tme);
	}

	BOOL CancelTrackMouse(DWORD dwType)
	{
		ATLASSERT(::IsWindow(m_hWnd));

		TRACKMOUSEEVENT tme = {};
		tme.cbSize = sizeof(TRACKMOUSEEVENT);
		tme.dwFlags = TME_CANCEL | dwType;
		tme.hwndTrack = m_hWnd;
		return ::TrackMouseEvent(&tme);
	}

// CString support
#ifdef __ATLSTR_H__
	int GetWindowText(ATL::CString& strText) const
	{
		int nLength = GetWindowTextLength();
		LPTSTR pszText = strText.GetBuffer(nLength + 1);
		nLength = ::GetWindowText(m_hWnd, pszText, nLength + 1);
		strText.ReleaseBuffer(nLength);

		return nLength;
	}

	UINT GetDlgItemText(int nID, ATL::CString& strText) const
	{
		ATLASSERT(::IsWindow(m_hWnd));

		HWND hItem = GetDlgItem(nID);
		if(hItem != NULL)
		{
			int nLength = ::GetWindowTextLength(hItem);
			LPTSTR pszText = strText.GetBuffer(nLength + 1);
			nLength = ::GetWindowText(hItem, pszText, nLength + 1);
			strText.ReleaseBuffer(nLength);

			return nLength;
		}
		else
		{
			strText.Empty();

			return 0;
		}
	}
#endif // __ATLSTR_H__

// Dialog window only
	UINT DlgGetDefID() const
	{
		ATLASSERT(::IsWindow(m_hWnd));

		LRESULT lRet = ::SendMessage(m_hWnd, DM_GETDEFID, 0, 0L);
		UINT uID = 0U;
		if(HIWORD(lRet) == DC_HASDEFID)
			uID = LOWORD(lRet);

		return uID;
	}

	void DlgSetDefID(UINT uID)
	{
		ATLASSERT(::IsWindow(m_hWnd));

		::SendMessage(m_hWnd, DM_SETDEFID, uID, 0L);
	}

	void DlgReposition()
	{
		ATLASSERT(::IsWindow(m_hWnd));

		::SendMessage(m_hWnd, DM_REPOSITION, 0, 0L);
	}
};

} // namespace WTL

#endif // __ATLWINX_H__