yum-archive/TaSTT-Whisper
High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model
git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper
8c4603c
master
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 9#ifndef __ATLUSER_H__ 10#define __ATLUSER_H__ 11 12#pragma once 13 14#ifndef __ATLAPP_H__ 15#error atluser.h requires atlapp.h to be included first 16#endif 17 18 19/////////////////////////////////////////////////////////////////////////////// 20// Classes in this file: 21// 22// CMenuItemInfo 23// CMenuT<t_bManaged> 24// CAcceleratorT<t_bManaged> 25// CIconT<t_bManaged> 26// CCursorT<t_bManaged> 27// CResource 28// 29// Global functions: 30// AtlMessageBox() 31// 32// AtlLoadAccelerators() 33// AtlLoadMenu() 34// AtlLoadBitmap() 35// AtlLoadSysBitmap() 36// AtlLoadCursor() 37// AtlLoadSysCursor() 38// AtlLoadIcon() 39// AtlLoadSysIcon() 40// AtlLoadBitmapImage() 41// AtlLoadCursorImage() 42// AtlLoadIconImage() 43// AtlLoadSysBitmapImage() 44// AtlLoadSysCursorImage() 45// AtlLoadSysIconImage() 46// AtlLoadString() 47 48 49namespace WTL 50{ 51 52/////////////////////////////////////////////////////////////////////////////// 53// AtlMessageBox - accepts both memory and resource based strings 54 55inline int AtlMessageBox (HWND hWndOwner ,ATL ::_U_STRINGorID message ,ATL ::_U_STRINGorID title = (LPCTSTR )NULL ,UINT uType = MB_OK |MB_ICONINFORMATION ) 56{ 57ATLASSERT ((hWndOwner == NULL )|| ::IsWindow (hWndOwner )); 58 59LPTSTR lpstrMessage = NULL ; 60if (IS_INTRESOURCE (message .m_lpstr )) 61 { 62for (int nLen = 256 ; ;nLen *=2 ) 63 { 64ATLTRY (lpstrMessage = new TCHAR [nLen ]); 65if (lpstrMessage == NULL ) 66 { 67ATLASSERT (FALSE); 68return 0 ; 69 } 70int nRes = ::LoadString (ModuleHelper ::GetResourceInstance (),LOWORD (message .m_lpstr ),lpstrMessage ,nLen ); 71if (nRes < nLen - 1 ) 72break ; 73delete []lpstrMessage ; 74lpstrMessage = NULL ; 75 } 76 77message .m_lpstr = lpstrMessage ; 78 } 79 80LPTSTR lpstrTitle = NULL ; 81if (IS_INTRESOURCE (title .m_lpstr )&& (LOWORD (title .m_lpstr )!= 0 )) 82 { 83for (int nLen = 256 ; ;nLen *=2 ) 84 { 85ATLTRY (lpstrTitle = new TCHAR [nLen ]); 86if (lpstrTitle == NULL ) 87 { 88ATLASSERT (FALSE); 89return 0 ; 90 } 91int nRes = ::LoadString (ModuleHelper ::GetResourceInstance (),LOWORD (title .m_lpstr ),lpstrTitle ,nLen ); 92if (nRes < nLen - 1 ) 93break ; 94delete []lpstrTitle ; 95lpstrTitle = NULL ; 96 } 97 98title .m_lpstr = lpstrTitle ; 99 } 100 101int nRet = ::MessageBox (hWndOwner ,message .m_lpstr ,title .m_lpstr ,uType ); 102 103delete []lpstrMessage ; 104delete []lpstrTitle ; 105 106return nRet ; 107} 108 109 110/////////////////////////////////////////////////////////////////////////////// 111// CMenu 112 113class CMenuItemInfo :public MENUITEMINFO 114{ 115public : 116CMenuItemInfo () 117 { 118memset (this ,0 ,sizeof (MENUITEMINFO )); 119cbSize = sizeof (MENUITEMINFO ); 120 } 121}; 122 123 124// forward declarations 125template < bool t_bManaged > class CMenuT ; 126typedef CMenuT < false> CMenuHandle ; 127typedef CMenuT < true> CMenu ; 128 129 130template < bool t_bManaged > 131class CMenuT 132{ 133public : 134// Data members 135HMENU m_hMenu ; 136 137// Constructor/destructor/operators 138CMenuT (HMENU hMenu = NULL ) :m_hMenu (hMenu ) 139 { } 140 141 ~CMenuT () 142 { 143if (t_bManaged && (m_hMenu != NULL )) 144DestroyMenu (); 145 } 146 147CMenuT < t_bManaged >& operator = (HMENU hMenu ) 148 { 149Attach (hMenu ); 150return * this ; 151 } 152 153void Attach (HMENU hMenuNew ) 154 { 155ATLASSERT (::IsMenu (hMenuNew )); 156if (t_bManaged && (m_hMenu != NULL )&& (m_hMenu != hMenuNew )) 157 ::DestroyMenu (m_hMenu ); 158m_hMenu = hMenuNew ; 159 } 160 161HMENU Detach () 162 { 163HMENU hMenu = m_hMenu ; 164m_hMenu = NULL ; 165return hMenu ; 166 } 167 168operator HMENU ()const {return m_hMenu ; } 169 170bool IsNull ()const {return (m_hMenu == NULL ); } 171 172BOOL IsMenu ()const 173 { 174return ::IsMenu (m_hMenu ); 175 } 176 177// Create/destroy methods 178BOOL CreateMenu () 179 { 180ATLASSERT (m_hMenu == NULL ); 181m_hMenu = ::CreateMenu (); 182return (m_hMenu != NULL ) ? TRUE : FALSE; 183 } 184 185BOOL CreatePopupMenu () 186 { 187ATLASSERT (m_hMenu == NULL ); 188m_hMenu = ::CreatePopupMenu (); 189return (m_hMenu != NULL ) ? TRUE : FALSE; 190 } 191 192BOOL LoadMenu (ATL ::_U_STRINGorID menu ) 193 { 194ATLASSERT (m_hMenu == NULL ); 195m_hMenu = ::LoadMenu (ModuleHelper ::GetResourceInstance (),menu .m_lpstr ); 196return (m_hMenu != NULL ) ? TRUE : FALSE; 197 } 198 199BOOL LoadMenuIndirect (const void * lpMenuTemplate ) 200 { 201ATLASSERT (m_hMenu == NULL ); 202m_hMenu = ::LoadMenuIndirect (lpMenuTemplate ); 203return (m_hMenu != NULL ) ? TRUE : FALSE; 204 } 205 206BOOL DestroyMenu () 207 { 208if (m_hMenu == NULL ) 209return FALSE; 210BOOL bRet = ::DestroyMenu (m_hMenu ); 211if (bRet ) 212m_hMenu = NULL ; 213return bRet ; 214 } 215 216// Menu Operations 217BOOL DeleteMenu (UINT nPosition ,UINT nFlags ) 218 { 219ATLASSERT (::IsMenu (m_hMenu )); 220return ::DeleteMenu (m_hMenu ,nPosition ,nFlags ); 221 } 222 223BOOL TrackPopupMenu (UINT nFlags ,int x ,int y ,HWND hWnd ,LPCRECT lpRect = NULL ) 224 { 225ATLASSERT (::IsMenu (m_hMenu )); 226x = _FixTrackMenuPopupX (x ,y ); 227return ::TrackPopupMenu (m_hMenu ,nFlags ,x ,y ,0 ,hWnd ,lpRect ); 228 } 229 230BOOL TrackPopupMenuEx (UINT uFlags ,int x ,int y ,HWND hWnd ,LPTPMPARAMS lptpm = NULL ) 231 { 232ATLASSERT (::IsMenu (m_hMenu )); 233x = _FixTrackMenuPopupX (x ,y ); 234return ::TrackPopupMenuEx (m_hMenu ,uFlags ,x ,y ,hWnd ,lptpm ); 235 } 236 237// helper that fixes popup menu X position when it's off-screen 238static int _FixTrackMenuPopupX (int x ,int y ) 239 { 240POINT pt = {x ,y }; 241HMONITOR hMonitor = ::MonitorFromPoint (pt ,MONITOR_DEFAULTTONULL ); 242if (hMonitor == NULL ) 243 { 244HMONITOR hMonitorNear = ::MonitorFromPoint (pt ,MONITOR_DEFAULTTONEAREST ); 245if (hMonitorNear != NULL ) 246 { 247MONITORINFO mi = {sizeof (MONITORINFO ) }; 248if (::GetMonitorInfo (hMonitorNear ,& mi )!= FALSE) 249 { 250if (x < mi .rcWork .left ) 251x = mi .rcWork .left ; 252else if (x > mi .rcWork .right ) 253x = mi .rcWork .right ; 254 } 255 } 256 } 257 258return x ; 259 } 260 261BOOL GetMenuInfo (LPMENUINFO lpMenuInfo )const 262 { 263ATLASSERT (::IsMenu (m_hMenu )); 264return ::GetMenuInfo (m_hMenu ,lpMenuInfo ); 265 } 266 267BOOL SetMenuInfo (LPCMENUINFO lpMenuInfo ) 268 { 269ATLASSERT (::IsMenu (m_hMenu )); 270return ::SetMenuInfo (m_hMenu ,lpMenuInfo ); 271 } 272 273// Menu Item Operations 274BOOL AppendMenu (UINT nFlags ,UINT_PTR nIDNewItem = 0 ,LPCTSTR lpszNewItem = NULL ) 275 { 276ATLASSERT (::IsMenu (m_hMenu )); 277return ::AppendMenu (m_hMenu ,nFlags ,nIDNewItem ,lpszNewItem ); 278 } 279 280BOOL AppendMenu (UINT nFlags ,HMENU hSubMenu ,LPCTSTR lpszNewItem ) 281 { 282ATLASSERT (::IsMenu (m_hMenu )); 283ATLASSERT (::IsMenu (hSubMenu )); 284return ::AppendMenu (m_hMenu ,nFlags |MF_POPUP , (UINT_PTR )hSubMenu ,lpszNewItem ); 285 } 286 287BOOL AppendMenu (UINT nFlags ,UINT_PTR nIDNewItem ,HBITMAP hBmp ) 288 { 289ATLASSERT (::IsMenu (m_hMenu )); 290return ::AppendMenu (m_hMenu ,nFlags |MF_BITMAP ,nIDNewItem , (LPCTSTR )hBmp ); 291 } 292 293BOOL AppendMenu (UINT nFlags ,HMENU hSubMenu ,HBITMAP hBmp ) 294 { 295ATLASSERT (::IsMenu (m_hMenu )); 296ATLASSERT (::IsMenu (hSubMenu )); 297return ::AppendMenu (m_hMenu ,nFlags | (MF_BITMAP |MF_POPUP ), (UINT_PTR )hSubMenu , (LPCTSTR )hBmp ); 298 } 299 300UINT CheckMenuItem (UINT nIDCheckItem ,UINT nCheck ) 301 { 302ATLASSERT (::IsMenu (m_hMenu )); 303return (UINT )::CheckMenuItem (m_hMenu ,nIDCheckItem ,nCheck ); 304 } 305 306UINT EnableMenuItem (UINT nIDEnableItem ,UINT nEnable ) 307 { 308ATLASSERT (::IsMenu (m_hMenu )); 309return ::EnableMenuItem (m_hMenu ,nIDEnableItem ,nEnable ); 310 } 311 312BOOL HiliteMenuItem (HWND hWnd ,UINT uIDHiliteItem ,UINT uHilite ) 313 { 314ATLASSERT (::IsMenu (m_hMenu )); 315return ::HiliteMenuItem (hWnd ,m_hMenu ,uIDHiliteItem ,uHilite ); 316 } 317 318int GetMenuItemCount ()const 319 { 320ATLASSERT (::IsMenu (m_hMenu )); 321return :: GetMenuItemCount ( m_hMenu ); 322} 323 324UINT GetMenuItemID ( int nPos) const 325{ 326ATLASSERT (:: IsMenu ( m_hMenu )); 327return :: GetMenuItemID (m_hMenu, nPos); 328} 329 330UINT GetMenuState ( UINT nID, UINT nFlags) const 331{ 332ATLASSERT (:: IsMenu ( m_hMenu )); 333return :: GetMenuState (m_hMenu, nID, nFlags); 334} 335 336int GetMenuString ( UINT nIDItem, LPTSTR lpString, int nMaxCount, UINT nFlags) const 337{ 338ATLASSERT (:: IsMenu ( m_hMenu )); 339return :: GetMenuString (m_hMenu, nIDItem, lpString, nMaxCount, nFlags); 340} 341 342int GetMenuStringLen ( UINT nIDItem, UINT nFlags) const 343{ 344ATLASSERT (:: IsMenu ( m_hMenu )); 345return :: GetMenuString (m_hMenu, nIDItem, NULL , 0 , nFlags); 346} 347 348BOOL GetMenuString ( UINT nIDItem, BSTR & bstrText, UINT nFlags) const 349{ 350USES_CONVERSION ; 351ATLASSERT (:: IsMenu ( m_hMenu )); 352ATLASSERT (bstrText == NULL ); 353 354int nLen = GetMenuStringLen (nIDItem, nFlags); 355if (nLen == 0 ) 356{ 357bstrText = :: SysAllocString ( OLESTR ( "" )); 358return (bstrText != NULL ) ? TRUE : FALSE; 359} 360 361nLen ++ ; // increment to include terminating NULL char 362ATL ::CTempBuffer < TCHAR , _WTL_STACK_ALLOC_THRESHOLD > buff; 363LPTSTR lpszText = buff. Allocate (nLen); 364if (lpszText == NULL ) 365return FALSE; 366 367if (! GetMenuString (nIDItem, lpszText, nLen, nFlags)) 368return FALSE; 369 370bstrText = :: SysAllocString ( T2OLE (lpszText)); 371return (bstrText != NULL ) ? TRUE : FALSE; 372} 373 374#ifdef __ATLSTR_H__ 375int GetMenuString ( UINT nIDItem, ATL ::CString & strText, UINT nFlags) const 376{ 377ATLASSERT (:: IsMenu ( m_hMenu )); 378 379int nLen = GetMenuStringLen (nIDItem, nFlags); 380if (nLen == 0 ) 381return 0 ; 382 383nLen ++ ; // increment to include terminating NULL char 384LPTSTR lpstr = strText. GetBufferSetLength (nLen); 385if (lpstr == NULL ) 386return 0 ; 387int nRet = GetMenuString (nIDItem, lpstr, nLen, nFlags); 388strText. ReleaseBuffer (); 389return nRet; 390} 391#endif // __ATLSTR_H__ 392 393CMenuHandle GetSubMenu ( int nPos) const 394{ 395ATLASSERT (:: IsMenu ( m_hMenu )); 396return CMenuHandle (:: GetSubMenu (m_hMenu, nPos)); 397} 398 399BOOL InsertMenu ( UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0 , LPCTSTR lpszNewItem = NULL ) 400{ 401ATLASSERT (:: IsMenu (m_hMenu)); 402return :: InsertMenu (m_hMenu, nPosition, nFlags, nIDNewItem, lpszNewItem); 403} 404 405BOOL InsertMenu ( UINT nPosition, UINT nFlags, HMENU hSubMenu, LPCTSTR lpszNewItem) 406{ 407ATLASSERT (:: IsMenu ( m_hMenu )); 408ATLASSERT (:: IsMenu ( hSubMenu )); 409return :: InsertMenu (m_hMenu, nPosition, nFlags | MF_POPUP , ( UINT_PTR )hSubMenu, lpszNewItem); 410} 411 412BOOL InsertMenu ( UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, HBITMAP hBmp) 413{ 414ATLASSERT (:: IsMenu ( m_hMenu )); 415return :: InsertMenu (m_hMenu, nPosition, nFlags | MF_BITMAP , nIDNewItem, ( LPCTSTR )hBmp); 416} 417 418BOOL InsertMenu ( UINT nPosition, UINT nFlags, HMENU hSubMenu, HBITMAP hBmp) 419{ 420ATLASSERT (:: IsMenu ( m_hMenu )); 421ATLASSERT (:: IsMenu ( hSubMenu )); 422return :: InsertMenu (m_hMenu, nPosition, nFlags | ( MF_BITMAP | MF_POPUP ), ( UINT_PTR )hSubMenu, ( LPCTSTR )hBmp); 423} 424 425BOOL ModifyMenu ( UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0 , LPCTSTR lpszNewItem = NULL ) 426{ 427ATLASSERT (:: IsMenu (m_hMenu)); 428return :: ModifyMenu (m_hMenu, nPosition, nFlags, nIDNewItem, lpszNewItem); 429} 430 431BOOL ModifyMenu ( UINT nPosition, UINT nFlags, HMENU hSubMenu, LPCTSTR lpszNewItem) 432{ 433ATLASSERT (:: IsMenu ( m_hMenu )); 434ATLASSERT (:: IsMenu ( hSubMenu )); 435return :: ModifyMenu (m_hMenu, nPosition, nFlags | MF_POPUP , ( UINT_PTR )hSubMenu, lpszNewItem); 436} 437 438BOOL ModifyMenu ( UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, HBITMAP hBmp) 439{ 440ATLASSERT (:: IsMenu ( m_hMenu )); 441return :: ModifyMenu (m_hMenu, nPosition, nFlags | MF_BITMAP , nIDNewItem, ( LPCTSTR )hBmp); 442} 443 444BOOL ModifyMenu ( UINT nPosition, UINT nFlags, HMENU hSubMenu, HBITMAP hBmp) 445{ 446ATLASSERT (:: IsMenu ( m_hMenu )); 447ATLASSERT (:: IsMenu ( hSubMenu )); 448return :: ModifyMenu (m_hMenu, nPosition, nFlags | ( MF_BITMAP | MF_POPUP ), ( UINT_PTR )hSubMenu, ( LPCTSTR )hBmp); 449} 450 451BOOL RemoveMenu ( UINT nPosition, UINT nFlags) 452{ 453ATLASSERT (:: IsMenu ( m_hMenu )); 454return :: RemoveMenu (m_hMenu, nPosition, nFlags); 455} 456 457BOOL SetMenuItemBitmaps ( UINT nPosition, UINT nFlags, HBITMAP hBmpUnchecked, HBITMAP hBmpChecked) 458{ 459ATLASSERT (:: IsMenu ( m_hMenu )); 460return :: SetMenuItemBitmaps (m_hMenu, nPosition, nFlags, hBmpUnchecked, hBmpChecked); 461} 462 463BOOL CheckMenuRadioItem ( UINT nIDFirst, UINT nIDLast, UINT nIDItem, UINT nFlags) 464{ 465ATLASSERT (:: IsMenu ( m_hMenu )); 466return :: CheckMenuRadioItem (m_hMenu, nIDFirst, nIDLast, nIDItem, nFlags); 467} 468 469BOOL GetMenuItemInfo ( UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii) const 470{ 471ATLASSERT (:: IsMenu ( m_hMenu )); 472return ( BOOL ):: GetMenuItemInfo (m_hMenu, uItem, bByPosition, lpmii); 473} 474 475BOOL SetMenuItemInfo ( UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii) 476{ 477ATLASSERT (:: IsMenu ( m_hMenu )); 478return ( BOOL ):: SetMenuItemInfo (m_hMenu, uItem, bByPosition, lpmii); 479} 480 481BOOL InsertMenuItem ( UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii) 482{ 483ATLASSERT (:: IsMenu ( m_hMenu )); 484return ( BOOL ):: InsertMenuItem (m_hMenu, uItem, bByPosition, lpmii); 485} 486 487UINT GetMenuDefaultItem ( BOOL bByPosition = FALSE, UINT uFlags = 0U ) const 488{ 489ATLASSERT (:: IsMenu (m_hMenu)); 490return :: GetMenuDefaultItem (m_hMenu, ( UINT )bByPosition, uFlags); 491} 492 493BOOL SetMenuDefaultItem ( UINT uItem = ( UINT ) - 1 , BOOL bByPosition = FALSE) 494{ 495ATLASSERT (:: IsMenu (m_hMenu)); 496return :: SetMenuDefaultItem (m_hMenu, uItem, ( UINT )bByPosition); 497} 498 499BOOL GetMenuItemRect ( HWND hWnd, UINT uItem, LPRECT lprcItem) const 500{ 501ATLASSERT (:: IsMenu ( m_hMenu )); 502return :: GetMenuItemRect (hWnd, m_hMenu, uItem, lprcItem); 503} 504 505int MenuItemFromPoint ( HWND hWnd, POINT point) const 506{ 507ATLASSERT (:: IsMenu ( m_hMenu )); 508return :: MenuItemFromPoint (hWnd, m_hMenu, point); 509} 510 511// Context Help Functions 512BOOL SetMenuContextHelpId ( DWORD dwContextHelpId) 513{ 514ATLASSERT (:: IsMenu ( m_hMenu )); 515return :: SetMenuContextHelpId (m_hMenu, dwContextHelpId); 516} 517 518DWORD GetMenuContextHelpId () const 519{ 520ATLASSERT (:: IsMenu ( m_hMenu )); 521return :: GetMenuContextHelpId ( m_hMenu ); 522} 523}; 524 525 526/////////////////////////////////////////////////////////////////////////////// 527// CAccelerator 528 529template < bool t_bManaged > 530class CAcceleratorT 531{ 532public: 533HACCEL m_hAccel; 534 535// Constructor/destructor/operators 536CAcceleratorT( HACCEL hAccel = NULL ) : m_hAccel (hAccel) 537{ } 538 539~ CAcceleratorT () 540{ 541if (t_bManaged && (m_hAccel != NULL )) 542:: DestroyAcceleratorTable (m_hAccel); 543} 544 545CAcceleratorT < t_bManaged >& operator = ( HACCEL hAccel) 546{ 547Attach (hAccel); 548return * this; 549} 550 551void Attach ( HACCEL hAccel) 552{ 553if (t_bManaged && (m_hAccel != NULL )) 554:: DestroyAcceleratorTable (m_hAccel); 555m_hAccel = hAccel; 556} 557 558HACCEL Detach () 559{ 560HACCEL hAccel = m_hAccel; 561m_hAccel = NULL ; 562return hAccel; 563} 564 565operator HACCEL () const { return m_hAccel; } 566 567bool IsNull () const { return m_hAccel == NULL ; } 568 569// Create/destroy methods 570HACCEL LoadAccelerators ( ATL ::_U_STRINGorID accel) 571{ 572ATLASSERT (m_hAccel == NULL ); 573m_hAccel = :: LoadAccelerators (ModuleHelper:: GetResourceInstance (), accel. m_lpstr ); 574return m_hAccel; 575} 576 577HACCEL CreateAcceleratorTable ( LPACCEL pAccel, int cEntries) 578{ 579ATLASSERT (m_hAccel == NULL ); 580ATLASSERT (pAccel != NULL ); 581m_hAccel = :: CreateAcceleratorTable (pAccel, cEntries); 582return m_hAccel; 583} 584 585void DestroyObject () 586{ 587if (m_hAccel != NULL ) 588{ 589:: DestroyAcceleratorTable (m_hAccel); 590m_hAccel = NULL ; 591} 592} 593 594// Operations 595int CopyAcceleratorTable ( LPACCEL lpAccelDst, int cEntries) 596{ 597ATLASSERT (m_hAccel != NULL ); 598ATLASSERT (lpAccelDst != NULL ); 599return :: CopyAcceleratorTable (m_hAccel, lpAccelDst, cEntries); 600} 601 602int GetEntriesCount () const 603{ 604ATLASSERT (m_hAccel != NULL ); 605return :: CopyAcceleratorTable (m_hAccel, NULL , 0 ); 606} 607 608BOOL TranslateAccelerator ( HWND hWnd, LPMSG pMsg) 609{ 610ATLASSERT (m_hAccel != NULL ); 611ATLASSERT (:: IsWindow ( hWnd )); 612ATLASSERT (pMsg != NULL ); 613return :: TranslateAccelerator (hWnd, m_hAccel, pMsg); 614} 615}; 616 617typedef CAcceleratorT < false > CAcceleratorHandle ; 618typedef CAcceleratorT < true > CAccelerator ; 619 620 621/////////////////////////////////////////////////////////////////////////////// 622// CIcon 623 624template < bool t_bManaged > 625class CIconT 626{ 627public : 628HICON m_hIcon; 629 630// Constructor/destructor/operators 631CIconT( HICON hIcon = NULL ) : m_hIcon (hIcon) 632{ } 633 634~ CIconT () 635{ 636if (t_bManaged && (m_hIcon != NULL )) 637:: DestroyIcon (m_hIcon); 638} 639 640CIconT < t_bManaged >& operator = ( HICON hIcon) 641{ 642Attach (hIcon); 643return * this; 644} 645 646void Attach ( HICON hIcon) 647{ 648if (t_bManaged && (m_hIcon != NULL )) 649:: DestroyIcon (m_hIcon); 650m_hIcon = hIcon; 651} 652 653HICON Detach () 654{ 655HICON hIcon = m_hIcon; 656m_hIcon = NULL ; 657return hIcon; 658} 659 660operator HICON () const { return m_hIcon; } 661 662bool IsNull () const { return m_hIcon == NULL ; } 663 664// Create/destroy methods 665HICON LoadIcon ( ATL ::_U_STRINGorID icon) 666{ 667ATLASSERT (m_hIcon == NULL ); 668m_hIcon = :: LoadIcon (ModuleHelper:: GetResourceInstance (), icon. m_lpstr ); 669return m_hIcon; 670} 671 672HICON LoadIcon ( ATL ::_U_STRINGorID icon, int cxDesired, int cyDesired, UINT fuLoad = 0 ) 673{ 674ATLASSERT (m_hIcon == NULL ); 675m_hIcon = ( HICON ) :: LoadImage ( ModuleHelper :: GetResourceInstance (), icon. m_lpstr , IMAGE_ICON , cxDesired, cyDesired, fuLoad); 676return m_hIcon; 677} 678 679HICON LoadOEMIcon ( LPCTSTR lpstrIconName) 680{ 681ATLASSERT (m_hIcon == NULL ); 682ATLASSERT ( IsOEMIcon (lpstrIconName)); 683m_hIcon = :: LoadIcon ( NULL , lpstrIconName); 684return m_hIcon; 685} 686 687HICON CreateIcon ( int nWidth, int nHeight, BYTE cPlanes, BYTE cBitsPixel, CONST BYTE * lpbANDbits, CONST BYTE * lpbXORbits) 688{ 689ATLASSERT (m_hIcon == NULL ); 690ATLASSERT (lpbANDbits != NULL ); 691ATLASSERT (lpbXORbits != NULL ); 692m_hIcon = :: CreateIcon (ModuleHelper:: GetResourceInstance (), nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits); 693return m_hIcon; 694} 695 696HICON CreateIconFromResource ( PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000 ) 697{ 698ATLASSERT (m_hIcon == NULL ); 699ATLASSERT (pBits != NULL ); 700m_hIcon = :: CreateIconFromResource (pBits, dwResSize, TRUE, dwVersion); 701return m_hIcon; 702} 703 704HICON CreateIconFromResourceEx ( PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000 , int cxDesired = 0 , int cyDesired = 0 , UINT uFlags = LR_DEFAULTCOLOR ) 705{ 706ATLASSERT (m_hIcon == NULL ); 707ATLASSERT (pbBits != NULL ); 708ATLASSERT (cbBits > 0 ); 709m_hIcon = :: CreateIconFromResourceEx (pbBits, cbBits, TRUE, dwVersion, cxDesired, cyDesired, uFlags); 710return m_hIcon; 711} 712 713HICON CreateIconIndirect ( PICONINFO pIconInfo) 714{ 715ATLASSERT (m_hIcon == NULL ); 716ATLASSERT (pIconInfo != NULL ); 717m_hIcon = :: CreateIconIndirect (pIconInfo); 718return m_hIcon; 719} 720 721HICON ExtractIcon ( LPCTSTR lpszExeFileName, UINT nIconIndex) 722{ 723ATLASSERT (m_hIcon == NULL ); 724ATLASSERT (lpszExeFileName != NULL ); 725m_hIcon = :: ExtractIcon (ModuleHelper:: GetModuleInstance (), lpszExeFileName, nIconIndex); 726return m_hIcon; 727} 728 729HICON ExtractAssociatedIcon ( HINSTANCE hInst, LPTSTR lpIconPath, LPWORD lpiIcon) 730{ 731ATLASSERT (m_hIcon == NULL ); 732ATLASSERT (lpIconPath != NULL ); 733ATLASSERT (lpiIcon != NULL ); 734m_hIcon = :: ExtractAssociatedIcon (hInst, lpIconPath, lpiIcon); 735return m_hIcon; 736} 737 738BOOL DestroyIcon () 739{ 740ATLASSERT (m_hIcon != NULL ); 741BOOL bRet = :: DestroyIcon (m_hIcon); 742if (bRet != FALSE) 743m_hIcon = NULL ; 744return bRet; 745} 746 747// Operations 748HICON CopyIcon () 749{ 750ATLASSERT (m_hIcon != NULL ); 751return :: CopyIcon (m_hIcon); 752} 753 754HICON DuplicateIcon () 755{ 756ATLASSERT (m_hIcon != NULL ); 757return :: DuplicateIcon ( NULL , m_hIcon); 758} 759 760BOOL DrawIcon ( HDC hDC, int x, int y) 761{ 762ATLASSERT (m_hIcon != NULL ); 763return :: DrawIcon (hDC, x, y, m_hIcon); 764} 765 766BOOL DrawIcon ( HDC hDC, POINT pt) 767{ 768ATLASSERT (m_hIcon != NULL ); 769return :: DrawIcon (hDC, pt. x , pt. y , m_hIcon); 770} 771 772BOOL DrawIconEx ( HDC hDC, int x, int y, int cxWidth, int cyWidth, UINT uStepIfAniCur = 0 , HBRUSH hbrFlickerFreeDraw = NULL , UINT uFlags = DI_NORMAL ) 773{ 774ATLASSERT (m_hIcon != NULL ); 775return :: DrawIconEx (hDC, x, y, m_hIcon, cxWidth, cyWidth, uStepIfAniCur, hbrFlickerFreeDraw, uFlags); 776} 777 778BOOL DrawIconEx ( HDC hDC, POINT pt, SIZE size, UINT uStepIfAniCur = 0 , HBRUSH hbrFlickerFreeDraw = NULL , UINT uFlags = DI_NORMAL ) 779{ 780ATLASSERT (m_hIcon != NULL ); 781return :: DrawIconEx (hDC, pt. x , pt. y , m_hIcon, size. cx , size. cy , uStepIfAniCur, hbrFlickerFreeDraw, uFlags); 782} 783 784BOOL GetIconInfo ( PICONINFO pIconInfo) const 785{ 786ATLASSERT (m_hIcon != NULL ); 787ATLASSERT (pIconInfo != NULL ); 788return :: GetIconInfo (m_hIcon, pIconInfo); 789} 790 791#if (_WIN32_WINNT >= 0x0600 ) 792BOOL GetIconInfoEx ( PICONINFOEX pIconInfo) const 793{ 794ATLASSERT (m_hIcon != NULL ); 795ATLASSERT (pIconInfo != NULL ); 796return :: GetIconInfoEx (m_hIcon, pIconInfo); 797} 798#endif // (_WIN32_WINNT >= 0x0600) 799 800#if defined( NTDDI_VERSION ) && ( NTDDI_VERSION >= NTDDI_LONGHORN ) 801HRESULT LoadIconMetric ( ATL ::_U_STRINGorID icon, int lims) 802{ 803ATLASSERT (m_hIcon == NULL ); 804USES_CONVERSION ; 805return :: LoadIconMetric (ModuleHelper:: GetResourceInstance (), T2CW (icon. m_lpstr ), lims, & m_hIcon); 806} 807 808HRESULT LoadIconWithScaleDown ( ATL ::_U_STRINGorID icon, int cx, int cy) 809{ 810ATLASSERT (m_hIcon == NULL ); 811USES_CONVERSION ; 812return :: LoadIconWithScaleDown (ModuleHelper:: GetResourceInstance (), T2CW (icon. m_lpstr ), cx, cy, & m_hIcon); 813} 814 815HRESULT LoadOEMIconMetric ( LPCTSTR lpstrIconName, int lims) 816{ 817ATLASSERT (m_hIcon == NULL ); 818ATLASSERT ( IsOEMIcon (lpstrIconName)); 819return :: LoadIconMetric ( NULL , ( LPCWSTR )lpstrIconName, lims, & m_hIcon); 820} 821 822HRESULT LoadOEMIconWithScaleDown ( LPCTSTR lpstrIconName, int cx, int cy) 823{ 824ATLASSERT (m_hIcon == NULL ); 825ATLASSERT ( IsOEMIcon (lpstrIconName)); 826USES_CONVERSION ; 827return :: LoadIconWithScaleDown ( NULL , ( LPCWSTR )lpstrIconName, cx, cy, & m_hIcon); 828} 829#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) 830 831// Helper 832static bool IsOEMIcon ( LPCTSTR lpstrIconName) 833{ 834#if ( WINVER >= 0x0600 ) 835return ((lpstrIconName == IDI_APPLICATION ) || (lpstrIconName == IDI_ASTERISK ) || (lpstrIconName == IDI_EXCLAMATION ) || 836(lpstrIconName == IDI_HAND ) || (lpstrIconName == IDI_QUESTION ) || (lpstrIconName == IDI_WINLOGO ) || 837(lpstrIconName == IDI_SHIELD )); 838#else // !(WINVER >= 0x0600) 839return ((lpstrIconName == IDI_APPLICATION ) || (lpstrIconName == IDI_ASTERISK ) || (lpstrIconName == IDI_EXCLAMATION ) || 840(lpstrIconName == IDI_HAND ) || (lpstrIconName == IDI_QUESTION ) || (lpstrIconName == IDI_WINLOGO )); 841#endif // !(WINVER >= 0x0600) 842} 843}; 844 845typedef CIconT < false > CIconHandle ; 846typedef CIconT < true > CIcon ; 847 848 849/////////////////////////////////////////////////////////////////////////////// 850// CCursor 851 852// protect template member from a winuser.h macro 853#ifdef CopyCursor 854#undef CopyCursor 855#endif 856 857template < bool t_bManaged > 858class CCursorT 859{ 860public : 861HCURSOR m_hCursor; 862 863// Constructor/destructor/operators 864CCursorT( HCURSOR hCursor = NULL ) : m_hCursor (hCursor) 865{ } 866 867~ CCursorT () 868{ 869if (t_bManaged && (m_hCursor != NULL )) 870DestroyCursor (); 871} 872 873CCursorT < t_bManaged >& operator = ( HCURSOR hCursor) 874{ 875Attach (hCursor); 876return * this; 877} 878 879void Attach ( HCURSOR hCursor) 880{ 881if (t_bManaged && (m_hCursor != NULL )) 882DestroyCursor (); 883m_hCursor = hCursor; 884} 885 886HCURSOR Detach () 887{ 888HCURSOR hCursor = m_hCursor; 889m_hCursor = NULL ; 890return hCursor; 891} 892 893operator HCURSOR () const { return m_hCursor; } 894 895bool IsNull () const { return m_hCursor == NULL ; } 896 897// Create/destroy methods 898HCURSOR LoadCursor ( ATL ::_U_STRINGorID cursor) 899{ 900ATLASSERT (m_hCursor == NULL ); 901m_hCursor = :: LoadCursor (ModuleHelper:: GetResourceInstance (), cursor. m_lpstr ); 902return m_hCursor; 903} 904 905HCURSOR LoadSysCursor ( LPCTSTR lpstrCursorName) 906{ 907ATLASSERT (m_hCursor == NULL ); 908ATLASSERT ((lpstrCursorName == IDC_ARROW ) || (lpstrCursorName == IDC_IBEAM ) || (lpstrCursorName == IDC_WAIT ) || 909(lpstrCursorName == IDC_CROSS ) || (lpstrCursorName == IDC_UPARROW ) || (lpstrCursorName == IDC_SIZE ) || 910(lpstrCursorName == IDC_ICON ) || (lpstrCursorName == IDC_SIZENWSE ) || (lpstrCursorName == IDC_SIZENESW ) || 911(lpstrCursorName == IDC_SIZEWE ) || (lpstrCursorName == IDC_SIZENS ) || (lpstrCursorName == IDC_SIZEALL ) || 912(lpstrCursorName == IDC_NO ) || (lpstrCursorName == IDC_APPSTARTING ) || (lpstrCursorName == IDC_HELP ) || 913(lpstrCursorName == IDC_HAND )); 914m_hCursor = :: LoadCursor ( NULL , lpstrCursorName); 915return m_hCursor; 916} 917 918// deprecated 919HCURSOR LoadOEMCursor ( LPCTSTR lpstrCursorName) 920{ 921return LoadSysCursor (lpstrCursorName); 922} 923 924HCURSOR LoadCursor ( ATL ::_U_STRINGorID cursor, int cxDesired, int cyDesired, UINT fuLoad = 0 ) 925{ 926ATLASSERT (m_hCursor == NULL ); 927m_hCursor = ( HCURSOR ) :: LoadImage ( ModuleHelper :: GetResourceInstance (), cursor. m_lpstr , IMAGE_CURSOR , cxDesired, cyDesired, fuLoad); 928return m_hCursor; 929} 930 931HCURSOR LoadCursorFromFile ( LPCTSTR pstrFilename) 932{ 933ATLASSERT (m_hCursor == NULL ); 934ATLASSERT (pstrFilename != NULL ); 935m_hCursor = :: LoadCursorFromFile (pstrFilename); 936return m_hCursor; 937} 938 939HCURSOR CreateCursor ( int xHotSpot, int yHotSpot, int nWidth, int nHeight, CONST VOID * pvANDPlane, CONST VOID * pvXORPlane) 940{ 941ATLASSERT (m_hCursor == NULL ); 942m_hCursor = :: CreateCursor (ModuleHelper:: GetResourceInstance (), xHotSpot, yHotSpot, nWidth, nHeight, pvANDPlane, pvXORPlane); 943return m_hCursor; 944} 945 946HCURSOR CreateCursorFromResource ( PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000 ) 947{ 948ATLASSERT (m_hCursor == NULL ); 949ATLASSERT (pBits != NULL ); 950m_hCursor = ( HCURSOR ):: CreateIconFromResource (pBits, dwResSize, FALSE, dwVersion); 951return m_hCursor; 952} 953 954HCURSOR CreateCursorFromResourceEx ( PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000 , int cxDesired = 0 , int cyDesired = 0 , UINT uFlags = LR_DEFAULTCOLOR ) 955{ 956ATLASSERT (m_hCursor == NULL ); 957ATLASSERT (pbBits != NULL ); 958ATLASSERT (cbBits > 0 ); 959m_hCursor = ( HCURSOR ):: CreateIconFromResourceEx (pbBits, cbBits, FALSE, dwVersion, cxDesired, cyDesired, uFlags); 960return m_hCursor; 961} 962 963BOOL DestroyCursor () 964{ 965ATLASSERT (m_hCursor != NULL ); 966BOOL bRet = :: DestroyCursor (m_hCursor); 967if (bRet != FALSE) 968m_hCursor = NULL ; 969return bRet; 970} 971 972// Operations 973HCURSOR CopyCursor () 974{ 975ATLASSERT (m_hCursor != NULL ); 976return ( HCURSOR ):: CopyIcon (( HICON )m_hCursor); 977} 978 979BOOL GetCursorInfo ( LPCURSORINFO pCursorInfo) 980{ 981ATLASSERT (m_hCursor != NULL ); 982ATLASSERT (pCursorInfo != NULL ); 983return :: GetCursorInfo (pCursorInfo); 984} 985}; 986 987typedef CCursorT < false > CCursorHandle ; 988typedef CCursorT < true > CCursor ; 989 990 991/////////////////////////////////////////////////////////////////////////////// 992// CResource - Wraps a generic Windows resource. 993// Use it with custom resource types other than the 994// standard RT_CURSOR, RT_BITMAP, etc. 995 996class CResource 997{ 998public : 999HGLOBAL m_hGlobal; 1000HRSRC m_hResource; 1001 1002// Constructor/destructor 1003CResource () : m_hGlobal ( NULL ), m_hResource ( NULL ) 1004{ } 1005 1006~ CResource () 1007{ 1008Release (); 1009} 1010 1011// Load methods 1012bool Load ( ATL ::_U_STRINGorID Type, ATL ::_U_STRINGorID ID ) 1013{ 1014ATLASSERT (m_hResource == NULL ); 1015ATLASSERT (m_hGlobal == NULL ); 1016 1017m_hResource = :: FindResource (ModuleHelper:: GetResourceInstance (), ID . m_lpstr , Type. m_lpstr ); 1018if (m_hResource == NULL ) 1019return false; 1020 1021m_hGlobal = :: LoadResource (ModuleHelper:: GetResourceInstance (), m_hResource); 1022if (m_hGlobal == NULL ) 1023{ 1024m_hResource = NULL ; 1025return false; 1026} 1027 1028return true; 1029} 1030 1031bool LoadEx ( ATL ::_U_STRINGorID ID , ATL ::_U_STRINGorID Type, WORD wLanguage) 1032{ 1033ATLASSERT (m_hResource == NULL ); 1034ATLASSERT (m_hGlobal == NULL ); 1035 1036m_hResource = :: FindResourceEx (ModuleHelper:: GetResourceInstance (), Type. m_lpstr , ID . m_lpstr , wLanguage); 1037if (m_hResource == NULL ) 1038return false; 1039 1040m_hGlobal = :: LoadResource (ModuleHelper:: GetResourceInstance (), m_hResource); 1041if (m_hGlobal == NULL ) 1042{ 1043m_hResource = NULL ; 1044return false; 1045} 1046 1047return true; 1048} 1049 1050// Misc. operations 1051DWORD GetSize () const 1052{ 1053ATLASSERT (m_hResource != NULL ); 1054return :: SizeofResource (ModuleHelper:: GetResourceInstance (), m_hResource); 1055} 1056 1057LPVOID Lock () 1058{ 1059ATLASSERT (m_hResource != NULL ); 1060ATLASSERT (m_hGlobal != NULL ); 1061LPVOID pVoid = :: LockResource (m_hGlobal); 1062ATLASSERT (pVoid != NULL ); 1063return pVoid; 1064} 1065 1066void Release () 1067{ 1068if (m_hGlobal != NULL ) 1069{ 1070FreeResource (m_hGlobal); 1071m_hGlobal = NULL ; 1072m_hResource = NULL ; 1073} 1074} 1075}; 1076 1077 1078/////////////////////////////////////////////////////////////////////////////// 1079// Toolbar resource descriptor 1080 1081struct _AtlToolBarData 1082{ 1083WORD wVersion ; 1084WORD wWidth ; 1085WORD wHeight ; 1086WORD wItemCount ; 1087 1088WORD * items () 1089{ return ( WORD * )( this + 1 ); } 1090}; 1091 1092 1093/////////////////////////////////////////////////////////////////////////////// 1094// Global functions for loading resources 1095 1096inline HACCEL AtlLoadAccelerators ( ATL ::_U_STRINGorID table) 1097{ 1098return :: LoadAccelerators (ModuleHelper:: GetResourceInstance (), table. m_lpstr ); 1099} 1100 1101inline HMENU AtlLoadMenu ( ATL ::_U_STRINGorID menu) 1102{ 1103return :: LoadMenu (ModuleHelper:: GetResourceInstance (), menu. m_lpstr ); 1104} 1105 1106inline HBITMAP AtlLoadBitmap ( ATL ::_U_STRINGorID bitmap) 1107{ 1108return :: LoadBitmap (ModuleHelper:: GetResourceInstance (), bitmap. m_lpstr ); 1109} 1110 1111#ifdef OEMRESOURCE 1112inline HBITMAP AtlLoadSysBitmap ( ATL ::_U_STRINGorID bitmap) 1113{ 1114#ifdef _DEBUG 1115WORD wID = LOWORD (bitmap. m_lpstr ); 1116ATLASSERT ((wID >= 32734 ) && (wID <= 32767 )); 1117#endif // _DEBUG 1118return :: LoadBitmap ( NULL , bitmap. m_lpstr ); 1119} 1120#endif // OEMRESOURCE 1121 1122inline HCURSOR AtlLoadCursor ( ATL ::_U_STRINGorID cursor) 1123{ 1124return :: LoadCursor (ModuleHelper:: GetResourceInstance (), cursor. m_lpstr ); 1125} 1126 1127inline HCURSOR AtlLoadSysCursor ( LPCTSTR lpCursorName) 1128{ 1129ATLASSERT ((lpCursorName == IDC_ARROW ) || (lpCursorName == IDC_IBEAM ) || (lpCursorName == IDC_WAIT ) || 1130(lpCursorName == IDC_CROSS ) || (lpCursorName == IDC_UPARROW ) || (lpCursorName == IDC_SIZE ) || 1131(lpCursorName == IDC_ICON ) || (lpCursorName == IDC_SIZENWSE ) || (lpCursorName == IDC_SIZENESW ) || 1132(lpCursorName == IDC_SIZEWE ) || (lpCursorName == IDC_SIZENS ) || (lpCursorName == IDC_SIZEALL ) || 1133(lpCursorName == IDC_NO ) || (lpCursorName == IDC_APPSTARTING ) || (lpCursorName == IDC_HELP ) || 1134(lpCursorName == IDC_HAND )); 1135return :: LoadCursor ( NULL , lpCursorName); 1136} 1137 1138inline HICON AtlLoadIcon ( ATL ::_U_STRINGorID icon) 1139{ 1140return :: LoadIcon (ModuleHelper:: GetResourceInstance (), icon. m_lpstr ); 1141} 1142 1143inline HICON AtlLoadSysIcon ( LPCTSTR lpIconName) 1144{ 1145#if ( WINVER >= 0x0600 ) 1146ATLASSERT ((lpIconName == IDI_APPLICATION ) || (lpIconName == IDI_ASTERISK ) || (lpIconName == IDI_EXCLAMATION ) || 1147(lpIconName == IDI_HAND ) || (lpIconName == IDI_QUESTION ) || (lpIconName == IDI_WINLOGO ) || 1148(lpIconName == IDI_SHIELD )); 1149#else // !(WINVER >= 0x0600) 1150ATLASSERT ((lpIconName == IDI_APPLICATION ) || (lpIconName == IDI_ASTERISK ) || (lpIconName == IDI_EXCLAMATION ) || 1151(lpIconName == IDI_HAND ) || (lpIconName == IDI_QUESTION ) || (lpIconName == IDI_WINLOGO )); 1152#endif // !(WINVER >= 0x0600) 1153return :: LoadIcon ( NULL , lpIconName); 1154} 1155 1156inline HBITMAP AtlLoadBitmapImage ( ATL ::_U_STRINGorID bitmap, UINT fuLoad = LR_DEFAULTCOLOR ) 1157{ 1158return ( HBITMAP ):: LoadImage (ModuleHelper:: GetResourceInstance (), bitmap. m_lpstr , IMAGE_BITMAP , 0 , 0 , fuLoad); 1159} 1160 1161inline HCURSOR AtlLoadCursorImage ( ATL ::_U_STRINGorID cursor, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE , int cxDesired = 0 , int cyDesired = 0 ) 1162{ 1163return ( HCURSOR ):: LoadImage (ModuleHelper:: GetResourceInstance (), cursor. m_lpstr , IMAGE_CURSOR , cxDesired, cyDesired, fuLoad); 1164} 1165 1166inline HICON AtlLoadIconImage ( ATL ::_U_STRINGorID icon, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE , int cxDesired = 0 , int cyDesired = 0 ) 1167{ 1168return ( HICON ):: LoadImage (ModuleHelper:: GetResourceInstance (), icon. m_lpstr , IMAGE_ICON , cxDesired, cyDesired, fuLoad); 1169} 1170 1171#ifdef OEMRESOURCE 1172inline HBITMAP AtlLoadSysBitmapImage ( WORD wBitmapID, UINT fuLoad = LR_DEFAULTCOLOR ) 1173{ 1174ATLASSERT ((wBitmapID >= 32734 ) && (wBitmapID <= 32767 )); 1175ATLASSERT ((fuLoad & LR_LOADFROMFILE ) == 0 ); // this one doesn't load from a file 1176return ( HBITMAP ):: LoadImage ( NULL , MAKEINTRESOURCE (wBitmapID), IMAGE_BITMAP , 0 , 0 , fuLoad); 1177} 1178#endif // OEMRESOURCE 1179 1180inline HCURSOR AtlLoadSysCursorImage ( ATL ::_U_STRINGorID cursor, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE , int cxDesired = 0 , int cyDesired = 0 ) 1181{ 1182#ifdef _DEBUG 1183WORD wID = LOWORD (cursor. m_lpstr ); 1184ATLASSERT (((wID >= 32512 ) && (wID <= 32516 )) || ((wID >= 32640 ) && (wID <= 32648 )) || (wID == 32650 ) || (wID == 32651 )); 1185ATLASSERT ((fuLoad & LR_LOADFROMFILE ) == 0 ); // this one doesn't load from a file 1186#endif // _DEBUG 1187return ( HCURSOR ):: LoadImage ( NULL , cursor. m_lpstr , IMAGE_CURSOR , cxDesired, cyDesired, fuLoad); 1188} 1189 1190inline HICON AtlLoadSysIconImage ( ATL ::_U_STRINGorID icon, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE , int cxDesired = 0 , int cyDesired = 0 ) 1191{ 1192#ifdef _DEBUG 1193WORD wID = LOWORD (icon. m_lpstr ); 1194ATLASSERT ((wID >= 32512 ) && (wID <= 32517 )); 1195ATLASSERT ((fuLoad & LR_LOADFROMFILE ) == 0 ); // this one doesn't load from a file 1196#endif // _DEBUG 1197return ( HICON ):: LoadImage ( NULL , icon. m_lpstr , IMAGE_ICON , cxDesired, cyDesired, fuLoad); 1198} 1199 1200inline bool AtlLoadString ( UINT uID, BSTR & bstrText) 1201{ 1202USES_CONVERSION ; 1203ATLASSERT (bstrText == NULL ); 1204 1205LPTSTR lpstrText = NULL ; 1206int nRes = 0 ; 1207for ( int nLen = 256 ; ; nLen *= 2 ) 1208{ 1209ATLTRY (lpstrText = new TCHAR [nLen]); 1210if (lpstrText == NULL ) 1211break ; 1212nRes = :: LoadString (ModuleHelper:: GetResourceInstance (), uID, lpstrText, nLen); 1213if (nRes < nLen - 1 ) 1214break ; 1215delete [] lpstrText; 1216lpstrText = NULL ; 1217} 1218 1219if (lpstrText != NULL ) 1220{ 1221if (nRes != 0 ) 1222bstrText = :: SysAllocString ( T2OLE (lpstrText)); 1223delete [] lpstrText; 1224} 1225 1226return (bstrText != NULL ) ? true : false; 1227} 1228 1229} // namespace WTL 1230 1231#endif // __ATLUSER_H__