1 // Windows Template Library - WTL version 9.0
2 // Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
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 // Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
7 // which can be found in the file CPL.TXT at the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by
9 // the terms of this license. You must not remove this notice, or
10 // any other, from this software.
18 #error atluser.h requires atlapp.h to be included first
22 ///////////////////////////////////////////////////////////////////////////////
23 // Classes in this file:
27 // CAcceleratorT<t_bManaged>
29 // CCursorT<t_bManaged>
35 // AtlLoadAccelerators()
43 // AtlLoadBitmapImage()
44 // AtlLoadCursorImage()
46 // AtlLoadSysBitmapImage()
47 // AtlLoadSysCursorImage()
48 // AtlLoadSysIconImage()
55 ///////////////////////////////////////////////////////////////////////////////
56 // AtlMessageBox - accepts both memory and resource based strings
58 inline int AtlMessageBox(HWND hWndOwner
, ATL::_U_STRINGorID message
, ATL::_U_STRINGorID title
= (LPCTSTR
)NULL
, UINT uType
= MB_OK
| MB_ICONINFORMATION
)
60 ATLASSERT(hWndOwner
== NULL
|| ::IsWindow(hWndOwner
));
62 LPTSTR lpstrMessage
= NULL
;
63 if(IS_INTRESOURCE(message
.m_lpstr
))
65 for(int nLen
= 256; ; nLen
*= 2)
67 ATLTRY(lpstrMessage
= new TCHAR
[nLen
]);
68 if(lpstrMessage
== NULL
)
73 int nRes
= ::LoadString(ModuleHelper::GetResourceInstance(), LOWORD(message
.m_lpstr
), lpstrMessage
, nLen
);
76 delete [] lpstrMessage
;
80 message
.m_lpstr
= lpstrMessage
;
83 LPTSTR lpstrTitle
= NULL
;
84 if(IS_INTRESOURCE(title
.m_lpstr
) && LOWORD(title
.m_lpstr
) != 0)
86 for(int nLen
= 256; ; nLen
*= 2)
88 ATLTRY(lpstrTitle
= new TCHAR
[nLen
]);
89 if(lpstrTitle
== NULL
)
94 int nRes
= ::LoadString(ModuleHelper::GetResourceInstance(), LOWORD(title
.m_lpstr
), lpstrTitle
, nLen
);
101 title
.m_lpstr
= lpstrTitle
;
104 int nRet
= ::MessageBox(hWndOwner
, message
.m_lpstr
, title
.m_lpstr
, uType
);
106 delete [] lpstrMessage
;
107 delete [] lpstrTitle
;
113 ///////////////////////////////////////////////////////////////////////////////
116 #if (WINVER >= 0x0500)
117 #ifndef MII_SIZEOF_STRUCT
118 #define MII_SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
120 #define MENUITEMINFO_SIZE_VERSION_400A MII_SIZEOF_STRUCT(MENUITEMINFOA, cch)
121 #define MENUITEMINFO_SIZE_VERSION_400W MII_SIZEOF_STRUCT(MENUITEMINFOW, cch)
123 #define MENUITEMINFO_SIZE_VERSION_400 MENUITEMINFO_SIZE_VERSION_400W
125 #define MENUITEMINFO_SIZE_VERSION_400 MENUITEMINFO_SIZE_VERSION_400A
127 #endif // (WINVER >= 0x0500)
129 class CMenuItemInfo
: public MENUITEMINFO
134 memset(this, 0, sizeof(MENUITEMINFO
));
135 cbSize
= sizeof(MENUITEMINFO
);
136 #if (WINVER >= 0x0500)
137 // adjust struct size if running on older version of Windows
138 if(AtlIsOldWindows())
140 ATLASSERT(cbSize
> MENUITEMINFO_SIZE_VERSION_400
); // must be
141 cbSize
= MENUITEMINFO_SIZE_VERSION_400
;
143 #endif // (WINVER >= 0x0500)
148 // forward declarations
149 template <bool t_bManaged
> class CMenuT
;
150 typedef CMenuT
<false> CMenuHandle
;
151 typedef CMenuT
<true> CMenu
;
154 template <bool t_bManaged
>
161 // Constructor/destructor/operators
162 CMenuT(HMENU hMenu
= NULL
) : m_hMenu(hMenu
)
167 if(t_bManaged
&& m_hMenu
!= NULL
)
171 CMenuT
<t_bManaged
>& operator =(HMENU hMenu
)
177 void Attach(HMENU hMenuNew
)
179 ATLASSERT(::IsMenu(hMenuNew
));
180 if(t_bManaged
&& m_hMenu
!= NULL
&& m_hMenu
!= hMenuNew
)
181 ::DestroyMenu(m_hMenu
);
187 HMENU hMenu
= m_hMenu
;
192 operator HMENU() const { return m_hMenu
; }
194 bool IsNull() const { return (m_hMenu
== NULL
); }
198 return ::IsMenu(m_hMenu
);
201 // Create/destroy methods
204 ATLASSERT(m_hMenu
== NULL
);
205 m_hMenu
= ::CreateMenu();
206 return (m_hMenu
!= NULL
) ? TRUE
: FALSE
;
209 BOOL
CreatePopupMenu()
211 ATLASSERT(m_hMenu
== NULL
);
212 m_hMenu
= ::CreatePopupMenu();
213 return (m_hMenu
!= NULL
) ? TRUE
: FALSE
;
216 BOOL
LoadMenu(ATL::_U_STRINGorID menu
)
218 ATLASSERT(m_hMenu
== NULL
);
219 m_hMenu
= ::LoadMenu(ModuleHelper::GetResourceInstance(), menu
.m_lpstr
);
220 return (m_hMenu
!= NULL
) ? TRUE
: FALSE
;
224 BOOL
LoadMenuIndirect(const void* lpMenuTemplate
)
226 ATLASSERT(m_hMenu
== NULL
);
227 m_hMenu
= ::LoadMenuIndirect(lpMenuTemplate
);
228 return (m_hMenu
!= NULL
) ? TRUE
: FALSE
;
230 #endif // !_WIN32_WCE
236 BOOL bRet
= ::DestroyMenu(m_hMenu
);
243 BOOL
DeleteMenu(UINT nPosition
, UINT nFlags
)
245 ATLASSERT(::IsMenu(m_hMenu
));
246 return ::DeleteMenu(m_hMenu
, nPosition
, nFlags
);
249 BOOL
TrackPopupMenu(UINT nFlags
, int x
, int y
, HWND hWnd
, LPCRECT lpRect
= NULL
)
251 ATLASSERT(::IsMenu(m_hMenu
));
253 #if (WINVER >= 0x0500)
254 x
= _FixTrackMenuPopupX(x
, y
);
255 #endif // !(WINVER >= 0x0500)
256 return ::TrackPopupMenu(m_hMenu
, nFlags
, x
, y
, 0, hWnd
, lpRect
);
259 return ::TrackPopupMenuEx(m_hMenu
, nFlags
, x
, y
, hWnd
, NULL
);
263 BOOL
TrackPopupMenuEx(UINT uFlags
, int x
, int y
, HWND hWnd
, LPTPMPARAMS lptpm
= NULL
)
265 ATLASSERT(::IsMenu(m_hMenu
));
266 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
267 x
= _FixTrackMenuPopupX(x
, y
);
268 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
269 return ::TrackPopupMenuEx(m_hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
272 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
273 // helper that fixes popup menu X position when it's off-screen
274 static int _FixTrackMenuPopupX(int x
, int y
)
277 HMONITOR hMonitor
= ::MonitorFromPoint(pt
, MONITOR_DEFAULTTONULL
);
280 HMONITOR hMonitorNear
= ::MonitorFromPoint(pt
, MONITOR_DEFAULTTONEAREST
);
281 if(hMonitorNear
!= NULL
)
283 MONITORINFO mi
= { sizeof(MONITORINFO
) };
284 if(::GetMonitorInfo(hMonitorNear
, &mi
) != FALSE
)
286 if(x
< mi
.rcWork
.left
)
288 else if(x
> mi
.rcWork
.right
)
297 BOOL
GetMenuInfo(LPMENUINFO lpMenuInfo
) const
299 ATLASSERT(::IsMenu(m_hMenu
));
300 return ::GetMenuInfo(m_hMenu
, lpMenuInfo
);
303 BOOL
SetMenuInfo(LPCMENUINFO lpMenuInfo
)
305 ATLASSERT(::IsMenu(m_hMenu
));
306 return ::SetMenuInfo(m_hMenu
, lpMenuInfo
);
308 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
310 // Menu Item Operations
311 BOOL
AppendMenu(UINT nFlags
, UINT_PTR nIDNewItem
= 0, LPCTSTR lpszNewItem
= NULL
)
313 ATLASSERT(::IsMenu(m_hMenu
));
314 return ::AppendMenu(m_hMenu
, nFlags
, nIDNewItem
, lpszNewItem
);
317 BOOL
AppendMenu(UINT nFlags
, HMENU hSubMenu
, LPCTSTR lpszNewItem
)
319 ATLASSERT(::IsMenu(m_hMenu
));
320 ATLASSERT(::IsMenu(hSubMenu
));
321 return ::AppendMenu(m_hMenu
, nFlags
| MF_POPUP
, (UINT_PTR
)hSubMenu
, lpszNewItem
);
325 BOOL
AppendMenu(UINT nFlags
, UINT_PTR nIDNewItem
, HBITMAP hBmp
)
327 ATLASSERT(::IsMenu(m_hMenu
));
328 return ::AppendMenu(m_hMenu
, nFlags
| MF_BITMAP
, nIDNewItem
, (LPCTSTR
)hBmp
);
331 BOOL
AppendMenu(UINT nFlags
, HMENU hSubMenu
, HBITMAP hBmp
)
333 ATLASSERT(::IsMenu(m_hMenu
));
334 ATLASSERT(::IsMenu(hSubMenu
));
335 return ::AppendMenu(m_hMenu
, nFlags
| (MF_BITMAP
| MF_POPUP
), (UINT_PTR
)hSubMenu
, (LPCTSTR
)hBmp
);
337 #endif // !_WIN32_WCE
339 UINT
CheckMenuItem(UINT nIDCheckItem
, UINT nCheck
)
341 ATLASSERT(::IsMenu(m_hMenu
));
342 return (UINT
)::CheckMenuItem(m_hMenu
, nIDCheckItem
, nCheck
);
345 UINT
EnableMenuItem(UINT nIDEnableItem
, UINT nEnable
)
347 ATLASSERT(::IsMenu(m_hMenu
));
348 return ::EnableMenuItem(m_hMenu
, nIDEnableItem
, nEnable
);
352 BOOL
HiliteMenuItem(HWND hWnd
, UINT uIDHiliteItem
, UINT uHilite
)
354 ATLASSERT(::IsMenu(m_hMenu
));
355 return ::HiliteMenuItem(hWnd
, m_hMenu
, uIDHiliteItem
, uHilite
);
358 int GetMenuItemCount() const
360 ATLASSERT(::IsMenu(m_hMenu
));
361 return ::GetMenuItemCount(m_hMenu
);
364 UINT
GetMenuItemID(int nPos
) const
366 ATLASSERT(::IsMenu(m_hMenu
));
367 return ::GetMenuItemID(m_hMenu
, nPos
);
370 UINT
GetMenuState(UINT nID
, UINT nFlags
) const
372 ATLASSERT(::IsMenu(m_hMenu
));
373 return ::GetMenuState(m_hMenu
, nID
, nFlags
);
376 int GetMenuString(UINT nIDItem
, LPTSTR lpString
, int nMaxCount
, UINT nFlags
) const
378 ATLASSERT(::IsMenu(m_hMenu
));
379 return ::GetMenuString(m_hMenu
, nIDItem
, lpString
, nMaxCount
, nFlags
);
382 int GetMenuStringLen(UINT nIDItem
, UINT nFlags
) const
384 ATLASSERT(::IsMenu(m_hMenu
));
385 return ::GetMenuString(m_hMenu
, nIDItem
, NULL
, 0, nFlags
);
389 BOOL
GetMenuString(UINT nIDItem
, BSTR
& bstrText
, UINT nFlags
) const
392 ATLASSERT(::IsMenu(m_hMenu
));
393 ATLASSERT(bstrText
== NULL
);
395 int nLen
= GetMenuStringLen(nIDItem
, nFlags
);
398 bstrText
= ::SysAllocString(OLESTR(""));
399 return (bstrText
!= NULL
) ? TRUE
: FALSE
;
402 nLen
++; // increment to include terminating NULL char
403 CTempBuffer
<TCHAR
, _WTL_STACK_ALLOC_THRESHOLD
> buff
;
404 LPTSTR lpszText
= buff
.Allocate(nLen
);
408 if(!GetMenuString(nIDItem
, lpszText
, nLen
, nFlags
))
411 bstrText
= ::SysAllocString(T2OLE(lpszText
));
412 return (bstrText
!= NULL
) ? TRUE
: FALSE
;
414 #endif // !_ATL_NO_COM
416 #elif (_ATL_VER >= 0x0800)
417 int GetMenuItemCount() const
419 ATLASSERT(::IsMenu(m_hMenu
));
420 return ATL::GetMenuItemCount(m_hMenu
);
423 UINT
GetMenuItemID(int nPos
) const
425 ATLASSERT(::IsMenu(m_hMenu
));
426 return ATL::GetMenuItemID(m_hMenu
, nPos
);
429 UINT
GetMenuState(UINT nID
, UINT nFlags
) const
431 ATLASSERT(::IsMenu(m_hMenu
));
432 return ATL::GetMenuState(m_hMenu
, nID
, nFlags
);
435 int GetMenuString(UINT nIDItem
, LPTSTR lpString
, int nMaxCount
, UINT nFlags
) const
437 ATLASSERT(::IsMenu(m_hMenu
));
438 return ATL::GetMenuString(m_hMenu
, nIDItem
, lpString
, nMaxCount
, nFlags
);
441 int GetMenuStringLen(UINT nIDItem
, UINT nFlags
) const
443 ATLASSERT(::IsMenu(m_hMenu
));
444 return ATL::GetMenuString(m_hMenu
, nIDItem
, NULL
, 0, nFlags
);
446 #endif // (_ATL_VER >= 0x0800)
448 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
449 int GetMenuString(UINT nIDItem
, _CSTRING_NS::CString
& strText
, UINT nFlags
) const
451 ATLASSERT(::IsMenu(m_hMenu
));
453 int nLen
= GetMenuStringLen(nIDItem
, nFlags
);
457 nLen
++; // increment to include terminating NULL char
458 LPTSTR lpstr
= strText
.GetBufferSetLength(nLen
);
461 int nRet
= GetMenuString(nIDItem
, lpstr
, nLen
, nFlags
);
462 strText
.ReleaseBuffer();
465 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
467 CMenuHandle
GetSubMenu(int nPos
) const
469 ATLASSERT(::IsMenu(m_hMenu
));
470 return CMenuHandle(::GetSubMenu(m_hMenu
, nPos
));
473 BOOL
InsertMenu(UINT nPosition
, UINT nFlags
, UINT_PTR nIDNewItem
= 0, LPCTSTR lpszNewItem
= NULL
)
475 ATLASSERT(::IsMenu(m_hMenu
));
476 return ::InsertMenu(m_hMenu
, nPosition
, nFlags
, nIDNewItem
, lpszNewItem
);
479 BOOL
InsertMenu(UINT nPosition
, UINT nFlags
, HMENU hSubMenu
, LPCTSTR lpszNewItem
)
481 ATLASSERT(::IsMenu(m_hMenu
));
482 ATLASSERT(::IsMenu(hSubMenu
));
483 return ::InsertMenu(m_hMenu
, nPosition
, nFlags
| MF_POPUP
, (UINT_PTR
)hSubMenu
, lpszNewItem
);
487 BOOL
InsertMenu(UINT nPosition
, UINT nFlags
, UINT_PTR nIDNewItem
, HBITMAP hBmp
)
489 ATLASSERT(::IsMenu(m_hMenu
));
490 return ::InsertMenu(m_hMenu
, nPosition
, nFlags
| MF_BITMAP
, nIDNewItem
, (LPCTSTR
)hBmp
);
493 BOOL
InsertMenu(UINT nPosition
, UINT nFlags
, HMENU hSubMenu
, HBITMAP hBmp
)
495 ATLASSERT(::IsMenu(m_hMenu
));
496 ATLASSERT(::IsMenu(hSubMenu
));
497 return ::InsertMenu(m_hMenu
, nPosition
, nFlags
| (MF_BITMAP
| MF_POPUP
), (UINT_PTR
)hSubMenu
, (LPCTSTR
)hBmp
);
500 BOOL
ModifyMenu(UINT nPosition
, UINT nFlags
, UINT_PTR nIDNewItem
= 0, LPCTSTR lpszNewItem
= NULL
)
502 ATLASSERT(::IsMenu(m_hMenu
));
503 return ::ModifyMenu(m_hMenu
, nPosition
, nFlags
, nIDNewItem
, lpszNewItem
);
506 BOOL
ModifyMenu(UINT nPosition
, UINT nFlags
, HMENU hSubMenu
, LPCTSTR lpszNewItem
)
508 ATLASSERT(::IsMenu(m_hMenu
));
509 ATLASSERT(::IsMenu(hSubMenu
));
510 return ::ModifyMenu(m_hMenu
, nPosition
, nFlags
| MF_POPUP
, (UINT_PTR
)hSubMenu
, lpszNewItem
);
513 BOOL
ModifyMenu(UINT nPosition
, UINT nFlags
, UINT_PTR nIDNewItem
, HBITMAP hBmp
)
515 ATLASSERT(::IsMenu(m_hMenu
));
516 return ::ModifyMenu(m_hMenu
, nPosition
, nFlags
| MF_BITMAP
, nIDNewItem
, (LPCTSTR
)hBmp
);
519 BOOL
ModifyMenu(UINT nPosition
, UINT nFlags
, HMENU hSubMenu
, HBITMAP hBmp
)
521 ATLASSERT(::IsMenu(m_hMenu
));
522 ATLASSERT(::IsMenu(hSubMenu
));
523 return ::ModifyMenu(m_hMenu
, nPosition
, nFlags
| (MF_BITMAP
| MF_POPUP
), (UINT_PTR
)hSubMenu
, (LPCTSTR
)hBmp
);
525 #endif // !_WIN32_WCE
527 BOOL
RemoveMenu(UINT nPosition
, UINT nFlags
)
529 ATLASSERT(::IsMenu(m_hMenu
));
530 return ::RemoveMenu(m_hMenu
, nPosition
, nFlags
);
534 BOOL
SetMenuItemBitmaps(UINT nPosition
, UINT nFlags
, HBITMAP hBmpUnchecked
, HBITMAP hBmpChecked
)
536 ATLASSERT(::IsMenu(m_hMenu
));
537 return ::SetMenuItemBitmaps(m_hMenu
, nPosition
, nFlags
, hBmpUnchecked
, hBmpChecked
);
539 #endif // !_WIN32_WCE
541 BOOL
CheckMenuRadioItem(UINT nIDFirst
, UINT nIDLast
, UINT nIDItem
, UINT nFlags
)
543 ATLASSERT(::IsMenu(m_hMenu
));
544 return ::CheckMenuRadioItem(m_hMenu
, nIDFirst
, nIDLast
, nIDItem
, nFlags
);
547 BOOL
GetMenuItemInfo(UINT uItem
, BOOL bByPosition
, LPMENUITEMINFO lpmii
) const
549 ATLASSERT(::IsMenu(m_hMenu
));
550 return (BOOL
)::GetMenuItemInfo(m_hMenu
, uItem
, bByPosition
, lpmii
);
553 BOOL
SetMenuItemInfo(UINT uItem
, BOOL bByPosition
, LPMENUITEMINFO lpmii
)
555 ATLASSERT(::IsMenu(m_hMenu
));
556 return (BOOL
)::SetMenuItemInfo(m_hMenu
, uItem
, bByPosition
, lpmii
);
560 BOOL
InsertMenuItem(UINT uItem
, BOOL bByPosition
, LPMENUITEMINFO lpmii
)
562 ATLASSERT(::IsMenu(m_hMenu
));
563 return (BOOL
)::InsertMenuItem(m_hMenu
, uItem
, bByPosition
, lpmii
);
566 UINT
GetMenuDefaultItem(BOOL bByPosition
= FALSE
, UINT uFlags
= 0U) const
568 ATLASSERT(::IsMenu(m_hMenu
));
569 return ::GetMenuDefaultItem(m_hMenu
, (UINT
)bByPosition
, uFlags
);
572 BOOL
SetMenuDefaultItem(UINT uItem
= (UINT
)-1, BOOL bByPosition
= FALSE
)
574 ATLASSERT(::IsMenu(m_hMenu
));
575 return ::SetMenuDefaultItem(m_hMenu
, uItem
, (UINT
)bByPosition
);
578 BOOL
GetMenuItemRect(HWND hWnd
, UINT uItem
, LPRECT lprcItem
) const
580 ATLASSERT(::IsMenu(m_hMenu
));
581 return ::GetMenuItemRect(hWnd
, m_hMenu
, uItem
, lprcItem
);
584 int MenuItemFromPoint(HWND hWnd
, POINT point
) const
586 ATLASSERT(::IsMenu(m_hMenu
));
587 return ::MenuItemFromPoint(hWnd
, m_hMenu
, point
);
590 // Context Help Functions
591 BOOL
SetMenuContextHelpId(DWORD dwContextHelpId
)
593 ATLASSERT(::IsMenu(m_hMenu
));
594 return ::SetMenuContextHelpId(m_hMenu
, dwContextHelpId
);
597 DWORD
GetMenuContextHelpId() const
599 ATLASSERT(::IsMenu(m_hMenu
));
600 return ::GetMenuContextHelpId(m_hMenu
);
602 #endif // !_WIN32_WCE
606 ///////////////////////////////////////////////////////////////////////////////
609 template <bool t_bManaged
>
615 // Constructor/destructor/operators
616 CAcceleratorT(HACCEL hAccel
= NULL
) : m_hAccel(hAccel
)
621 if(t_bManaged
&& m_hAccel
!= NULL
)
622 ::DestroyAcceleratorTable(m_hAccel
);
625 CAcceleratorT
<t_bManaged
>& operator =(HACCEL hAccel
)
631 void Attach(HACCEL hAccel
)
633 if(t_bManaged
&& m_hAccel
!= NULL
)
634 ::DestroyAcceleratorTable(m_hAccel
);
640 HACCEL hAccel
= m_hAccel
;
645 operator HACCEL() const { return m_hAccel
; }
647 bool IsNull() const { return m_hAccel
== NULL
; }
649 // Create/destroy methods
650 HACCEL
LoadAccelerators(ATL::_U_STRINGorID accel
)
652 ATLASSERT(m_hAccel
== NULL
);
653 m_hAccel
= ::LoadAccelerators(ModuleHelper::GetResourceInstance(), accel
.m_lpstr
);
657 HACCEL
CreateAcceleratorTable(LPACCEL pAccel
, int cEntries
)
659 ATLASSERT(m_hAccel
== NULL
);
660 ATLASSERT(pAccel
!= NULL
);
661 m_hAccel
= ::CreateAcceleratorTable(pAccel
, cEntries
);
669 ::DestroyAcceleratorTable(m_hAccel
);
676 int CopyAcceleratorTable(LPACCEL lpAccelDst
, int cEntries
)
678 ATLASSERT(m_hAccel
!= NULL
);
679 ATLASSERT(lpAccelDst
!= NULL
);
680 return ::CopyAcceleratorTable(m_hAccel
, lpAccelDst
, cEntries
);
683 int GetEntriesCount() const
685 ATLASSERT(m_hAccel
!= NULL
);
686 return ::CopyAcceleratorTable(m_hAccel
, NULL
, 0);
688 #endif // !_WIN32_WCE
690 BOOL
TranslateAccelerator(HWND hWnd
, LPMSG pMsg
)
692 ATLASSERT(m_hAccel
!= NULL
);
693 ATLASSERT(::IsWindow(hWnd
));
694 ATLASSERT(pMsg
!= NULL
);
695 return ::TranslateAccelerator(hWnd
, m_hAccel
, pMsg
);
699 typedef CAcceleratorT
<false> CAcceleratorHandle
;
700 typedef CAcceleratorT
<true> CAccelerator
;
703 ///////////////////////////////////////////////////////////////////////////////
706 template <bool t_bManaged
>
712 // Constructor/destructor/operators
713 CIconT(HICON hIcon
= NULL
) : m_hIcon(hIcon
)
718 if(t_bManaged
&& m_hIcon
!= NULL
)
719 ::DestroyIcon(m_hIcon
);
722 CIconT
<t_bManaged
>& operator =(HICON hIcon
)
728 void Attach(HICON hIcon
)
730 if(t_bManaged
&& m_hIcon
!= NULL
)
731 ::DestroyIcon(m_hIcon
);
737 HICON hIcon
= m_hIcon
;
742 operator HICON() const { return m_hIcon
; }
744 bool IsNull() const { return m_hIcon
== NULL
; }
746 // Create/destroy methods
747 HICON
LoadIcon(ATL::_U_STRINGorID icon
)
749 ATLASSERT(m_hIcon
== NULL
);
750 m_hIcon
= ::LoadIcon(ModuleHelper::GetResourceInstance(), icon
.m_lpstr
);
754 HICON
LoadIcon(ATL::_U_STRINGorID icon
, int cxDesired
, int cyDesired
, UINT fuLoad
= 0)
756 ATLASSERT(m_hIcon
== NULL
);
757 m_hIcon
= (HICON
) ::LoadImage(ModuleHelper::GetResourceInstance(), icon
.m_lpstr
, IMAGE_ICON
, cxDesired
, cyDesired
, fuLoad
);
762 HICON
LoadOEMIcon(LPCTSTR lpstrIconName
)
764 ATLASSERT(m_hIcon
== NULL
);
765 ATLASSERT(IsOEMIcon(lpstrIconName
));
766 m_hIcon
= ::LoadIcon(NULL
, lpstrIconName
);
770 HICON
CreateIcon(int nWidth
, int nHeight
, BYTE cPlanes
, BYTE cBitsPixel
, CONST BYTE
* lpbANDbits
, CONST BYTE
*lpbXORbits
)
772 ATLASSERT(m_hIcon
== NULL
);
773 ATLASSERT(lpbANDbits
!= NULL
);
774 ATLASSERT(lpbXORbits
!= NULL
);
775 m_hIcon
= ::CreateIcon(ModuleHelper::GetResourceInstance(), nWidth
, nHeight
, cPlanes
, cBitsPixel
, lpbANDbits
, lpbXORbits
);
779 HICON
CreateIconFromResource(PBYTE pBits
, DWORD dwResSize
, DWORD dwVersion
= 0x00030000)
781 ATLASSERT(m_hIcon
== NULL
);
782 ATLASSERT(pBits
!= NULL
);
783 m_hIcon
= ::CreateIconFromResource(pBits
, dwResSize
, TRUE
, dwVersion
);
787 HICON
CreateIconFromResourceEx(PBYTE pbBits
, DWORD cbBits
, DWORD dwVersion
= 0x00030000, int cxDesired
= 0, int cyDesired
= 0, UINT uFlags
= LR_DEFAULTCOLOR
)
789 ATLASSERT(m_hIcon
== NULL
);
790 ATLASSERT(pbBits
!= NULL
);
791 ATLASSERT(cbBits
> 0);
792 m_hIcon
= ::CreateIconFromResourceEx(pbBits
, cbBits
, TRUE
, dwVersion
, cxDesired
, cyDesired
, uFlags
);
795 #endif // !_WIN32_WCE
797 HICON
CreateIconIndirect(PICONINFO pIconInfo
)
799 ATLASSERT(m_hIcon
== NULL
);
800 ATLASSERT(pIconInfo
!= NULL
);
801 m_hIcon
= ::CreateIconIndirect(pIconInfo
);
806 HICON
ExtractIcon(LPCTSTR lpszExeFileName
, UINT nIconIndex
)
808 ATLASSERT(m_hIcon
== NULL
);
809 ATLASSERT(lpszExeFileName
!= NULL
);
810 m_hIcon
= ::ExtractIcon(ModuleHelper::GetModuleInstance(), lpszExeFileName
, nIconIndex
);
814 HICON
ExtractAssociatedIcon(HINSTANCE hInst
, LPTSTR lpIconPath
, LPWORD lpiIcon
)
816 ATLASSERT(m_hIcon
== NULL
);
817 ATLASSERT(lpIconPath
!= NULL
);
818 ATLASSERT(lpiIcon
!= NULL
);
819 m_hIcon
= ::ExtractAssociatedIcon(hInst
, lpIconPath
, lpiIcon
);
822 #endif // !_WIN32_WCE
826 ATLASSERT(m_hIcon
!= NULL
);
827 BOOL bRet
= ::DestroyIcon(m_hIcon
);
837 ATLASSERT(m_hIcon
!= NULL
);
838 return ::CopyIcon(m_hIcon
);
841 HICON
DuplicateIcon()
843 ATLASSERT(m_hIcon
!= NULL
);
844 return ::DuplicateIcon(NULL
, m_hIcon
);
846 #endif // !_WIN32_WCE
848 BOOL
DrawIcon(HDC hDC
, int x
, int y
)
850 ATLASSERT(m_hIcon
!= NULL
);
852 return ::DrawIcon(hDC
, x
, y
, m_hIcon
);
854 return ::DrawIconEx(hDC
, x
, y
, m_hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
858 BOOL
DrawIcon(HDC hDC
, POINT pt
)
860 ATLASSERT(m_hIcon
!= NULL
);
862 return ::DrawIcon(hDC
, pt
.x
, pt
.y
, m_hIcon
);
864 return ::DrawIconEx(hDC
, pt
.x
, pt
.y
, m_hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
868 BOOL
DrawIconEx(HDC hDC
, int x
, int y
, int cxWidth
, int cyWidth
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
870 ATLASSERT(m_hIcon
!= NULL
);
871 return ::DrawIconEx(hDC
, x
, y
, m_hIcon
, cxWidth
, cyWidth
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
874 BOOL
DrawIconEx(HDC hDC
, POINT pt
, SIZE size
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
876 ATLASSERT(m_hIcon
!= NULL
);
877 return ::DrawIconEx(hDC
, pt
.x
, pt
.y
, m_hIcon
, size
.cx
, size
.cy
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
881 BOOL
GetIconInfo(PICONINFO pIconInfo
) const
883 ATLASSERT(m_hIcon
!= NULL
);
884 ATLASSERT(pIconInfo
!= NULL
);
885 return ::GetIconInfo(m_hIcon
, pIconInfo
);
888 #if (_WIN32_WINNT >= 0x0600)
889 BOOL
GetIconInfoEx(PICONINFOEX pIconInfo
) const
891 ATLASSERT(m_hIcon
!= NULL
);
892 ATLASSERT(pIconInfo
!= NULL
);
893 return ::GetIconInfoEx(m_hIcon
, pIconInfo
);
895 #endif // (_WIN32_WINNT >= 0x0600)
897 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
898 HRESULT
LoadIconMetric(ATL::_U_STRINGorID icon
, int lims
)
900 ATLASSERT(m_hIcon
== NULL
);
902 return ::LoadIconMetric(ModuleHelper::GetResourceInstance(), T2CW(icon
.m_lpstr
), lims
, &m_hIcon
);
905 HRESULT
LoadIconWithScaleDown(ATL::_U_STRINGorID icon
, int cx
, int cy
)
907 ATLASSERT(m_hIcon
== NULL
);
909 return ::LoadIconWithScaleDown(ModuleHelper::GetResourceInstance(), T2CW(icon
.m_lpstr
), cx
, cy
, &m_hIcon
);
912 HRESULT
LoadOEMIconMetric(LPCTSTR lpstrIconName
, int lims
)
914 ATLASSERT(m_hIcon
== NULL
);
915 ATLASSERT(IsOEMIcon(lpstrIconName
));
916 return ::LoadIconMetric(NULL
, (LPCWSTR
)lpstrIconName
, lims
, &m_hIcon
);
919 HRESULT
LoadOEMIconWithScaleDown(LPCTSTR lpstrIconName
, int cx
, int cy
)
921 ATLASSERT(m_hIcon
== NULL
);
922 ATLASSERT(IsOEMIcon(lpstrIconName
));
924 return ::LoadIconWithScaleDown(NULL
, (LPCWSTR
)lpstrIconName
, cx
, cy
, &m_hIcon
);
926 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
927 #endif // !_WIN32_WCE
931 static bool IsOEMIcon(LPCTSTR lpstrIconName
)
933 #if (WINVER >= 0x0600)
934 return (lpstrIconName
== IDI_APPLICATION
|| lpstrIconName
== IDI_ASTERISK
|| lpstrIconName
== IDI_EXCLAMATION
||
935 lpstrIconName
== IDI_HAND
|| lpstrIconName
== IDI_QUESTION
|| lpstrIconName
== IDI_WINLOGO
||
936 lpstrIconName
== IDI_SHIELD
);
937 #else // !(WINVER >= 0x0600)
938 return (lpstrIconName
== IDI_APPLICATION
|| lpstrIconName
== IDI_ASTERISK
|| lpstrIconName
== IDI_EXCLAMATION
||
939 lpstrIconName
== IDI_HAND
|| lpstrIconName
== IDI_QUESTION
|| lpstrIconName
== IDI_WINLOGO
);
940 #endif // !(WINVER >= 0x0600)
942 #endif // !_WIN32_WCE
945 typedef CIconT
<false> CIconHandle
;
946 typedef CIconT
<true> CIcon
;
949 ///////////////////////////////////////////////////////////////////////////////
952 // protect template member from a winuser.h macro
957 template <bool t_bManaged
>
963 // Constructor/destructor/operators
964 CCursorT(HCURSOR hCursor
= NULL
) : m_hCursor(hCursor
)
969 if(t_bManaged
&& m_hCursor
!= NULL
)
973 CCursorT
<t_bManaged
>& operator =(HCURSOR hCursor
)
979 void Attach(HCURSOR hCursor
)
981 if(t_bManaged
&& m_hCursor
!= NULL
)
988 HCURSOR hCursor
= m_hCursor
;
993 operator HCURSOR() const { return m_hCursor
; }
995 bool IsNull() const { return m_hCursor
== NULL
; }
997 // Create/destroy methods
998 HCURSOR
LoadCursor(ATL::_U_STRINGorID cursor
)
1000 ATLASSERT(m_hCursor
== NULL
);
1001 m_hCursor
= ::LoadCursor(ModuleHelper::GetResourceInstance(), cursor
.m_lpstr
);
1005 HCURSOR
LoadSysCursor(LPCTSTR lpstrCursorName
)
1007 ATLASSERT(m_hCursor
== NULL
);
1008 #if (WINVER >= 0x0500)
1009 ATLASSERT(lpstrCursorName
== IDC_ARROW
|| lpstrCursorName
== IDC_IBEAM
|| lpstrCursorName
== IDC_WAIT
||
1010 lpstrCursorName
== IDC_CROSS
|| lpstrCursorName
== IDC_UPARROW
|| lpstrCursorName
== IDC_SIZE
||
1011 lpstrCursorName
== IDC_ICON
|| lpstrCursorName
== IDC_SIZENWSE
|| lpstrCursorName
== IDC_SIZENESW
||
1012 lpstrCursorName
== IDC_SIZEWE
|| lpstrCursorName
== IDC_SIZENS
|| lpstrCursorName
== IDC_SIZEALL
||
1013 lpstrCursorName
== IDC_NO
|| lpstrCursorName
== IDC_APPSTARTING
|| lpstrCursorName
== IDC_HELP
||
1014 lpstrCursorName
== IDC_HAND
);
1015 #else // !(WINVER >= 0x0500)
1016 ATLASSERT(lpstrCursorName
== IDC_ARROW
|| lpstrCursorName
== IDC_IBEAM
|| lpstrCursorName
== IDC_WAIT
||
1017 lpstrCursorName
== IDC_CROSS
|| lpstrCursorName
== IDC_UPARROW
|| lpstrCursorName
== IDC_SIZE
||
1018 lpstrCursorName
== IDC_ICON
|| lpstrCursorName
== IDC_SIZENWSE
|| lpstrCursorName
== IDC_SIZENESW
||
1019 lpstrCursorName
== IDC_SIZEWE
|| lpstrCursorName
== IDC_SIZENS
|| lpstrCursorName
== IDC_SIZEALL
||
1020 lpstrCursorName
== IDC_NO
|| lpstrCursorName
== IDC_APPSTARTING
|| lpstrCursorName
== IDC_HELP
);
1021 #endif // !(WINVER >= 0x0500)
1022 m_hCursor
= ::LoadCursor(NULL
, lpstrCursorName
);
1027 HCURSOR
LoadOEMCursor(LPCTSTR lpstrCursorName
)
1029 return LoadSysCursor(lpstrCursorName
);
1032 HCURSOR
LoadCursor(ATL::_U_STRINGorID cursor
, int cxDesired
, int cyDesired
, UINT fuLoad
= 0)
1034 ATLASSERT(m_hCursor
== NULL
);
1035 m_hCursor
= (HCURSOR
) ::LoadImage(ModuleHelper::GetResourceInstance(), cursor
.m_lpstr
, IMAGE_CURSOR
, cxDesired
, cyDesired
, fuLoad
);
1040 HCURSOR
LoadCursorFromFile(LPCTSTR pstrFilename
)
1042 ATLASSERT(m_hCursor
== NULL
);
1043 ATLASSERT(pstrFilename
!= NULL
);
1044 m_hCursor
= ::LoadCursorFromFile(pstrFilename
);
1047 #endif // !_WIN32_WCE
1049 #if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
1050 HCURSOR
CreateCursor(int xHotSpot
, int yHotSpot
, int nWidth
, int nHeight
, CONST VOID
*pvANDPlane
, CONST VOID
*pvXORPlane
)
1052 ATLASSERT(m_hCursor
== NULL
);
1053 m_hCursor
= ::CreateCursor(ModuleHelper::GetResourceInstance(), xHotSpot
, yHotSpot
, nWidth
, nHeight
, pvANDPlane
, pvXORPlane
);
1056 #endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
1059 HCURSOR
CreateCursorFromResource(PBYTE pBits
, DWORD dwResSize
, DWORD dwVersion
= 0x00030000)
1061 ATLASSERT(m_hCursor
== NULL
);
1062 ATLASSERT(pBits
!= NULL
);
1063 m_hCursor
= (HCURSOR
)::CreateIconFromResource(pBits
, dwResSize
, FALSE
, dwVersion
);
1067 HCURSOR
CreateCursorFromResourceEx(PBYTE pbBits
, DWORD cbBits
, DWORD dwVersion
= 0x00030000, int cxDesired
= 0, int cyDesired
= 0, UINT uFlags
= LR_DEFAULTCOLOR
)
1069 ATLASSERT(m_hCursor
== NULL
);
1070 ATLASSERT(pbBits
!= NULL
);
1071 ATLASSERT(cbBits
> 0);
1072 m_hCursor
= (HCURSOR
)::CreateIconFromResourceEx(pbBits
, cbBits
, FALSE
, dwVersion
, cxDesired
, cyDesired
, uFlags
);
1075 #endif // !_WIN32_WCE
1077 BOOL
DestroyCursor()
1079 ATLASSERT(m_hCursor
!= NULL
);
1080 #if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
1081 BOOL bRet
= ::DestroyCursor(m_hCursor
);
1085 #else // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
1086 ATLTRACE2(atlTraceUI
, 0, _T("Warning: This version of Windows CE does not have ::DestroyCursor()\n"));
1088 #endif // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
1093 HCURSOR
CopyCursor()
1095 ATLASSERT(m_hCursor
!= NULL
);
1096 return (HCURSOR
)::CopyIcon((HICON
)m_hCursor
);
1098 #endif // !_WIN32_WCE
1100 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1101 BOOL
GetCursorInfo(LPCURSORINFO pCursorInfo
)
1103 ATLASSERT(m_hCursor
!= NULL
);
1104 ATLASSERT(pCursorInfo
!= NULL
);
1105 return ::GetCursorInfo(pCursorInfo
);
1107 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1110 typedef CCursorT
<false> CCursorHandle
;
1111 typedef CCursorT
<true> CCursor
;
1114 ///////////////////////////////////////////////////////////////////////////////
1115 // CResource - Wraps a generic Windows resource.
1116 // Use it with custom resource types other than the
1117 // standard RT_CURSOR, RT_BITMAP, etc.
1125 // Constructor/destructor
1126 CResource() : m_hGlobal(NULL
), m_hResource(NULL
)
1135 bool Load(ATL::_U_STRINGorID Type
, ATL::_U_STRINGorID ID
)
1137 ATLASSERT(m_hResource
== NULL
);
1138 ATLASSERT(m_hGlobal
== NULL
);
1140 m_hResource
= ::FindResource(ModuleHelper::GetResourceInstance(), ID
.m_lpstr
, Type
.m_lpstr
);
1141 if(m_hResource
== NULL
)
1144 m_hGlobal
= ::LoadResource(ModuleHelper::GetResourceInstance(), m_hResource
);
1145 if(m_hGlobal
== NULL
)
1155 bool LoadEx(ATL::_U_STRINGorID Type
, ATL::_U_STRINGorID ID
, WORD wLanguage
)
1157 ATLASSERT(m_hResource
== NULL
);
1158 ATLASSERT(m_hGlobal
== NULL
);
1160 m_hResource
= ::FindResourceEx(ModuleHelper::GetResourceInstance(), ID
.m_lpstr
, Type
.m_lpstr
, wLanguage
);
1161 if(m_hResource
== NULL
)
1164 m_hGlobal
= ::LoadResource(ModuleHelper::GetResourceInstance(), m_hResource
);
1165 if(m_hGlobal
== NULL
)
1173 #endif // !_WIN32_WCE
1176 DWORD
GetSize() const
1178 ATLASSERT(m_hResource
!= NULL
);
1179 return ::SizeofResource(ModuleHelper::GetResourceInstance(), m_hResource
);
1184 ATLASSERT(m_hResource
!= NULL
);
1185 ATLASSERT(m_hGlobal
!= NULL
);
1186 LPVOID pVoid
= ::LockResource(m_hGlobal
);
1187 ATLASSERT(pVoid
!= NULL
);
1193 if(m_hGlobal
!= NULL
)
1195 FreeResource(m_hGlobal
);
1203 ///////////////////////////////////////////////////////////////////////////////
1204 // Toolbar resource descriptor
1206 struct _AtlToolBarData
1214 { return (WORD
*)(this+1); }
1218 ///////////////////////////////////////////////////////////////////////////////
1219 // Global functions for loading resources
1221 inline HACCEL
AtlLoadAccelerators(ATL::_U_STRINGorID table
)
1223 return ::LoadAccelerators(ModuleHelper::GetResourceInstance(), table
.m_lpstr
);
1226 inline HMENU
AtlLoadMenu(ATL::_U_STRINGorID menu
)
1228 return ::LoadMenu(ModuleHelper::GetResourceInstance(), menu
.m_lpstr
);
1231 inline HBITMAP
AtlLoadBitmap(ATL::_U_STRINGorID bitmap
)
1233 return ::LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap
.m_lpstr
);
1237 inline HBITMAP
AtlLoadSysBitmap(ATL::_U_STRINGorID bitmap
)
1240 WORD wID
= (WORD
)bitmap
.m_lpstr
;
1241 ATLASSERT(wID
>= 32734 && wID
<= 32767);
1243 return ::LoadBitmap(NULL
, bitmap
.m_lpstr
);
1245 #endif // OEMRESOURCE
1247 inline HCURSOR
AtlLoadCursor(ATL::_U_STRINGorID cursor
)
1249 return ::LoadCursor(ModuleHelper::GetResourceInstance(), cursor
.m_lpstr
);
1252 inline HCURSOR
AtlLoadSysCursor(LPCTSTR lpCursorName
)
1254 #if (WINVER >= 0x0500)
1255 ATLASSERT(lpCursorName
== IDC_ARROW
|| lpCursorName
== IDC_IBEAM
|| lpCursorName
== IDC_WAIT
||
1256 lpCursorName
== IDC_CROSS
|| lpCursorName
== IDC_UPARROW
|| lpCursorName
== IDC_SIZE
||
1257 lpCursorName
== IDC_ICON
|| lpCursorName
== IDC_SIZENWSE
|| lpCursorName
== IDC_SIZENESW
||
1258 lpCursorName
== IDC_SIZEWE
|| lpCursorName
== IDC_SIZENS
|| lpCursorName
== IDC_SIZEALL
||
1259 lpCursorName
== IDC_NO
|| lpCursorName
== IDC_APPSTARTING
|| lpCursorName
== IDC_HELP
||
1260 lpCursorName
== IDC_HAND
);
1261 #else // !(WINVER >= 0x0500)
1262 ATLASSERT(lpCursorName
== IDC_ARROW
|| lpCursorName
== IDC_IBEAM
|| lpCursorName
== IDC_WAIT
||
1263 lpCursorName
== IDC_CROSS
|| lpCursorName
== IDC_UPARROW
|| lpCursorName
== IDC_SIZE
||
1264 lpCursorName
== IDC_ICON
|| lpCursorName
== IDC_SIZENWSE
|| lpCursorName
== IDC_SIZENESW
||
1265 lpCursorName
== IDC_SIZEWE
|| lpCursorName
== IDC_SIZENS
|| lpCursorName
== IDC_SIZEALL
||
1266 lpCursorName
== IDC_NO
|| lpCursorName
== IDC_APPSTARTING
|| lpCursorName
== IDC_HELP
);
1267 #endif // !(WINVER >= 0x0500)
1268 return ::LoadCursor(NULL
, lpCursorName
);
1271 inline HICON
AtlLoadIcon(ATL::_U_STRINGorID icon
)
1273 return ::LoadIcon(ModuleHelper::GetResourceInstance(), icon
.m_lpstr
);
1277 inline HICON
AtlLoadSysIcon(LPCTSTR lpIconName
)
1279 #if (WINVER >= 0x0600)
1280 ATLASSERT(lpIconName
== IDI_APPLICATION
|| lpIconName
== IDI_ASTERISK
|| lpIconName
== IDI_EXCLAMATION
||
1281 lpIconName
== IDI_HAND
|| lpIconName
== IDI_QUESTION
|| lpIconName
== IDI_WINLOGO
||
1282 lpIconName
== IDI_SHIELD
);
1283 #else // !(WINVER >= 0x0600)
1284 ATLASSERT(lpIconName
== IDI_APPLICATION
|| lpIconName
== IDI_ASTERISK
|| lpIconName
== IDI_EXCLAMATION
||
1285 lpIconName
== IDI_HAND
|| lpIconName
== IDI_QUESTION
|| lpIconName
== IDI_WINLOGO
);
1286 #endif // !(WINVER >= 0x0600)
1287 return ::LoadIcon(NULL
, lpIconName
);
1289 #endif // !_WIN32_WCE
1291 inline HBITMAP
AtlLoadBitmapImage(ATL::_U_STRINGorID bitmap
, UINT fuLoad
= LR_DEFAULTCOLOR
)
1293 return (HBITMAP
)::LoadImage(ModuleHelper::GetResourceInstance(), bitmap
.m_lpstr
, IMAGE_BITMAP
, 0, 0, fuLoad
);
1296 inline HCURSOR
AtlLoadCursorImage(ATL::_U_STRINGorID cursor
, UINT fuLoad
= LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
, int cxDesired
= 0, int cyDesired
= 0)
1298 return (HCURSOR
)::LoadImage(ModuleHelper::GetResourceInstance(), cursor
.m_lpstr
, IMAGE_CURSOR
, cxDesired
, cyDesired
, fuLoad
);
1301 inline HICON
AtlLoadIconImage(ATL::_U_STRINGorID icon
, UINT fuLoad
= LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
, int cxDesired
= 0, int cyDesired
= 0)
1303 return (HICON
)::LoadImage(ModuleHelper::GetResourceInstance(), icon
.m_lpstr
, IMAGE_ICON
, cxDesired
, cyDesired
, fuLoad
);
1307 inline HBITMAP
AtlLoadSysBitmapImage(WORD wBitmapID
, UINT fuLoad
= LR_DEFAULTCOLOR
)
1309 ATLASSERT(wBitmapID
>= 32734 && wBitmapID
<= 32767);
1310 ATLASSERT((fuLoad
& LR_LOADFROMFILE
) == 0); // this one doesn't load from a file
1311 return (HBITMAP
)::LoadImage(NULL
, MAKEINTRESOURCE(wBitmapID
), IMAGE_BITMAP
, 0, 0, fuLoad
);
1313 #endif // OEMRESOURCE
1315 inline HCURSOR
AtlLoadSysCursorImage(ATL::_U_STRINGorID cursor
, UINT fuLoad
= LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
, int cxDesired
= 0, int cyDesired
= 0)
1318 WORD wID
= (WORD
)cursor
.m_lpstr
;
1319 ATLASSERT((wID
>= 32512 && wID
<= 32516) || (wID
>= 32640 && wID
<= 32648) || (wID
== 32650) || (wID
== 32651));
1320 ATLASSERT((fuLoad
& LR_LOADFROMFILE
) == 0); // this one doesn't load from a file
1322 return (HCURSOR
)::LoadImage(NULL
, cursor
.m_lpstr
, IMAGE_CURSOR
, cxDesired
, cyDesired
, fuLoad
);
1325 inline HICON
AtlLoadSysIconImage(ATL::_U_STRINGorID icon
, UINT fuLoad
= LR_DEFAULTCOLOR
| LR_DEFAULTSIZE
, int cxDesired
= 0, int cyDesired
= 0)
1328 WORD wID
= (WORD
)icon
.m_lpstr
;
1329 ATLASSERT(wID
>= 32512 && wID
<= 32517);
1330 ATLASSERT((fuLoad
& LR_LOADFROMFILE
) == 0); // this one doesn't load from a file
1332 return (HICON
)::LoadImage(NULL
, icon
.m_lpstr
, IMAGE_ICON
, cxDesired
, cyDesired
, fuLoad
);
1335 #if (_ATL_VER < 0x0700)
1336 inline int AtlLoadString(UINT uID
, LPTSTR lpBuffer
, int nBufferMax
)
1338 return ::LoadString(ModuleHelper::GetResourceInstance(), uID
, lpBuffer
, nBufferMax
);
1342 using ATL::AtlLoadString
;
1344 #endif // (_ATL_VER < 0x0700)
1346 #ifdef _WIN32_WCE // CE only direct access to the resource
1347 inline LPCTSTR
AtlLoadString(UINT uID
)
1349 LPCTSTR s
= (LPCTSTR
)::LoadString(ModuleHelper::GetResourceInstance(), uID
, NULL
, 0);
1350 #ifdef DEBUG // Check for null-termination
1352 // Note: RC -n <file.rc> compiles null-terminated resource strings
1353 ATLASSERT(s
[*((WORD
*)s
-1) - 1] == L
'\0');
1357 #endif // _WIN32_WCE
1359 inline bool AtlLoadString(UINT uID
, BSTR
& bstrText
)
1362 ATLASSERT(bstrText
== NULL
);
1364 LPTSTR lpstrText
= NULL
;
1366 for(int nLen
= 256; ; nLen
*= 2)
1368 ATLTRY(lpstrText
= new TCHAR
[nLen
]);
1369 if(lpstrText
== NULL
)
1371 nRes
= ::LoadString(ModuleHelper::GetResourceInstance(), uID
, lpstrText
, nLen
);
1374 delete [] lpstrText
;
1378 if(lpstrText
!= NULL
)
1381 bstrText
= ::SysAllocString(T2OLE(lpstrText
));
1382 delete [] lpstrText
;
1385 return (bstrText
!= NULL
) ? true : false;
1390 #endif // __ATLUSER_H__