ExtCmdManager.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:173k
- {
- _file.Attach( pStream );
- CArchive ar( &_file, CArchive::store|CArchive::bNoFlushOnDelete );
- CRuntimeClass * pRTC = pRM->GetRuntimeClass();
- ASSERT( pRTC != NULL );
- ar.WriteClass( pRTC );
- pRM->SerializeSynchronizationData( ar );
- ar.Flush();
- ULARGE_INTEGER liNewPosition;
- LARGE_INTEGER liOff;
- LISet32( liOff, 0 );
- sc = pStream->Seek( liOff, STREAM_SEEK_SET, &liNewPosition );
- if( sc != S_OK )
- {
- ASSERT( FALSE );
- ::AfxThrowUserException();
- }
- return pStream;
- } // try
- catch( CException * pException )
- {
- pException->Delete();
- } // catch( CException * pException )
- catch( ... )
- {
- } // catch( ... )
- _file.Detach();
- pStream->Release();
- return NULL;
- }
- void CExtResourceManager::CExtResourceManagerAutoPtr::PmSynchronizeSink_SynchronizeFrom(
- LPSTREAM pStream
- )
- {
- __PROF_UIS_MANAGE_STATE;
- if( pStream == NULL )
- return;
- if( PmSynchronizeSink_IsSynchronizing() )
- return;
- m_bPmSynchronizeSinkIsSynchronizing = true;
- COleStreamFile _file;
- _file.Attach( pStream );
- try
- {
- CArchive ar( &_file, CArchive::load|CArchive::bNoFlushOnDelete, 0 );
- CRuntimeClass * pRTC = ar.ReadClass();
- ASSERT( pRTC != NULL );
- CObject * pObj = pRTC->CreateObject();
- if( pObj != NULL )
- {
- ASSERT_VALID( pObj );
- CExtResourceManager * pResourceManager =
- DYNAMIC_DOWNCAST( CExtResourceManager, pObj );
- if( pResourceManager == NULL )
- {
- ASSERT( FALSE );
- delete pObj;
- } // if( pPaintManager == NULL )
- else
- {
- pResourceManager->SerializeSynchronizationData( ar );
- InstallResourceManager( pResourceManager );
- PmSynchronizeSink_SynchronizeOthers();
- } // else from if( pPaintManager == NULL )
- } // if( pObj != NULL )
- } // try
- catch( CException * pException )
- {
- pException->Delete();
- } // catch( CException * pException )
- catch( ... )
- {
- } // catch( ... )
- _file.Detach();
- m_bPmSynchronizeSinkIsSynchronizing = false;
- }
- CExtResourceManager::CExtResourceMemoryBuffer::CExtResourceMemoryBuffer()
- : m_pBuffer( NULL )
- , m_dwBufferSize( 0 )
- {
- }
- CExtResourceManager::CExtResourceMemoryBuffer::CExtResourceMemoryBuffer(
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- )
- : m_pBuffer( NULL )
- , m_dwBufferSize( 0 )
- {
- AssignFromOther( other );
- }
- CExtResourceManager::CExtResourceMemoryBuffer::~CExtResourceMemoryBuffer()
- {
- Empty();
- }
- #ifdef _DEBUG
- void CExtResourceManager::CExtResourceMemoryBuffer::Dump()
- {
- for( DWORD i = 0; i < m_dwBufferSize; i++ )
- {
- TCHAR _tchr[2] = { m_pBuffer[ i ], _T(' ') };
- afxDump << _tchr;
- afxDump.Flush();
- }
- }
- #endif // _DEBUG
- CExtResourceManager::CExtResourceMemoryBuffer &
- CExtResourceManager::CExtResourceMemoryBuffer::operator = (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- )
- {
- AssignFromOther( other );
- return (*this);
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator ! () const
- {
- return (! IsEmpty() );
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator == (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) == 0 ) ? true : false;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator != (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) != 0 ) ? true : false;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator < (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) < 0 ) ? true : false;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator <= (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) <= 0 ) ? true : false;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator > (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) > 0 ) ? true : false;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::operator >= (
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- return ( CompareWithOther( other ) >= 0 ) ? true : false;
- }
- BYTE CExtResourceManager::CExtResourceMemoryBuffer::operator [] ( DWORD dwByteIndex ) const
- {
- ASSERT( m_pBuffer != NULL && dwByteIndex < m_dwBufferSize );
- return m_pBuffer[ dwByteIndex ];
- }
- CExtResourceManager::CExtResourceMemoryBuffer::operator BYTE * ()
- {
- return m_pBuffer;
- }
- CExtResourceManager::CExtResourceMemoryBuffer::operator const BYTE * ()
- {
- return m_pBuffer;
- }
- void CExtResourceManager::CExtResourceMemoryBuffer::AssignFromOther(
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- )
- {
- if( LPVOID(this) == LPVOID(&other) )
- return;
- Empty();
- if( other.IsEmpty() )
- return;
- DWORD dwBufferSize = other.GetSize();
- if( ! Alloc( dwBufferSize, false ) )
- return;
- __EXT_MFC_MEMCPY(
- GetBuffer(),
- GetSize(),
- other.GetBuffer(),
- dwBufferSize
- );
- }
- int CExtResourceManager::CExtResourceMemoryBuffer::CompareWithOther(
- const CExtResourceManager::CExtResourceMemoryBuffer & other
- ) const
- {
- if( IsEmpty() )
- {
- if( other.IsEmpty() )
- return 0;
- return -1;
- } // if( IsEmpty() )
- else
- {
- if( other.IsEmpty() )
- return 1;
- DWORD dwSizeThis = GetSize();
- DWORD dwSizeOther = other.GetSize();
- DWORD dwCmpSize = min( dwSizeThis, dwSizeOther );
- ASSERT( dwCmpSize > 0 );
- int nCmpResult = ::memcmp( GetBuffer(), other.GetBuffer(), dwCmpSize );
- if( nCmpResult != 0 )
- return nCmpResult;
- if( dwSizeThis == dwSizeOther )
- return 0;
- if( dwSizeThis < dwSizeOther )
- return -1;
- return 1;
- } // else from if( IsEmpty() )
- }
- DWORD CExtResourceManager::CExtResourceMemoryBuffer::GetSize() const
- {
- return m_dwBufferSize;
- }
- BYTE * CExtResourceManager::CExtResourceMemoryBuffer::GetBuffer()
- {
- return m_pBuffer;
- }
- const BYTE * CExtResourceManager::CExtResourceMemoryBuffer::GetBuffer() const
- {
- return m_pBuffer;
- }
- HGLOBAL CExtResourceManager::CExtResourceMemoryBuffer::AllocGlobalBufferBuffer(
- UINT nFlags // = GPTR
- ) const
- {
- if( IsEmpty() )
- return NULL;
- HGLOBAL hGlobal = ::GlobalAlloc( nFlags, GetSize() );
- ASSERT( hGlobal != NULL );
- if( hGlobal == NULL )
- return NULL;
- LPVOID pMem = ::GlobalLock( hGlobal );
- ASSERT( pMem != NULL );
- __EXT_MFC_MEMCPY(
- pMem,
- GetSize(),
- GetBuffer(),
- GetSize()
- );
- ::GlobalUnlock( hGlobal );
- return hGlobal;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::IsEmpty() const
- {
- return (m_dwBufferSize == 0) ? true : false;
- }
- void CExtResourceManager::CExtResourceMemoryBuffer::Empty()
- {
- if( m_pBuffer != NULL )
- {
- ASSERT( m_dwBufferSize > 0 );
- ::free( m_pBuffer );
- m_pBuffer = NULL;
- m_dwBufferSize = 0;
- }
- #ifdef _DEBUG
- else
- {
- ASSERT( m_dwBufferSize == 0 );
- }
- #endif // _DEBUG
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::Alloc(
- DWORD dwBufferSize,
- bool bZeroMemory // = true
- )
- {
- ASSERT( dwBufferSize > 0 );
- if( dwBufferSize == 0 )
- return false;
- Empty();
- m_pBuffer = (BYTE *)::malloc( dwBufferSize );
- if( m_pBuffer == NULL )
- return false;
- m_dwBufferSize = dwBufferSize;
- if( bZeroMemory )
- ::memset( m_pBuffer, 0, m_dwBufferSize );
- return true;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::Load(
- HINSTANCE hModule,
- HRSRC hResource
- )
- {
- HGLOBAL hGlobal = LoadResource( hModule, hResource );
- if( hGlobal == NULL )
- return false;
- LPVOID pResourceData = LockResource( hGlobal );
- bool bRetVal = false;
- if( pResourceData != NULL )
- {
- DWORD dwSizeofResource = SizeofResource( hModule, hResource );
- if( dwSizeofResource == 0 )
- {
- Empty();
- bRetVal = true;
- } // if( dwSizeofResource == 0 )
- else if( Alloc( dwSizeofResource ) )
- {
- __EXT_MFC_MEMCPY(
- m_pBuffer,
- GetSize(),
- pResourceData,
- dwSizeofResource
- );
- bRetVal = true;
- } // else if( Alloc( dwSizeofResource ) )
- UnlockResource( hGlobal );
- } // if( pResourceData != NULL )
- FreeResource( hGlobal );
- return bRetVal;
- }
- bool CExtResourceManager::CExtResourceMemoryBuffer::FindAndLoad(
- HINSTANCE hModule,
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired
- )
- {
- Empty();
- HRSRC hResource =
- ::FindResourceEx(
- hModule,
- strResourceType,
- MAKEINTRESOURCE(nResourceName),
- nLangIdDesired
- );
- if( hResource == NULL )
- return false;
- return Load( hModule, hResource );
- }
- CExtResourceManager::CExtResourceManager(
- bool bAllowCustomLang, // = false
- WORD nLangIdDesired, // = __EXT_MFC_LANG_ID_DEFAULT_NEUTRAL
- DWORD nLangLayout // = DWORD(-1) // if nLangLayout == DWORD(-1), get language layout from the locale information
- )
- : m_bAllowCustomLang( bAllowCustomLang )
- , m_nLangIdDesired( nLangIdDesired )
- , m_nLangLayout( nLangLayout )
- {
- }
- CExtResourceManager::~CExtResourceManager()
- {
- RscInst_RemoveAll();
- }
- void CExtResourceManager::SerializeSynchronizationData( CArchive & ar )
- {
- ASSERT_VALID( this );
- DWORD dwBasicData[3];
- ::memset( &dwBasicData, 0, sizeof(dwBasicData) );
- if( ar.IsStoring() )
- {
- if( IsCustomLangAllowed() )
- dwBasicData[0] |= 0x00000001;
- dwBasicData[1] = (DWORD)GetLangIdDesired();
- ar.Write( &dwBasicData, sizeof(dwBasicData) );
- } // if( ar.IsStoring() )
- else
- {
- ar.Read( &dwBasicData, sizeof(dwBasicData) );
- bool bAllow = ( ( dwBasicData[0] & 0x00000001 ) != 0 ) ? true : false;
- AllowCustomLang( bAllow );
- SetLangIdDesired( (WORD)dwBasicData[1] );
- } // else from if( ar.IsStoring() )
- }
- DLGTEMPLATE * CExtResourceManager::OnAdjustDialogTemplate(
- const DLGTEMPLATE * lpDialogTemplate,
- CObject * pHelperSrc,
- bool bWizard, // = false
- LPARAM lParam // = 0L
- )
- {
- ASSERT_VALID( this );
- ASSERT( lpDialogTemplate != NULL );
- lpDialogTemplate;
- pHelperSrc;
- bWizard;
- lParam;
- return NULL;
- }
- bool CExtResourceManager::IsCustomLangAllowed() const
- {
- ASSERT_VALID( this );
- return m_bAllowCustomLang;
- }
- void CExtResourceManager::AllowCustomLang(
- bool bAllow // = true
- )
- {
- ASSERT_VALID( this );
- m_bAllowCustomLang = bAllow;
- }
- WORD CExtResourceManager::GetLangIdDesired() const
- {
- ASSERT_VALID( this );
- return m_nLangIdDesired;
- }
- void CExtResourceManager::SetLangIdDesired(
- WORD nLangIdDesired
- )
- {
- ASSERT_VALID( this );
- m_nLangIdDesired = nLangIdDesired;
- }
- WORD CExtResourceManager::GetLangIdNeutral() const
- {
- ASSERT_VALID( this );
- return g_nLangIdNeutral;
- }
- DWORD CExtResourceManager::OnQueryLangLayout() const
- {
- ASSERT_VALID( this );
- if( m_nLangLayout == DWORD(-1) )
- {
- LANGID nLangID;
- if( IsCustomLangAllowed() )
- nLangID = GetLangIdDesired();
- else
- nLangID = ::GetUserDefaultLangID();
- switch( nLangID )
- {
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_SAUDI_ARABIA ): // Arabic (Saudi Arabia)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_IRAQ ): // Arabic (Iraq)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_EGYPT ): // Arabic (Egypt)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_LIBYA ): // Arabic (Libya)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_ALGERIA ): // Arabic (Algeria)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_MOROCCO ): // Arabic (Morocco)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_TUNISIA ): // Arabic (Tunisia)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_OMAN ): // Arabic (Oman)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_YEMEN ): // Arabic (Yemen)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_SYRIA ): // Arabic (Syria)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_JORDAN ): // Arabic (Jordan)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_LEBANON ): // Arabic (Lebanon)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_KUWAIT ): // Arabic (Kuwait)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_UAE ): // Arabic (U.A.E)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_BAHRAIN ): // Arabic (Bahrain)
- case MAKELANGID( LANG_ARABIC, SUBLANG_ARABIC_QATAR ): // Arabic (Qatar)
- case MAKELANGID( LANG_HEBREW, SUBLANG_DEFAULT ): // Israel
- case MAKELANGID( LANG_URDU, SUBLANG_URDU_PAKISTAN ): // Urdu (Pakistan)
- case MAKELANGID( LANG_URDU, SUBLANG_URDU_INDIA ): // Urdu (India)
- case MAKELANGID( LANG_FARSI, SUBLANG_DEFAULT ): // Iran (Persian)
- case MAKELANGID( LANG_PUNJABI, SUBLANG_DEFAULT ): // India
- case MAKELANGID( LANG_KASHMIRI, SUBLANG_DEFAULT ): // Kashmiri
- case MAKELANGID( LANG_KASHMIRI, SUBLANG_KASHMIRI_INDIA ): // Kashmiri (India)
- case MAKELANGID( LANG_SINDHI, SUBLANG_DEFAULT ):
- return LAYOUT_RTL;
- default:
- return LAYOUT_LTR;
- } // switch( nLangID )
- } // if( m_nLangLayout == DWORD(-1) )
- else
- return m_nLangLayout;
- }
- DWORD CExtResourceManager::GetLangLayout() const
- {
- ASSERT_VALID( this );
- return m_nLangLayout;
- }
- DWORD CExtResourceManager::SetLangLayout(
- DWORD nLangLayout // = DWORD(-1)
- )
- {
- ASSERT_VALID( this );
- ASSERT(
- nLangLayout == DWORD(-1)
- || nLangLayout == LAYOUT_LTR
- || nLangLayout == LAYOUT_RTL
- || nLangLayout == (LAYOUT_RTL|LAYOUT_BITMAPORIENTATIONPRESERVED)
- );
- DWORD nLangLayoutOld = m_nLangLayout;
- m_nLangLayout = nLangLayout;
- return nLangLayoutOld;
- }
- int CExtResourceManager::GetLocaleInfo(
- LCTYPE LCType,
- __EXT_MFC_SAFE_LPTSTR lpLCData,
- int cchData
- )
- {
- ASSERT_VALID( this );
- int nRetVal = 0;
- if( IsCustomLangAllowed() )
- {
- nRetVal =
- ::GetLocaleInfo(
- ( MAKELCID( GetLangIdDesired(), SORT_DEFAULT ) ),
- LCType,
- lpLCData,
- cchData
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetLocaleInfo(
- ( MAKELCID( GetLangIdNeutral(), SORT_DEFAULT ) ),
- LCType,
- lpLCData,
- cchData
- );
- if( nRetVal != 0 )
- return nRetVal;
- } // if( IsCustomLangAllowed() )
- nRetVal =
- ::GetLocaleInfo(
- LOCALE_USER_DEFAULT,
- LCType,
- lpLCData,
- cchData
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetLocaleInfo(
- LOCALE_SYSTEM_DEFAULT,
- LCType,
- lpLCData,
- cchData
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetLocaleInfo(
- LOCALE_NEUTRAL,
- LCType,
- lpLCData,
- cchData
- );
- return nRetVal;
- }
- INT CExtResourceManager::GetTimeFormat(
- DWORD dwFlags,
- const SYSTEMTIME * lpTime,
- __EXT_MFC_SAFE_LPCTSTR lpFormat,
- __EXT_MFC_SAFE_LPTSTR lpTimeStr,
- INT cchTime
- )
- {
- ASSERT_VALID( this );
- INT nRetVal = 0;
- if( IsCustomLangAllowed() )
- {
- nRetVal =
- ::GetTimeFormat(
- ( MAKELCID( GetLangIdDesired(), SORT_DEFAULT ) ),
- dwFlags,
- lpTime,
- lpFormat,
- lpTimeStr,
- cchTime
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetTimeFormat(
- ( MAKELCID( GetLangIdNeutral(), SORT_DEFAULT ) ),
- dwFlags,
- lpTime,
- lpFormat,
- lpTimeStr,
- cchTime
- );
- if( nRetVal != 0 )
- return nRetVal;
- } // if( IsCustomLangAllowed() )
- nRetVal =
- ::GetTimeFormat(
- LOCALE_USER_DEFAULT,
- dwFlags,
- lpTime,
- lpFormat,
- lpTimeStr,
- cchTime
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetTimeFormat(
- LOCALE_SYSTEM_DEFAULT,
- dwFlags,
- lpTime,
- lpFormat,
- lpTimeStr,
- cchTime
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetTimeFormat(
- LOCALE_NEUTRAL,
- dwFlags,
- lpTime,
- lpFormat,
- lpTimeStr,
- cchTime
- );
- return nRetVal;
- }
- INT CExtResourceManager::GetDateFormat(
- DWORD dwFlags,
- const SYSTEMTIME * lpDate,
- __EXT_MFC_SAFE_LPCTSTR lpFormat,
- __EXT_MFC_SAFE_LPTSTR lpDateStr,
- INT cchDate
- )
- {
- ASSERT_VALID( this );
- INT nRetVal = 0;
- if( IsCustomLangAllowed() )
- {
- nRetVal =
- ::GetDateFormat(
- ( MAKELCID( GetLangIdDesired(), SORT_DEFAULT ) ),
- dwFlags,
- lpDate,
- lpFormat,
- lpDateStr,
- cchDate
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetDateFormat(
- ( MAKELCID( GetLangIdNeutral(), SORT_DEFAULT ) ),
- dwFlags,
- lpDate,
- lpFormat,
- lpDateStr,
- cchDate
- );
- if( nRetVal != 0 )
- return nRetVal;
- } // if( IsCustomLangAllowed() )
- nRetVal =
- ::GetDateFormat(
- LOCALE_USER_DEFAULT,
- dwFlags,
- lpDate,
- lpFormat,
- lpDateStr,
- cchDate
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetDateFormat(
- LOCALE_SYSTEM_DEFAULT,
- dwFlags,
- lpDate,
- lpFormat,
- lpDateStr,
- cchDate
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetDateFormat(
- LOCALE_NEUTRAL,
- dwFlags,
- lpDate,
- lpFormat,
- lpDateStr,
- cchDate
- );
- return nRetVal;
- }
- INT CExtResourceManager::GetNumberFormat(
- DWORD dwFlags,
- __EXT_MFC_SAFE_LPCTSTR lpValue,
- const NUMBERFMT * lpFormat,
- __EXT_MFC_SAFE_LPTSTR lpNumberStr,
- INT cchNumber
- )
- {
- ASSERT_VALID( this );
- INT nRetVal = 0;
- if( IsCustomLangAllowed() )
- {
- nRetVal =
- ::GetNumberFormat(
- ( MAKELCID( GetLangIdDesired(), SORT_DEFAULT ) ),
- dwFlags,
- lpValue,
- lpFormat,
- lpNumberStr,
- cchNumber
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetNumberFormat(
- ( MAKELCID( GetLangIdNeutral(), SORT_DEFAULT ) ),
- dwFlags,
- lpValue,
- lpFormat,
- lpNumberStr,
- cchNumber
- );
- if( nRetVal != 0 )
- return nRetVal;
- } // if( IsCustomLangAllowed() )
- nRetVal =
- ::GetNumberFormat(
- LOCALE_USER_DEFAULT,
- dwFlags,
- lpValue,
- lpFormat,
- lpNumberStr,
- cchNumber
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetNumberFormat(
- LOCALE_SYSTEM_DEFAULT,
- dwFlags,
- lpValue,
- lpFormat,
- lpNumberStr,
- cchNumber
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetNumberFormat(
- LOCALE_NEUTRAL,
- dwFlags,
- lpValue,
- lpFormat,
- lpNumberStr,
- cchNumber
- );
- return nRetVal;
- }
- INT CExtResourceManager::GetCurrencyFormat(
- DWORD dwFlags,
- __EXT_MFC_SAFE_LPCTSTR lpValue,
- const CURRENCYFMT * lpFormat,
- __EXT_MFC_SAFE_LPTSTR lpCurrencyStr,
- INT cchCurrency
- )
- {
- ASSERT_VALID( this );
- INT nRetVal = 0;
- if( IsCustomLangAllowed() )
- {
- nRetVal =
- ::GetCurrencyFormat(
- ( MAKELCID( GetLangIdDesired(), SORT_DEFAULT ) ),
- dwFlags,
- lpValue,
- lpFormat,
- lpCurrencyStr,
- cchCurrency
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetCurrencyFormat(
- ( MAKELCID( GetLangIdNeutral(), SORT_DEFAULT ) ),
- dwFlags,
- lpValue,
- lpFormat,
- lpCurrencyStr,
- cchCurrency
- );
- if( nRetVal != 0 )
- return nRetVal;
- } // if( IsCustomLangAllowed() )
- nRetVal =
- ::GetCurrencyFormat(
- LOCALE_USER_DEFAULT,
- dwFlags,
- lpValue,
- lpFormat,
- lpCurrencyStr,
- cchCurrency
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetCurrencyFormat(
- LOCALE_SYSTEM_DEFAULT,
- dwFlags,
- lpValue,
- lpFormat,
- lpCurrencyStr,
- cchCurrency
- );
- if( nRetVal != 0 )
- return nRetVal;
- nRetVal =
- ::GetCurrencyFormat(
- LOCALE_NEUTRAL,
- dwFlags,
- lpValue,
- lpFormat,
- lpCurrencyStr,
- cchCurrency
- );
- return nRetVal;
- }
- //////////////////////////////////////////////////////////////////////////
- // CExtResourceManager::RscInstEntry
- CExtResourceManager::RscInstEntry::RscInstEntry(
- HINSTANCE hInstance,
- bool bFreeInstance // = true
- )
- : m_hInstance( hInstance )
- , m_bFreeInstance( bFreeInstance )
- {
- }
- CExtResourceManager::RscInstEntry::RscInstEntry(
- __EXT_MFC_SAFE_LPCTSTR strModulePathToLoad,
- bool bFreeInstance // = true
- )
- : m_hInstance( NULL )
- , m_bFreeInstance( bFreeInstance )
- {
- if( LPCTSTR(strModulePathToLoad) != NULL
- && INT(_tcslen(LPCTSTR(strModulePathToLoad))) > 0
- )
- {
- m_hInstance = ::LoadLibrary( strModulePathToLoad );
- //ASSERT( m_hInstance != NULL );
- }
- }
- CExtResourceManager::RscInstEntry::~RscInstEntry()
- {
- if( m_hInstance != NULL )
- {
- if( m_bFreeInstance )
- ::FreeLibrary( m_hInstance );
- m_hInstance = NULL;
- }
- }
- HINSTANCE CExtResourceManager::RscInstEntry::GetInstance() const
- {
- return m_hInstance;
- }
- bool CExtResourceManager::RscInstEntry::IsEmpty() const
- {
- return ( GetInstance() == NULL ) ? true : false;
- }
- INT CExtResourceManager::RscInst_GetCount() const
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- return INT( m_arrRscInst.GetSize() );
- }
- bool CExtResourceManager::RscInst_Insert(
- HINSTANCE hInstance,
- bool bFreeInstance, // = true
- INT nInsertPos // = -1 // -1 - Append
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( hInstance == NULL )
- return false;
- RscInstEntry * pRscInstEntry =
- new RscInstEntry( hInstance, bFreeInstance );
- bool bRetVal =
- RscInst_Insert(
- pRscInstEntry,
- nInsertPos
- );
- if( ! bRetVal )
- delete pRscInstEntry;
- return bRetVal;
- }
- bool CExtResourceManager::RscInst_Insert(
- __EXT_MFC_SAFE_LPCTSTR strModulePathToLoad,
- bool bFreeInstance, // = true
- INT nInsertPos // = -1 // -1 - Append
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( LPCTSTR(strModulePathToLoad) == NULL
- || INT(_tcslen(LPCTSTR(strModulePathToLoad))) == 0
- )
- return false;
- RscInstEntry * pRscInstEntry =
- new RscInstEntry( strModulePathToLoad, bFreeInstance );
- bool bRetVal =
- RscInst_Insert(
- pRscInstEntry,
- nInsertPos
- );
- if( ! bRetVal )
- delete pRscInstEntry;
- return bRetVal;
- }
- bool CExtResourceManager::RscInst_Insert(
- RscInstEntry * pRscInstEntry,
- INT nInsertPos // = -1 // -1 - Append
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( pRscInstEntry == NULL
- || pRscInstEntry->IsEmpty()
- )
- return false;
- INT nCount = INT( m_arrRscInst.GetSize() );
- if( nInsertPos < 0 || nInsertPos > nCount )
- nInsertPos = nCount;
- m_arrRscInst.InsertAt( nInsertPos, pRscInstEntry );
- return true;
- }
- bool CExtResourceManager::RscInst_RemoveAt(
- INT nRemovePos
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( nRemovePos < 0 || nRemovePos >= INT( m_arrRscInst.GetSize() ) )
- return false;
- RscInstEntry * pRscInstEntry =
- m_arrRscInst[ nRemovePos ];
- if( pRscInstEntry != NULL )
- delete pRscInstEntry;
- m_arrRscInst.RemoveAt( nRemovePos );
- return true;
- }
- void CExtResourceManager::RscInst_RemoveAll()
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- INT nIndex, nCount = INT( m_arrRscInst.GetSize() );
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- RscInstEntry * pRscInstEntry =
- m_arrRscInst[ nIndex ];
- if( pRscInstEntry != NULL )
- delete pRscInstEntry;
- } // for( nIndex = 0; nIndex < nCount; nIndex++ )
- m_arrRscInst.RemoveAll();
- }
- const CExtResourceManager::RscInstEntry * CExtResourceManager::RscInst_GetAt(
- INT nPos
- ) const
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- return
- ( const_cast < CExtResourceManager * > ( this ) )
- -> RscInst_GetAt( nPos );
- }
- CExtResourceManager::RscInstEntry * CExtResourceManager::RscInst_GetAt(
- INT nPos
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( nPos < 0 || nPos >= INT( m_arrRscInst.GetSize() ) )
- return NULL;
- return m_arrRscInst.GetAt( nPos );
- }
- bool CExtResourceManager::RscInst_LoadResourceBufferSingleLanguage(
- CExtResourceMemoryBuffer & bufferOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = NULL;
- INT nIndex, nCount = RscInst_GetCount();
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- RscInstEntry * pRscInstEntry = RscInst_GetAt( nIndex );
- if( pRscInstEntry == NULL
- || pRscInstEntry->IsEmpty()
- )
- continue;
- HINSTANCE hInstance = pRscInstEntry->GetInstance();
- if( bufferOut.FindAndLoad(
- hInstance,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstance;
- return true;
- }
- } // for( nIndex = 0; nIndex < nCount; nIndex++ )
- return false;
- }
- HINSTANCE CExtResourceManager::RscInst_FindResourceHandleSingleLanguage(
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD * p_wLangIdOut, // = NULL
- HRSRC * p_hResourceOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = NULL;
- INT nIndex, nCount = RscInst_GetCount();
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- RscInstEntry * pRscInstEntry = RscInst_GetAt( nIndex );
- if( pRscInstEntry == NULL
- || pRscInstEntry->IsEmpty()
- )
- continue;
- HINSTANCE hInstance = pRscInstEntry->GetInstance();
- HRSRC hResource =
- ::FindResourceEx(
- hInstance,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInstance;
- } // if( hResource != NULL )
- } // for( nIndex = 0; nIndex < nCount; nIndex++ )
- return NULL;
- }
- __EXT_MFC_SAFE_LPCTSTR CExtResourceManager::DesiredFont_GetFaceName() const
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( m_strHelperDesiredFontFaceName.IsEmpty() )
- return LPCTSTR(NULL);
- return LPCTSTR(m_strHelperDesiredFontFaceName);
- }
- void CExtResourceManager::DesiredFont_SetFaceName(
- __EXT_MFC_SAFE_LPCTSTR strDesiredFontFaceName // = NULL // NULL = no font replacement
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( LPCTSTR(strDesiredFontFaceName) == NULL
- || _tcslen( LPCTSTR(strDesiredFontFaceName) ) == 0
- )
- {
- m_strHelperDesiredFontFaceName.Empty();
- m_helperFontDesired.DeleteObject();
- return;
- }
- if( m_strHelperDesiredFontFaceName == LPCTSTR(strDesiredFontFaceName) )
- return;
- m_strHelperDesiredFontFaceName = strDesiredFontFaceName;
- m_helperFontDesired.DeleteObject(); // will be re-created on the fly if needed
- }
- HFONT CExtResourceManager::DesiredFont_GetHandle() const
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- LPCTSTR strDesiredFontFaceName = DesiredFont_GetFaceName();
- if( strDesiredFontFaceName == NULL
- || INT(_tcslen(strDesiredFontFaceName)) == 0
- )
- return NULL;
- HFONT hFont = (HFONT)m_helperFontDesired.GetSafeHandle();
- if( hFont != NULL )
- return hFont;
- LOGFONT _lf;
- ::memset( &_lf, 0, sizeof(LOGFONT) );
- g_PaintManager->m_FontNormal.GetLogFont( &_lf );
- __EXT_MFC_STRCPY( _lf.lfFaceName, LF_FACESIZE, strDesiredFontFaceName );
- m_helperFontDesired.CreateFontIndirect( &_lf );
- hFont = (HFONT)m_helperFontDesired.GetSafeHandle();
- return hFont;
- }
- void CExtResourceManager::DesiredFont_ChangeWindow(
- HWND hWnd,
- INT nNestedDepth, // = 0 // 0 - only hWnd, 1 - +all its children, 2 - ...
- bool bRedrawWindow // = true
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( nNestedDepth >= 0 );
- if( hWnd == NULL || (! ::IsWindow( hWnd ) ) )
- return;
- HFONT hFont = DesiredFont_GetHandle();
- if( hFont == NULL )
- return;
- ::SendMessage(
- hWnd,
- WM_SETFONT,
- (WPARAM)hFont,
- bRedrawWindow ? (!0) : 0
- );
- if( nNestedDepth == 0 )
- return;
- nNestedDepth --;
- hWnd = ::GetWindow( hWnd, GW_CHILD );
- for( ; hWnd != NULL; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ) )
- DesiredFont_ChangeWindow(
- hWnd,
- nNestedDepth,
- bRedrawWindow
- );
- }
- HINSTANCE CExtResourceManager::FindResourceHandleSingleLanguage(
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD * p_wLangIdOut, // = NULL
- HRSRC * p_hResourceOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = NULL;
- if( ! IsCustomLangAllowed() )
- {
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hInst == NULL )
- return NULL;
- HRSRC hResource =
- ::FindResource(
- hInst,
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hResource == NULL )
- return NULL;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInst;
- } // if( ! IsCustomLangAllowed() )
- HINSTANCE hInstance =
- RscInst_FindResourceHandleSingleLanguage(
- strResourceType,
- nResourceName,
- nLangIdDesired,
- p_wLangIdOut,
- p_hResourceOut
- );
- if( hInstance != NULL )
- return hInstance;
- AFX_MODULE_STATE * pModuleState = ::AfxGetModuleState();
- if( ! pModuleState->m_bSystem )
- {
- hInstance = AfxGetResourceHandle();
- HRSRC hResource =
- ::FindResourceEx(
- hInstance,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInstance;
- } // if( hResource != NULL )
- } // if( ! pModuleState->m_bSystem )
- #if (!defined __EXT_PROFUIS_STATIC_LINK)
- AfxLockGlobals( CRIT_DYNLINKLIST );
- CDynLinkLibrary * pDLL = NULL;
- for( pDLL = pModuleState->m_libraryList;
- pDLL != NULL;
- pDLL = pDLL->m_pNextDLL
- )
- {
- if( (! pDLL->m_bSystem)
- && pDLL->m_hResource != NULL
- )
- {
- HRSRC hResource =
- ::FindResourceEx(
- pDLL->m_hResource,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- AfxUnlockGlobals(CRIT_DYNLINKLIST);
- return pDLL->m_hResource;
- } // if( hResource != NULL )
- }
- }
- AfxUnlockGlobals( CRIT_DYNLINKLIST );
- hInstance = pModuleState->m_appLangDLL;
- if( hInstance != NULL )
- {
- HRSRC hResource =
- ::FindResourceEx(
- hInstance,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInstance;
- } // if( hResource != NULL )
- }
- #endif // (!defined __EXT_PROFUIS_STATIC_LINK)
- if( pModuleState->m_bSystem )
- {
- hInstance = AfxGetResourceHandle();
- HRSRC hResource =
- ::FindResourceEx(
- hInstance,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInstance;
- } // if( hResource != NULL )
- } // if( pModuleState->m_bSystem )
- #if (!defined __EXT_PROFUIS_STATIC_LINK)
- AfxLockGlobals(CRIT_DYNLINKLIST);
- for( pDLL = pModuleState->m_libraryList;
- pDLL != NULL;
- pDLL = pDLL->m_pNextDLL
- )
- {
- if( pDLL->m_bSystem
- && pDLL->m_hResource != NULL
- )
- {
- HRSRC hResource =
- ::FindResourceEx(
- pDLL->m_hResource,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- AfxUnlockGlobals(CRIT_DYNLINKLIST);
- return pDLL->m_hResource;
- } // if( hResource != NULL )
- }
- }
- AfxUnlockGlobals( CRIT_DYNLINKLIST );
- #endif // (!defined __EXT_PROFUIS_STATIC_LINK)
- hInstance = AfxGetResourceHandle();
- HRSRC hResource =
- ::FindResourceEx(
- hInstance,
- LPCTSTR(strResourceType),
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- nLangIdDesired
- );
- if( hResource != NULL )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInstance;
- } // if( hResource != NULL )
- return NULL;
- }
- HINSTANCE CExtResourceManager::FindResourceHandleEx(
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HRSRC * p_hResourceOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = NULL;
- if( ! IsCustomLangAllowed() )
- {
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hInst == NULL )
- return NULL;
- HRSRC hResource =
- ::FindResource(
- hInst,
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hResource == NULL )
- return NULL;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInst;
- } // if( ! IsCustomLangAllowed() )
- HINSTANCE hInst =
- FindResourceHandleSingleLanguage(
- strResourceType,
- nResourceName,
- nLangIdDesired,
- p_wLangIdOut,
- p_hResourceOut
- );
- if( hInst != NULL )
- return hInst;
- if( nLangIdDesired == nLangIdNeutral )
- return NULL;
- hInst =
- FindResourceHandleSingleLanguage(
- strResourceType,
- nResourceName,
- nLangIdNeutral,
- p_wLangIdOut,
- p_hResourceOut
- );
- return hInst;
- }
- HINSTANCE CExtResourceManager::FindResourceHandle(
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HRSRC * p_hResourceOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = NULL;
- if( ! IsCustomLangAllowed() )
- {
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hInst == NULL )
- return NULL;
- HRSRC hResource =
- ::FindResource(
- hInst,
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- LPCTSTR(strResourceType)
- );
- if( hResource == NULL )
- return NULL;
- if( p_hResourceOut != NULL )
- (*p_hResourceOut) = hResource;
- return hInst;
- } // if( ! IsCustomLangAllowed() )
- return
- FindResourceHandleEx(
- strResourceType,
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hResourceOut
- );
- }
- bool CExtResourceManager::LoadResourceBufferSingleLanguage(
- CExtResourceManager::CExtResourceMemoryBuffer & bufferOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- strResourceType
- );
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInst;
- if( hInst == NULL )
- return false;
- bufferOut.Empty();
- return
- bufferOut.FindAndLoad(
- hInst,
- strResourceType,
- nResourceName,
- MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
- );
- } // if( ! IsCustomLangAllowed() )
- ASSERT( strResourceType != NULL );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = NULL;
- if( RscInst_LoadResourceBufferSingleLanguage(
- bufferOut,
- strResourceType,
- nResourceName,
- nLangIdDesired,
- p_wLangIdOut = NULL,
- p_hInstOut
- )
- )
- return true;
- HINSTANCE hInstance = NULL;
- AFX_MODULE_STATE * pModuleState = ::AfxGetModuleState();
- if( ! pModuleState->m_bSystem )
- {
- hInstance = AfxGetResourceHandle();
- if( bufferOut.FindAndLoad(
- hInstance,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstance;
- return true;
- }
- } // if( ! pModuleState->m_bSystem )
- #if (!defined __EXT_PROFUIS_STATIC_LINK)
- AfxLockGlobals( CRIT_DYNLINKLIST );
- CDynLinkLibrary * pDLL = NULL;
- for( pDLL = pModuleState->m_libraryList;
- pDLL != NULL;
- pDLL = pDLL->m_pNextDLL
- )
- {
- if( (! pDLL->m_bSystem)
- && pDLL->m_hResource != NULL
- )
- {
- if( bufferOut.FindAndLoad(
- pDLL->m_hResource,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = pDLL->m_hResource;
- AfxUnlockGlobals(CRIT_DYNLINKLIST);
- return true;
- }
- }
- }
- AfxUnlockGlobals( CRIT_DYNLINKLIST );
- hInstance = pModuleState->m_appLangDLL;
- if( hInstance != NULL )
- {
- if( bufferOut.FindAndLoad(
- hInstance,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstance;
- return true;
- }
- }
- #endif // (!defined __EXT_PROFUIS_STATIC_LINK)
- if( pModuleState->m_bSystem )
- {
- hInstance = AfxGetResourceHandle();
- if( bufferOut.FindAndLoad(
- hInstance,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstance;
- return true;
- }
- } // if( pModuleState->m_bSystem )
- #if (!defined __EXT_PROFUIS_STATIC_LINK)
- AfxLockGlobals(CRIT_DYNLINKLIST);
- for( pDLL = pModuleState->m_libraryList;
- pDLL != NULL;
- pDLL = pDLL->m_pNextDLL
- )
- {
- if( pDLL->m_bSystem
- && pDLL->m_hResource != NULL
- )
- {
- if( bufferOut.FindAndLoad(
- pDLL->m_hResource,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = pDLL->m_hResource;
- AfxUnlockGlobals(CRIT_DYNLINKLIST);
- return true;
- }
- }
- }
- AfxUnlockGlobals( CRIT_DYNLINKLIST );
- #endif // (!defined __EXT_PROFUIS_STATIC_LINK)
- hInstance = AfxGetResourceHandle();
- if( bufferOut.FindAndLoad(
- hInstance,
- strResourceType,
- nResourceName,
- nLangIdDesired
- )
- )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = nLangIdDesired;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstance;
- return true;
- }
- return false;
- }
- bool CExtResourceManager::LoadResourceBufferEx(
- CExtResourceManager::CExtResourceMemoryBuffer & bufferOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = NULL;
- if( ! IsCustomLangAllowed() )
- {
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- strResourceType
- );
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInst;
- if( hInst == NULL )
- return false;
- bufferOut.Empty();
- return
- bufferOut.FindAndLoad(
- hInst,
- strResourceType,
- nResourceName,
- MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
- );
- } // if( ! IsCustomLangAllowed() )
- if( LoadResourceBufferSingleLanguage(
- bufferOut,
- strResourceType,
- nResourceName,
- nLangIdDesired,
- p_wLangIdOut,
- p_hInstOut
- )
- )
- return true;
- if( nLangIdDesired == nLangIdNeutral )
- return false;
- return
- LoadResourceBufferSingleLanguage(
- bufferOut,
- strResourceType,
- nResourceName,
- nLangIdNeutral,
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadResourceBuffer(
- CExtResourceManager::CExtResourceMemoryBuffer & bufferOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceType,
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInst =
- ::AfxFindResourceHandle(
- LPCTSTR(__EXT_MFC_UINT_PTR(nResourceName)),
- strResourceType
- );
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInst;
- if( hInst == NULL )
- return false;
- bufferOut.Empty();
- return
- bufferOut.FindAndLoad(
- hInst,
- strResourceType,
- nResourceName,
- MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
- );
- } // if( ! IsCustomLangAllowed() )
- return
- LoadResourceBufferEx(
- bufferOut,
- strResourceType,
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadStringEx(
- CExtSafeString & strOut,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- return strOut.LoadString( nResourceName ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- strOut.Empty();
- CExtResourceMemoryBuffer bufferOut;
- if( ! LoadResourceBufferEx(
- bufferOut,
- RT_STRING,
- (nResourceName>>4)+1,
- nLangIdDesired,
- nLangIdNeutral,
- p_wLangIdOut,
- p_hInstOut
- )
- )
- {
- //ASSERT( FALSE );
- return false;
- }
- ASSERT( ! bufferOut.IsEmpty() );
- ASSERT( bufferOut.GetBuffer() > 0 );
- LPWORD pSource = (LPWORD)bufferOut.GetBuffer();
- ASSERT( pSource != NULL );
- UINT nTableEntryIdx = nResourceName&0x0F;
- for( UINT nIdx = 0; nIdx < nTableEntryIdx; nIdx++ )
- {
- WORD wStrLen = pSource[0];
- pSource += wStrLen + 1;
- } // for( UINT nIdx = 0; nIdx < nTableEntryIdx; nIdx++ )
- WORD wStrLen = pSource[0];
- if( wStrLen == 0 )
- return true;
- pSource ++;
- #if (defined _UNICODE) || ( _MFC_VER < 0x700 )
- CExtSafeString strTemp(
- reinterpret_cast < wchar_t * > ( pSource ),
- wStrLen
- );
- strOut = strTemp;
- #else
- strOut.Empty();
- if( wStrLen == 0 )
- return true;
- LPSTR pStrOut = strOut.GetBuffer( wStrLen+1 );
- if( pStrOut == NULL )
- return false;
- ::memset( pStrOut, 0, wStrLen+1 );
- int nResult =
- ::WideCharToMultiByte(
- CP_ACP,
- 0,
- reinterpret_cast < wchar_t * > ( pSource ),
- wStrLen, // -1
- pStrOut,
- wStrLen,
- NULL,
- NULL
- );
- strOut.ReleaseBuffer();
- if( nResult < 0 )
- return false;
- #endif
- return true;
- }
- bool CExtResourceManager::LoadString(
- CExtSafeString & strOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- return
- strOut.LoadString( UINT(__EXT_MFC_UINT_PTR(LPCTSTR(strResourceName))) ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadStringEx(
- strOut,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(strResourceName))),
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadString(
- CExtSafeString & strOut,
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- return strOut.LoadString( nResourceName ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadStringEx(
- strOut,
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadMenuEx(
- CMenu & menuOut,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( menuOut.GetSafeHmenu() != NULL )
- menuOut.DestroyMenu();
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- return menuOut.LoadMenu( nResourceName ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- CExtResourceMemoryBuffer bufferOut;
- if( ! LoadResourceBufferEx(
- bufferOut,
- RT_MENU,
- nResourceName,
- nLangIdDesired,
- nLangIdNeutral,
- p_wLangIdOut,
- p_hInstOut
- )
- )
- {
- //ASSERT( FALSE );
- return false;
- }
- ASSERT( ! bufferOut.IsEmpty() );
- ASSERT( bufferOut.GetBuffer() > 0 );
- LPMENUTEMPLATE pTemplate = LPMENUTEMPLATE( bufferOut.GetBuffer() );
- HMENU hMenu = ::LoadMenuIndirect( pTemplate );
- if( hMenu == NULL )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- menuOut.Attach( hMenu );
- return true;
- }
- bool CExtResourceManager::LoadMenu(
- CMenu & menuOut,
- __EXT_MFC_SAFE_LPCTSTR strResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- if( menuOut.GetSafeHmenu() != NULL )
- menuOut.DestroyMenu();
- return menuOut.LoadMenu( strResourceName ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadMenuEx(
- menuOut,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(strResourceName))),
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadMenu(
- CMenu & menuOut,
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- if( p_hInstOut != NULL )
- (*p_hInstOut) = ::AfxGetResourceHandle();
- if( menuOut.GetSafeHmenu() != NULL )
- menuOut.DestroyMenu();
- return menuOut.LoadMenu( nResourceName ) ? true : false;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadMenuEx(
- menuOut,
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- HACCEL CExtResourceManager::LoadAcceleratorsEx(
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- MAKEINTRESOURCE(nResourceName),
- RT_ACCELERATOR
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- HACCEL hAccel =
- ::LoadAccelerators(
- hInstResource,
- MAKEINTRESOURCE(nResourceName)
- );
- return hAccel;
- } // if( ! IsCustomLangAllowed() )
- CExtResourceMemoryBuffer bufferOut;
- if( ! LoadResourceBufferEx(
- bufferOut,
- RT_ACCELERATOR,
- nResourceName,
- nLangIdDesired,
- nLangIdNeutral,
- p_wLangIdOut,
- p_hInstOut
- )
- )
- {
- //ASSERT( FALSE );
- return NULL;
- }
- ASSERT( ! bufferOut.IsEmpty() );
- ASSERT( bufferOut.GetBuffer() > 0 );
- struct res_accel_t
- {
- WORD fVirt;
- WORD key;
- DWORD cmd;
- };
- int i, nCount = bufferOut.GetSize() / sizeof( res_accel_t );
- ASSERT( nCount > 0 );
- CExtResourceMemoryBuffer bufferTmp;
- bufferTmp.Alloc( nCount * sizeof(ACCEL) );
- res_accel_t * pResourceData = (res_accel_t *)( bufferOut.GetBuffer() );
- LPACCEL pTemplate = LPACCEL( bufferTmp.GetBuffer() );
- for( i = 0; i < nCount; i++ )
- {
- pTemplate[i].fVirt = (BYTE)pResourceData[i].fVirt;
- pTemplate[i].key = pResourceData[i].key;
- pTemplate[i].cmd = (WORD)pResourceData[i].cmd;
- } // for( i = 0; i < nCount; i++ )
- HACCEL hAccel =
- ::CreateAcceleratorTable(
- pTemplate,
- nCount
- );
- return hAccel;
- }
- HACCEL CExtResourceManager::LoadAccelerators(
- __EXT_MFC_SAFE_LPCTSTR strResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- strResourceName,
- RT_ACCELERATOR
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- HACCEL hAccel =
- ::LoadAccelerators(
- hInstResource,
- strResourceName
- );
- return hAccel;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadAcceleratorsEx(
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(strResourceName))),
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- HACCEL CExtResourceManager::LoadAccelerators(
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- MAKEINTRESOURCE(nResourceName),
- RT_ACCELERATOR
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- HACCEL hAccel =
- ::LoadAccelerators(
- hInstResource,
- MAKEINTRESOURCE(nResourceName)
- );
- return hAccel;
- } // if( ! IsCustomLangAllowed() )
- return
- LoadAcceleratorsEx(
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadBitmapEx(
- CExtBitmap & _bitmap,
- UINT nResourceName,
- WORD nLangIdDesired,
- WORD nLangIdNeutral, // = CExtResourceManager::g_nLangIdNeutral
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- _bitmap.Empty();
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- MAKEINTRESOURCE(nResourceName),
- RT_BITMAP
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- // HBITMAP hBitmap =
- // ::LoadBitmap(
- // hInstResource,
- // MAKEINTRESOURCE(nResourceName)
- // );
- // if( hBitmap == NULL )
- // return false;
- // _bitmap.FromBitmap( hBitmap );
- // ::DeleteObject( hBitmap );
- _bitmap.LoadBMP_Resource(
- MAKEINTRESOURCE(nResourceName),
- RT_BITMAP,
- hInstResource
- );
- return ( ! _bitmap.IsEmpty() );
- } // if( ! IsCustomLangAllowed() )
- HRSRC hResource = NULL;
- HINSTANCE hInst =
- FindResourceHandleEx(
- RT_BITMAP,
- nResourceName,
- nLangIdDesired,
- nLangIdNeutral,
- p_wLangIdOut,
- &hResource
- );
- if( hInst == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInst;
- ASSERT( hResource != NULL );
- _bitmap.LoadBMP_Resource(
- hInst,
- hResource
- );
- return ( ! _bitmap.IsEmpty() );
- }
- bool CExtResourceManager::LoadBitmap(
- CExtBitmap & _bitmap,
- __EXT_MFC_SAFE_LPCTSTR strResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- _bitmap.Empty();
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- strResourceName,
- RT_BITMAP
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- // HBITMAP hBitmap =
- // ::LoadBitmap(
- // hInstResource,
- // strResourceName
- // );
- // if( hBitmap == NULL )
- // return false;
- // _bitmap.FromBitmap( hBitmap );
- // ::DeleteObject( hBitmap );
- _bitmap.LoadBMP_Resource(
- strResourceName,
- RT_BITMAP,
- hInstResource
- );
- return ( ! _bitmap.IsEmpty() );
- } // if( ! IsCustomLangAllowed() )
- return
- LoadBitmapEx(
- _bitmap,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(strResourceName))),
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- bool CExtResourceManager::LoadBitmap(
- CExtBitmap & _bitmap,
- UINT nResourceName,
- WORD * p_wLangIdOut, // = NULL
- HINSTANCE * p_hInstOut // = NULL
- )
- {
- ASSERT_VALID( this );
- _bitmap.Empty();
- if( ! IsCustomLangAllowed() )
- {
- __PROF_UIS_MANAGE_STATE;
- if( p_wLangIdOut != NULL )
- (*p_wLangIdOut) = GetLangIdNeutral();
- HINSTANCE hInstResource =
- ::AfxFindResourceHandle(
- MAKEINTRESOURCE(nResourceName),
- RT_BITMAP
- );
- if( hInstResource == NULL )
- return NULL;
- if( p_hInstOut != NULL )
- (*p_hInstOut) = hInstResource;
- // HBITMAP hBitmap =
- // ::LoadBitmap(
- // hInstResource,
- // MAKEINTRESOURCE(nResourceName)
- // );
- // if( hBitmap == NULL )
- // return false;
- // _bitmap.FromBitmap( hBitmap );
- // ::DeleteObject( hBitmap );
- _bitmap.LoadBMP_Resource(
- MAKEINTRESOURCE(nResourceName),
- RT_BITMAP,
- hInstResource
- );
- return ( ! _bitmap.IsEmpty() );
- } // if( ! IsCustomLangAllowed() )
- return
- LoadBitmapEx(
- _bitmap,
- nResourceName,
- GetLangIdDesired(),
- GetLangIdNeutral(),
- p_wLangIdOut,
- p_hInstOut
- );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtResDlg window
- IMPLEMENT_DYNCREATE( CExtResDlg, CDialog )
- IMPLEMENT_CExtPmBridge_MEMBERS( CExtResDlg );
- CExtResDlg::CExtResDlg()
- : m_lpszTemplateName_SAVED( NULL )
- , m_sizeDLUCVT( 0, 0 )
- {
- PmBridge_Install();
- }
- CExtResDlg::CExtResDlg(
- UINT nIDTemplate,
- CWnd * pParentWnd // = NULL
- )
- : CDialog( nIDTemplate, pParentWnd )
- , m_lpszTemplateName_SAVED( NULL )
- , m_sizeDLUCVT( 0, 0 )
- {
- PmBridge_Install();
- }
- CExtResDlg::CExtResDlg(
- __EXT_MFC_SAFE_LPCTSTR lpszTemplateName,
- CWnd * pParentWnd // = NULL
- )
- : CDialog( lpszTemplateName, pParentWnd )
- , m_lpszTemplateName_SAVED( NULL )
- , m_sizeDLUCVT( 0, 0 )
- {
- PmBridge_Install();
- }
- CExtResDlg::~CExtResDlg()
- {
- PmBridge_Uninstall();
- }
- int CExtResDlg::_DLU2PxHorz( int nX )
- {
- ASSERT_VALID( this );
- if( m_sizeDLUCVT.cx == 0 )
- {
- RECT rc = { 0, 0, __EXT_MFC_DLU_BASE_CVT_CX, __EXT_MFC_DLU_BASE_CVT_CY };
- MapDialogRect( &rc );
- m_sizeDLUCVT.cx = rc.right - rc.left;
- m_sizeDLUCVT.cy = rc.bottom - rc.top;
- }
- return ::MulDiv( nX, m_sizeDLUCVT.cx, __EXT_MFC_DLU_BASE_CVT_CX );
- }
- int CExtResDlg::_DLU2PxVert( int nY )
- {
- ASSERT_VALID( this );
- if( m_sizeDLUCVT.cy == 0 )
- {
- RECT rc = { 0, 0, __EXT_MFC_DLU_BASE_CVT_CX, __EXT_MFC_DLU_BASE_CVT_CY };
- MapDialogRect( &rc );
- m_sizeDLUCVT.cx = rc.right - rc.left;
- m_sizeDLUCVT.cy = rc.bottom - rc.top;
- }
- return ::MulDiv( nY, m_sizeDLUCVT.cy, __EXT_MFC_DLU_BASE_CVT_CY );
- }
- void CExtResDlg::_DLU2Px( POINT & _pt )
- {
- ASSERT_VALID( this );
- _pt.x = _DLU2PxHorz( _pt.x );
- _pt.y = _DLU2PxVert( _pt.y );
- }
- void CExtResDlg::_DLU2Px( SIZE & _size )
- {
- ASSERT_VALID( this );
- _size.cx = _DLU2PxHorz( _size.cx );
- _size.cy = _DLU2PxVert( _size.cy );
- }
- void CExtResDlg::_DLU2Px( RECT & _rc )
- {
- ASSERT_VALID( this );
- _rc.left = _DLU2PxHorz( _rc.left );
- _rc.top = _DLU2PxVert( _rc.top );
- _rc.right = _DLU2PxHorz( _rc.right );
- _rc.bottom = _DLU2PxVert( _rc.bottom );
- }
- __EXT_MFC_SAFE_LPCTSTR CExtResDlg::OnQuerySkinnedFontParmName() const
- {
- ASSERT_VALID( this );
- return NULL;
- }
- void CExtResDlg::PmBridge_OnPaintManagerChanged(
- CExtPaintManager * pGlobalPM
- )
- {
- CExtPmBridge::PmBridge_OnPaintManagerChanged( pGlobalPM );
- HWND hWndOwn = GetSafeHwnd();
- if( hWndOwn == NULL )
- return;
- HWND hWndParent = ::GetParent( hWndOwn );
- if( hWndParent != NULL
- && ( ::__EXT_MFC_GetWindowLong( hWndOwn, GWL_STYLE ) & WS_POPUP ) != 0
- )
- {
- ::SetWindowPos(
- hWndOwn, NULL, 0, 0, 0, 0,
- SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE
- |SWP_NOZORDER|SWP_NOOWNERZORDER
- |SWP_FRAMECHANGED
- );
- ::RedrawWindow(
- hWndOwn,
- NULL,
- NULL,
- RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN
- );
- }
- }
- BEGIN_MESSAGE_MAP(CExtResDlg, CDialog)
- //{{AFX_MSG_MAP(CExtResDlg)
- ON_WM_ACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void CExtResDlg::OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- nState;
- pWndOther;
- bMinimized;
- }
- BOOL CExtResDlg::Create(
- __EXT_MFC_SAFE_LPCTSTR lpszTemplateName,
- CWnd * pParentWnd // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT(
- HIWORD(lpszTemplateName) == 0
- || AfxIsValidString( lpszTemplateName )
- );
- m_lpszTemplateName = lpszTemplateName; // used for help
- if( HIWORD(m_lpszTemplateName) == 0
- && m_nIDHelp == 0
- )
- m_nIDHelp = LOWORD((DWORD)(__EXT_MFC_DWORD_PTR)m_lpszTemplateName);
- m_lpszTemplateName_SAVED = m_lpszTemplateName;
- HRSRC hResource = NULL;
- HINSTANCE hInst =
- g_ResourceManager->FindResourceHandle(
- RT_DIALOG,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(lpszTemplateName))),
- NULL,
- &hResource
- );
- ASSERT( hInst != NULL );
- ASSERT( hResource != NULL );
- if( hInst == NULL )
- return FALSE;
- HGLOBAL hTemplate = LoadResource( hInst, hResource );
- ASSERT( hTemplate != NULL );
- BOOL bResult = CreateIndirect( hTemplate, pParentWnd, hInst );
- FreeResource( hTemplate );
- return bResult;
- }
- BOOL CExtResDlg::Create(
- UINT nIDTemplate,
- CWnd * pParentWnd // = NULL
- )
- {
- return Create( MAKEINTRESOURCE(nIDTemplate), pParentWnd );
- }
- DLGTEMPLATE * CExtResDlg::stat_ChangeDlgFont(
- const DLGTEMPLATE * pTemplate
- )
- {
- CDialogTemplate dlgTemplate( pTemplate );
- CExtSafeString strFaceDefault, strFace;
- WORD wSizeDefault, wSize;
- if( CExtResPP::stat_GetPropSheetFont(
- strFaceDefault,
- wSizeDefault,
- FALSE
- )
- )
- {
- CString _strFaceBuffer;
- BOOL bFontFetched =
- CDialogTemplate::GetFont(
- pTemplate,
- _strFaceBuffer,
- wSize
- );
- strFace = LPCTSTR( _strFaceBuffer );
- if( ( (! bFontFetched )
- || (strFace != strFaceDefault)
- || (wSize != wSizeDefault)
- )
- && ( ( _tcscmp( strFace, _T("MS Sans Serif") ) == 0
- || _tcscmp( strFace, _T("MS Shell Dlg") ) == 0
- )
- && (wSize == wSizeDefault)
- )
- )
- dlgTemplate.SetFont(
- strFaceDefault,
- wSizeDefault
- );
- // else if(
- // _tcscmp( strFace, _T("Khmer OS") ) == 0
- // || _tcscmp( strFace, _T("Khmer OS System") ) == 0
- // )
- // dlgTemplate.SetFont(
- // strFace,
- // wSize
- // );
- }
- return (DLGTEMPLATE*)dlgTemplate.Detach();
- }
- __EXT_MFC_INT_PTR CExtResDlg::DoModal()
- {
- __PROF_UIS_MANAGE_STATE;
- m_lpszTemplateName_SAVED = m_lpszTemplateName;
- return _DoModalImpl();
- }
- __EXT_MFC_INT_PTR CExtResDlg::_DoModalImpl()
- {
- ASSERT(
- m_lpszTemplateName != NULL
- || m_hDialogTemplate != NULL
- || m_lpDialogTemplate != NULL
- );
- LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
- HGLOBAL hDialogTemplate = m_hDialogTemplate;
- HINSTANCE hInst = ::AfxGetResourceHandle();
- if( m_lpszTemplateName != NULL )
- {
- HRSRC hResource = NULL;
- hInst =
- g_ResourceManager->FindResourceHandle(
- RT_DIALOG,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(m_lpszTemplateName))),
- NULL,
- &hResource
- );
- ASSERT( hInst != NULL );
- ASSERT( hResource != NULL );
- //hInst = AfxFindResourceHandle( m_lpszTemplateName, RT_DIALOG );
- //HRSRC hResource = ::FindResource( hInst, m_lpszTemplateName, RT_DIALOG );
- hDialogTemplate = ::LoadResource( hInst, hResource );
- } // if( m_lpszTemplateName != NULL )
- if( hDialogTemplate != NULL )
- lpDialogTemplate = (LPCDLGTEMPLATE)LockResource( hDialogTemplate );
- if( lpDialogTemplate == NULL )
- return -1;
- HWND hWndParent = PreModal();
- ::AfxUnhookWindowCreate();
- BOOL bEnableParent = FALSE;
- if( hWndParent != NULL && ::IsWindowEnabled( hWndParent ) )
- {
- ::EnableWindow( hWndParent, FALSE );
- bEnableParent = TRUE;
- } // if( hWndParent != NULL && ::IsWindowEnabled( hWndParent ) )
- TRY
- {
- ::AfxHookWindowCreate( this );
- if( CreateDlgIndirect(
- lpDialogTemplate,
- CWnd::FromHandle( hWndParent ),
- hInst
- )
- )
- {
- if( (m_nFlags&WF_CONTINUEMODAL) != 0 )
- {
- DWORD dwFlags = MLF_SHOWONIDLE;
- if( (GetStyle()&DS_NOIDLEMSG) != 0 )
- dwFlags |= MLF_NOIDLEMSG;
- int nModalResult = RunModalLoop( dwFlags );
- VERIFY( nModalResult == m_nModalResult );
- nModalResult;
- } // if( (m_nFlags&WF_CONTINUEMODAL) != 0 )
- if( m_hWnd != NULL )
- SetWindowPos(
- NULL, 0, 0, 0, 0,
- SWP_HIDEWINDOW
- |SWP_NOSIZE|SWP_NOMOVE
- |SWP_NOACTIVATE|SWP_NOZORDER
- );
- }
- }
- CATCH_ALL(e)
- {
- DELETE_EXCEPTION( e );
- m_nModalResult = -1;
- }
- END_CATCH_ALL
- if( bEnableParent )
- ::EnableWindow( hWndParent, TRUE );
- if( hWndParent != NULL && ::GetActiveWindow() == m_hWnd )
- ::SetActiveWindow( hWndParent );
- DestroyWindow();
- PostModal();
- if( m_lpszTemplateName != NULL || m_hDialogTemplate != NULL )
- UnlockResource( hDialogTemplate );
- if (m_lpszTemplateName != NULL)
- FreeResource( hDialogTemplate );
- return m_nModalResult;
- }
- DLGTEMPLATE * CExtResDlg::OnAdjustDialogTemplate(
- const DLGTEMPLATE * lpDialogTemplate
- )
- {
- ASSERT( lpDialogTemplate != NULL);
- DLGTEMPLATE * lpDialogTemplateOut =
- g_ResourceManager->OnAdjustDialogTemplate(
- lpDialogTemplate,
- this
- );
- if( lpDialogTemplateOut != NULL )
- return lpDialogTemplateOut;
- lpDialogTemplateOut =
- PmBridge_GetPM()->AdjustDialogTemplate(
- lpDialogTemplate,
- this
- );
- if( lpDialogTemplateOut != NULL )
- return lpDialogTemplateOut;
- lpDialogTemplateOut =
- stat_ChangeDlgFont(
- lpDialogTemplate
- );
- return lpDialogTemplateOut;
- }
- BOOL CExtResDlg::CreateDlgIndirect(
- LPCDLGTEMPLATE lpDialogTemplate,
- CWnd * pParentWnd,
- HINSTANCE hInst
- )
- {
- ASSERT( lpDialogTemplate != NULL);
- lpDialogTemplate = (LPCDLGTEMPLATE)
- OnAdjustDialogTemplate( lpDialogTemplate );
- #ifdef _DEBUG
- if( pParentWnd != NULL )
- ASSERT_VALID( pParentWnd );
- #endif // _DEBUG
- if( hInst == NULL )
- {
- hInst = ::AfxGetResourceHandle();
- if( hInst == NULL )
- hInst = ::AfxGetInstanceHandle();
- }
- _AFX_OCC_DIALOG_INFO occDialogInfo;
- COccManager * pOccManager = afxOccManager;
- HGLOBAL hTemplate = NULL;
- HWND hWnd = NULL;
- #ifdef _DEBUG
- DWORD dwError = 0;
- #endif
- TRY
- {
- VERIFY( AfxDeferRegisterClass( AFX_WNDCOMMCTLS_REG ) );
- AfxDeferRegisterClass( AFX_WNDCOMMCTLSNEW_REG );
- if( pOccManager != NULL )
- {
- if( ! SetOccDialogInfo( &occDialogInfo ) )
- return FALSE;
- lpDialogTemplate =
- pOccManager->PreCreateDialog(
- &occDialogInfo,
- lpDialogTemplate
- );
- }
- if( lpDialogTemplate == NULL )
- return FALSE;
- CString strFace;
- WORD wSize = 0;
- CString _strFaceBuffer;
- BOOL bFontFetched =
- CDialogTemplate::GetFont(
- lpDialogTemplate,
- _strFaceBuffer,
- wSize
- );
- strFace = LPCTSTR( _strFaceBuffer );
- BOOL bSetSysFont = ! bFontFetched;
- if( (!bSetSysFont)
- && GetSystemMetrics( SM_DBCSENABLED )
- )
- {
- bSetSysFont =
- (strFace == _T("MS Shell Dlg")
- || strFace == _T("MS Sans Serif")
- || strFace == _T("Helv")
- );
- if( bSetSysFont && (wSize == 8) )
- wSize = 0;
- }
- if( bSetSysFont )
- {
- CDialogTemplate dlgTemp( lpDialogTemplate );
- dlgTemp.SetSystemFont( wSize );
- hTemplate = dlgTemp.Detach();
- }
- if( hTemplate != NULL )
- lpDialogTemplate = (LPCDLGTEMPLATE)GlobalLock( hTemplate );
- m_nModalResult = -1;
- m_nFlags |= WF_CONTINUEMODAL;
- ::AfxHookWindowCreate( this );
- if( OnQueryAutomaticRTLTransform() )
- {
- if( (g_ResourceManager->OnQueryLangLayout()&LAYOUT_RTL) != 0 )
- {
- if( ((DLGTEMPLATEEX*)lpDialogTemplate)->signature == 0x0FFFF )
- ((DLGTEMPLATEEX*)lpDialogTemplate)->exStyle |= WS_EX_LAYOUTRTL;
- else
- ((DLGTEMPLATE*)lpDialogTemplate)->dwExtendedStyle |= WS_EX_LAYOUTRTL;
- }
- }
- hWnd =
- ::CreateDialogIndirect(
- hInst,
- lpDialogTemplate,
- pParentWnd->GetSafeHwnd(),
- AfxDlgProc
- );
- #ifdef _DEBUG
- dwError = ::GetLastError();
- #endif
- }
- CATCH_ALL(e)
- {
- DELETE_EXCEPTION(e);
- m_nModalResult = -1;
- }
- END_CATCH_ALL
- if( pOccManager != NULL )
- {
- pOccManager->PostCreateDialog( &occDialogInfo );
- if( hWnd != NULL )
- SetOccDialogInfo( NULL );
- }
- if( !AfxUnhookWindowCreate() )
- PostNcDestroy();
- if( hWnd != NULL
- && ( (m_nFlags&WF_CONTINUEMODAL) == 0 )
- )
- {
- ::DestroyWindow(hWnd);
- hWnd = NULL;
- }
- if( hTemplate != NULL )
- {
- GlobalUnlock( hTemplate );
- GlobalFree( hTemplate );
- }
- if( hWnd == NULL && (m_nFlags&WF_CONTINUEMODAL) != 0 )
- {
- #ifdef _DEBUG
- if (afxOccManager == NULL)
- {
- TRACE0(">>> If this dialog has OLE controls:n");
- TRACE0(">>> AfxEnableControlContainer has not been called yet.n");
- TRACE0(">>> You should call it in your app's InitInstance function.n");
- }
- else if( dwError != 0 )
- {
- TRACE1("Warning: Dialog creation failed! GetLastError returns 0x%8.8Xn", dwError);
- }
- #endif //_DEBUG
- return FALSE;
- }
- ASSERT( hWnd == m_hWnd );
- return TRUE;
- }
- BOOL CExtResDlg::CreateDlgIndirect(
- LPCDLGTEMPLATE lpDialogTemplate,
- CWnd * pParentWnd
- )
- {
- return CreateDlgIndirect( lpDialogTemplate, pParentWnd, NULL );
- }
- BOOL CExtResDlg::CreateIndirect(
- LPCDLGTEMPLATE lpDialogTemplate,
- CWnd * pParentWnd, // = NULL
- void * lpDialogInit // = NULL
- )
- {
- return
- CreateIndirect(
- lpDialogTemplate,
- pParentWnd,
- lpDialogInit,
- NULL
- );
- }
- BOOL CExtResDlg::CreateIndirect(
- HGLOBAL hDialogTemplate,
- CWnd * pParentWnd // = NULL
- )
- {
- return
- CreateIndirect(
- hDialogTemplate,
- pParentWnd,
- NULL
- );
- }
- BOOL CExtResDlg::CreateIndirect(
- LPCDLGTEMPLATE lpDialogTemplate,
- CWnd * pParentWnd,
- void * lpDialogInit,
- HINSTANCE hInst
- )
- {
- ASSERT( lpDialogTemplate != NULL );
- if( pParentWnd == NULL )
- pParentWnd = ::AfxGetMainWnd();
- m_lpDialogInit = lpDialogInit;
- return
- CreateDlgIndirect(
- lpDialogTemplate,
- pParentWnd,
- hInst
- );
- }
- BOOL CExtResDlg::CreateIndirect(
- HGLOBAL hDialogTemplate,
- CWnd * pParentWnd,
- HINSTANCE hInst
- )
- {
- ASSERT(hDialogTemplate != NULL);
- LPCDLGTEMPLATE lpDialogTemplate =
- (LPCDLGTEMPLATE)LockResource( hDialogTemplate );
- BOOL bResult =
- CreateIndirect(
- lpDialogTemplate,
- pParentWnd,
- NULL,
- hInst
- );
- UnlockResource( hDialogTemplate );
- return bResult;
- }
- BOOL CExtResDlg::OnInitDialog()
- {
- if( m_lpszTemplateName_SAVED != NULL )
- {
- m_lpDialogInit = NULL;
- ExecuteDlgInit( m_lpszTemplateName_SAVED );
- }
- void * _lpDialogInit = m_lpDialogInit;
- m_lpDialogInit = NULL;
- LPCTSTR _lpszTemplateName = m_lpszTemplateName;
- m_lpszTemplateName = NULL;
- BOOL bRetVal = CDialog::OnInitDialog();
- m_lpDialogInit = _lpDialogInit;
- m_lpszTemplateName = _lpszTemplateName;
- return bRetVal;
- }
- BOOL CExtResDlg::stat_ExecuteDlgInit(
- CWnd * pWnd,
- LPVOID pResource
- )
- {
- BOOL bSuccess = TRUE;
- if( pResource != NULL )
- {
- UNALIGNED WORD * pResWalk = (WORD*)pResource;
- for( ; bSuccess && (*pResWalk) != 0; )
- {
- WORD nIDC = *pResWalk++;
- WORD nMsg = *pResWalk++;
- DWORD dwLen = *((UNALIGNED DWORD*&)pResWalk)++;
- #define WIN16_LB_ADDSTRING 0x0401
- #define WIN16_CB_ADDSTRING 0x0403
- #define AFX_CB_ADDSTRING 0x1234
- if( nMsg == AFX_CB_ADDSTRING )
- nMsg = CBEM_INSERTITEM;
- else if (nMsg == WIN16_LB_ADDSTRING)
- nMsg = LB_ADDSTRING;
- else if (nMsg == WIN16_CB_ADDSTRING)
- nMsg = CB_ADDSTRING;
- #ifdef _DEBUG
- if( nMsg == LB_ADDSTRING
- || nMsg == CB_ADDSTRING
- || nMsg == CBEM_INSERTITEM
- )
- ASSERT( *((LPBYTE)pResWalk + (UINT)dwLen - 1) == 0 );
- #endif
- if( nMsg == CBEM_INSERTITEM )
- {
- USES_CONVERSION;
- COMBOBOXEXITEM item;
- item.mask = CBEIF_TEXT;
- item.iItem = -1;
- item.pszText = A2T( LPSTR(pResWalk) );
- if( ::SendDlgItemMessage(
- pWnd->m_hWnd,
- nIDC,
- nMsg,
- 0,
- (LPARAM)&item
- ) == - 1
- )
- bSuccess = FALSE;
- } // if( nMsg == CBEM_INSERTITEM )
- else if( nMsg == LB_ADDSTRING || nMsg == CB_ADDSTRING )
- {
- LPCSTR strToInsert = LPSTR(pResWalk);
- if( ::SendDlgItemMessageA(
- pWnd->m_hWnd,
- nIDC,
- nMsg,
- 0,
- (LPARAM)strToInsert
- ) == -1
- )
- bSuccess = FALSE;
- } // else if( nMsg == LB_ADDSTRING || nMsg == CB_ADDSTRING )
- pResWalk = (WORD*)((LPBYTE)pResWalk + (UINT)dwLen);
- } // for( ; bSuccess && (*pResWalk) != 0; )
- } // if( pResource != NULL )
- if( bSuccess )
- pWnd->SendMessageToDescendants(
- WM_INITIALUPDATE,
- 0,
- 0,
- FALSE,
- FALSE
- );
- return bSuccess;
- }
- BOOL CExtResDlg::ExecuteDlgInit( __EXT_MFC_SAFE_LPCTSTR lpszResourceName )
- {
- LPVOID pResource = NULL;
- HGLOBAL hGlobalResource = NULL;
- if (lpszResourceName != NULL)
- {
- HRSRC hResource = NULL;
- HINSTANCE hInst =
- g_ResourceManager->FindResourceHandle(
- RT_DLGINIT,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(m_lpszTemplateName))),
- NULL,
- &hResource
- );
- if( hInst != NULL )
- {
- ASSERT( hResource != NULL );
- hGlobalResource = LoadResource( hInst, hResource );
- if( hGlobalResource == NULL )
- return FALSE;
- pResource = LockResource( hGlobalResource );
- ASSERT( pResource != NULL );
- } // if( hInst != NULL )
- }
- BOOL bResult = ExecuteDlgInit( pResource );
- if( pResource != NULL && hGlobalResource != NULL )
- {
- UnlockResource( hGlobalResource );
- FreeResource( hGlobalResource );
- }
- return bResult;
- }
- BOOL CExtResDlg::ExecuteDlgInit( LPVOID pResource )
- {
- return stat_ExecuteDlgInit( this, pResource );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtResPP window
- IMPLEMENT_DYNCREATE( CExtResPP, CPropertyPage )
- IMPLEMENT_CExtPmBridge_MEMBERS( CExtResPP );
- CExtResPP::CExtResPP()
- : m_lpszTemplateName_SAVED( NULL )
- {
- CommonConstruct( NULL, 0 );
- PmBridge_Install();
- }
- CExtResPP::CExtResPP(
- UINT nIDTemplate,
- UINT nIDCaption // = 0
- )
- {
- ASSERT( nIDTemplate != 0 );
- CommonConstruct( MAKEINTRESOURCE(nIDTemplate), nIDCaption );
- PmBridge_Install();
- }
- CExtResPP::CExtResPP(
- __EXT_MFC_SAFE_LPCTSTR lpszTemplateName,
- UINT nIDCaption // = 0
- )
- {
- ASSERT(
- HIWORD(lpszTemplateName) == 0
- || AfxIsValidString( lpszTemplateName )
- );
- CommonConstruct( lpszTemplateName, nIDCaption );
- PmBridge_Install();
- }
- CExtResPP::~CExtResPP()
- {
- PmBridge_Uninstall();
- }
- __EXT_MFC_SAFE_LPCTSTR CExtResPP::OnQuerySkinnedFontParmName() const
- {
- ASSERT_VALID( this );
- return NULL;
- }
- BEGIN_MESSAGE_MAP(CExtResPP, CPropertyPage)
- //{{AFX_MSG_MAP(CExtResPP)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CExtResPP::OnInitDialog()
- {
- if( m_lpszTemplateName_SAVED != NULL )
- {
- m_lpDialogInit = NULL;
- ExecuteDlgInit( m_lpszTemplateName_SAVED );
- }
- void * _lpDialogInit = m_lpDialogInit;
- m_lpDialogInit = NULL;
- LPCTSTR _lpszTemplateName = m_lpszTemplateName;
- m_lpszTemplateName = NULL;
- BOOL bRetVal = CPropertyPage::OnInitDialog();
- m_lpDialogInit = _lpDialogInit;
- m_lpszTemplateName = _lpszTemplateName;
- g_ResourceManager->DesiredFont_ChangeWindow( GetSafeHwnd(), 32766 );
- return bRetVal;
- }
- BOOL CExtResPP::ExecuteDlgInit( __EXT_MFC_SAFE_LPCTSTR lpszResourceName )
- {
- LPVOID pResource = NULL;
- HGLOBAL hGlobalResource = NULL;
- if (lpszResourceName != NULL)
- {
- HRSRC hResource = NULL;
- HINSTANCE hInst =
- g_ResourceManager->FindResourceHandle(
- RT_DLGINIT,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(m_lpszTemplateName))),
- NULL,
- &hResource
- );
- if( hInst != NULL )
- {
- ASSERT( hResource != NULL );
- hGlobalResource = LoadResource( hInst, hResource );
- if( hGlobalResource == NULL )
- return FALSE;
- pResource = LockResource( hGlobalResource );
- ASSERT( pResource != NULL );
- } // if( hInst != NULL )
- }
- BOOL bResult = ExecuteDlgInit( pResource );
- if( pResource != NULL && hGlobalResource != NULL )
- {
- UnlockResource( hGlobalResource );
- FreeResource( hGlobalResource );
- }
- return bResult;
- }
- BOOL CExtResPP::ExecuteDlgInit( LPVOID pResource )
- {
- return CExtResDlg::stat_ExecuteDlgInit( this, pResource );
- }
- #define IDD_PROPSHEET 1006
- #define IDD_WIZARD 1020
- BOOL CExtResPP::stat_GetPropSheetFont(
- CExtSafeString & strFace,
- WORD & wSize,
- BOOL bWizard
- )
- {
- //HFONT hFont = g_ResourceManager->DesiredFont_GetHandle();
- // if( hFont != NULL )
- // {
- // LOGFONT _lf;
- // ::memset( &_lf, 0, sizeof(LOGFONT) );
- // ::GetObject( hFont, sizeof(LOGFONT), &_lf );
- // strFace = _lf.lfFaceName;
- // wSize = 8;
- // return TRUE;
- // } // if( hFont != NULL )
- struct FAKE_PROPPAGEFONTINFO : public CNoTrackObject
- {
- LPTSTR m_pszFaceName;
- WORD m_wSize;
- FAKE_PROPPAGEFONTINFO() : m_pszFaceName(NULL), m_wSize(0) {}
- ~FAKE_PROPPAGEFONTINFO() { GlobalFree(m_pszFaceName); }
- };
- static FAKE_PROPPAGEFONTINFO _afxPropPageFontInfo;
- FAKE_PROPPAGEFONTINFO * pFontInfo = &_afxPropPageFontInfo;
- if( pFontInfo->m_wSize == 0 )
- {
- ASSERT( pFontInfo->m_pszFaceName == NULL );
- HINSTANCE hInst =
- ::GetModuleHandleA( "COMCTL32.DLL" );
- if( hInst != NULL )
- {
- // HRSRC hResource =
- // ::FindResource(
- // hInst,
- // MAKEINTRESOURCE( (bWizard ? IDD_WIZARD : IDD_PROPSHEET) ),
- // RT_DIALOG
- // );
- // HGLOBAL hTemplate = ::LoadResource( hInst, hResource );
- // if( hTemplate != NULL )
- // CDialogTemplate::GetFont(
- // (DLGTEMPLATE*)hTemplate,
- // strFace,
- // wSize
- // );
- CExtResourceManager::CExtResourceMemoryBuffer bufferOut;
- if( bufferOut.FindAndLoad(
- hInst,
- RT_DIALOG,
- bWizard ? IDD_WIZARD : IDD_PROPSHEET,
- g_ResourceManager->GetLangIdNeutral()
- )
- )
- {
- CString _strFace;
- CDialogTemplate::GetFont(
- (DLGTEMPLATE*)bufferOut.GetBuffer(),
- _strFace,
- wSize
- );
- strFace = LPCTSTR( _strFace );
- }
- } // if( hInst != NULL )
- pFontInfo->m_pszFaceName =
- (LPTSTR)::GlobalAlloc(
- GPTR,
- sizeof(TCHAR) * ( strFace.GetLength() + 1 )
- );
- lstrcpy( pFontInfo->m_pszFaceName, LPCTSTR(strFace) );
- pFontInfo->m_wSize = wSize;
- } // if( pFontInfo->m_wSize == 0 )
- strFace = pFontInfo->m_pszFaceName;
- wSize = pFontInfo->m_wSize;
- return ( wSize != 0xFFFF) ? TRUE : FALSE;
- }
- DLGTEMPLATE * CExtResPP::OnAdjustDialogTemplate(
- const DLGTEMPLATE * pTemplate,
- BOOL bWizard
- )
- {
- ASSERT( pTemplate != NULL);
- DLGTEMPLATE * lpDialogTemplateOut =
- g_ResourceManager->OnAdjustDialogTemplate(
- pTemplate,
- this,
- bWizard ? true : false
- );
- if( lpDialogTemplateOut != NULL )
- return lpDialogTemplateOut;
- lpDialogTemplateOut =
- PmBridge_GetPM()->AdjustDialogTemplate(
- pTemplate,
- this,
- bWizard ? true : false
- );
- if( lpDialogTemplateOut != NULL )
- return lpDialogTemplateOut;
- return
- stat_ChangePropPageFont( pTemplate, bWizard );
- }
- DLGTEMPLATE * CExtResPP::stat_ChangePropPageFont(
- const DLGTEMPLATE * pTemplate,
- BOOL bWizard
- )
- {
- CExtSafeString strFaceDefault;
- WORD wSizeDefault;
- //HFONT hFont = g_ResourceManager->DesiredFont_GetHandle();
- // if( hFont != NULL )
- // {
- // LOGFONT _lf;
- // ::memset( &_lf, 0, sizeof(LOGFONT) );
- // ::GetObject( hFont, sizeof(LOGFONT), &_lf );
- // strFaceDefault = _lf.lfFaceName;
- // wSizeDefault = 8;
- // } // if( hFont != NULL )
- // else
- {
- if( ! stat_GetPropSheetFont(
- strFaceDefault,
- wSizeDefault,
- bWizard
- )
- )
- return NULL;
- } // else from if( hFont != NULL )
- WORD wSize;
- CExtSafeString strFace;
- CString _strFaceBuffer;
- BOOL bFontFetched =
- CDialogTemplate::GetFont(
- pTemplate,
- _strFaceBuffer,
- wSize
- );
- strFace = LPCTSTR( _strFaceBuffer );
- if( (! bFontFetched )
- || (strFace != strFaceDefault)
- || (wSize != wSizeDefault)
- )
- {
- CDialogTemplate dlgTemplate( pTemplate );
- dlgTemplate.SetFont( strFaceDefault, wSizeDefault );
- return (DLGTEMPLATE*)dlgTemplate.Detach();
- }
- return NULL;
- }
- void CExtResPP::PreProcessPageTemplate(
- PROPSHEETPAGE & psp,
- BOOL bWizard
- )
- {
- const DLGTEMPLATE * pTemplate;
- CExtResourceManager::CExtResourceMemoryBuffer bufferOut;
- if( psp.dwFlags & PSP_DLGINDIRECT )
- {
- pTemplate = psp.pResource;
- m_lpszTemplateName_SAVED = NULL;
- }
- else
- {
- // HRSRC hResource =
- // ::FindResource(
- // psp.hInstance,
- // psp.pszTemplate,
- // RT_DIALOG
- // );
- // HGLOBAL hTemplate = LoadResource(psp.hInstance,
- // hResource);
- // pTemplate = (LPCDLGTEMPLATE)LockResource(hTemplate);
- HRSRC hResource = NULL;
- HINSTANCE hInst =
- g_ResourceManager->FindResourceHandle(
- RT_DIALOG,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(psp.pszTemplate))),
- NULL,
- &hResource
- );
- ASSERT( hInst != NULL );
- ASSERT( hResource != NULL );
- ASSERT( psp.hInstance == hInst );
- HGLOBAL hTemplate = LoadResource(psp.hInstance,
- hResource);
- pTemplate = (LPCDLGTEMPLATE)LockResource(hTemplate);
- }
- ASSERT( pTemplate != NULL );
- #ifdef _DEBUG
- if( ( ( DLGTEMPLATEEX*)pTemplate )->signature == 0xFFFF )
- {
- DWORD dwVersion = ::GetVersion();
- if( dwVersion & 0x80000000 )
- {
- HINSTANCE hInst = LoadLibrary(_T("COMCTL32.DLL"));
- ASSERT(hInst != NULL);
- if (hInst != NULL)
- {
- FARPROC proc = GetProcAddress(hInst, "DllGetVersion");
- if (proc == NULL)
- ASSERT( FALSE );
- FreeLibrary(hInst);
- }
- } // if( dwVersion & 0x80000000 )
- else if (LOBYTE(LOWORD(dwVersion)) == 3)
- {
- ASSERT( FALSE );
- } // else from if( dwVersion & 0x80000000 )
- } // if( ( ( DLGTEMPLATEEX*)pTemplate )->signature == 0xFFFF )
- #endif // _DEBUG
- if( afxOccManager != NULL )
- pTemplate = InitDialogInfo( pTemplate );
- HGLOBAL hTemplate =
- OnAdjustDialogTemplate(
- pTemplate,
- bWizard
- );
- if( m_hDialogTemplate != NULL )
- {
- GlobalFree( m_hDialogTemplate );
- m_hDialogTemplate = NULL;
- }
- if( hTemplate != NULL )
- {
- pTemplate = (LPCDLGTEMPLATE)hTemplate;
- m_hDialogTemplate = hTemplate;
- }
- psp.pResource = pTemplate;
- psp.dwFlags |= PSP_DLGINDIRECT;
- }
- void CExtResPP::Construct(
- UINT nIDTemplate,
- UINT nIDCaption
- )
- {
- ASSERT( nIDTemplate != 0 );
- CommonConstruct( MAKEINTRESOURCE(nIDTemplate), nIDCaption );
- }
- void CExtResPP::Construct(
- __EXT_MFC_SAFE_LPCTSTR lpszTemplateName,
- UINT nIDCaption
- )
- {
- ASSERT(
- HIWORD(lpszTemplateName) == 0
- || AfxIsValidString( lpszTemplateName )
- );
- CommonConstruct( lpszTemplateName, nIDCaption );
- }
- UINT CALLBACK CExtResPP::stat_PropPageCallback( HWND, UINT message, LPPROPSHEETPAGE pPropPage )
- {
- switch (message)
- {
- case PSPCB_CREATE:
- {
- #if _MFC_VER < 0x700
- ASSERT( AfxIsValidAddress( pPropPage, sizeof(AFX_OLDPROPSHEETPAGE) ) );
- #endif
- ASSERT( AfxIsValidAddress( pPropPage, pPropPage->dwSize ) );
- CPropertyPage * pPage =
- STATIC_DOWNCAST( CPropertyPage, (CObject*)(pPropPage->lParam) );
- ASSERT_VALID( pPage );
- TRY
- {
- AfxHookWindowCreate( pPage );
- }
- CATCH_ALL( e )
- {
- return FALSE;
- }
- END_CATCH_ALL
- }
- return TRUE;
- case PSPCB_RELEASE:
- AfxUnhookWindowCreate();
- break;
- }
- return 0;
- }
- void CExtResPP::CommonConstruct(
- __EXT_MFC_SAFE_LPCTSTR lpszTemplateName,
- UINT nIDCaption
- )
- {
- memset( &m_psp, 0, sizeof(m_psp) );
- m_psp.dwSize = sizeof(m_psp);
- m_psp.dwFlags = PSP_USECALLBACK;
- if( lpszTemplateName != NULL )
- //m_psp.hInstance = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
- m_psp.hInstance =
- g_ResourceManager->FindResourceHandle(
- RT_DIALOG,
- UINT(__EXT_MFC_UINT_PTR(LPCTSTR(lpszTemplateName)))
- );
-
- m_psp.pszTemplate = lpszTemplateName;
- m_psp.pfnDlgProc = AfxDlgProc;
- m_psp.lParam = (LPARAM)this;
- m_psp.pfnCallback = stat_PropPageCallback;
- if( nIDCaption != 0 )
- {
- CExtSafeString _strCaption;
- VERIFY( g_ResourceManager->LoadString( _strCaption, nIDCaption ) );
- m_strCaption = LPCTSTR(_strCaption);
- m_psp.pszTitle = m_strCaption;
- m_psp.dwFlags |= PSP_USETITLE;
- }
- if( AfxHelpEnabled() )
- m_psp.dwFlags |= PSP_HASHELP;
- if( HIWORD(lpszTemplateName) == 0 )
- m_nIDHelp = LOWORD((DWORD)(__EXT_MFC_DWORD_PTR)lpszTemplateName);
- m_lpszTemplateName = m_psp.pszTemplate;
- m_bFirstSetActive = TRUE;
- }
- #ifdef _DEBUG
- void CExtResPP::AssertValid() const
- {
- CWnd::AssertValid();
- }
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CExtResPS window
- IMPLEMENT_DYNCREATE( CExtResPS, CPropertySheet )
- IMPLEMENT_CExtPmBridge_MEMBERS( CExtResPS );
- CExtResPS::CExtResPS()
- {
- PmBridge_Install();
- }
- CExtResPS::CExtResPS(
- UINT nIDCaption,
- CWnd * pParentWnd, // = NULL
- UINT iSelectPage // = 0
- )
- : CPropertySheet( nIDCaption, pParentWnd, iSelectPage )
- {
- CExtSafeString strCaption;
- if( g_ResourceManager->LoadString( strCaption, nIDCaption ) )
- {
- m_strCaption = LPCTSTR( strCaption );
- m_psh.pszCaption = m_strCaption;
- }
- PmBridge_Install();
- }
- CExtResPS::CExtResPS(
- __EXT_MFC_SAFE_LPCTSTR pszCaption,
- CWnd * pParentWnd, // = NULL
- UINT iSelectPage // = 0
- )
- : CPropertySheet( LPCTSTR(pszCaption), pParentWnd, iSelectPage )
- {
- PmBridge_Install();
- }
- CExtResPS::~CExtResPS()
- {
- PmBridge_Uninstall();
- }
- __EXT_MFC_SAFE_LPCTSTR CExtResPS::OnQuerySkinnedFontParmName() const
- {
- ASSERT_VALID( this );
- return NULL;
- }
- BEGIN_MESSAGE_MAP(CExtResPS, CPropertySheet)
- //{{AFX_MSG_MAP(CExtResPS)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void CExtResPS::InitLocalizedChildren()
- {
- // TO DO: NOT IMPL YET
- // HINSTANCE hInst =
- // ::GetModuleHandleA( "COMCTL32.DLL" );
- // if( hInst != NULL )
- // {
- // CExtResourceManager::CExtResourceMemoryBuffer bufferOut;
- // if( bufferOut.FindAndLoad(
- // hInst,
- // RT_DIALOG,
- // IDD_WIZARD,
- // g_ResourceManager->GetLangIdNeutral()
- // )
- // )
- // {
- // //CDialogTemplate dlgTemplate( (DLGTEMPLATE*)bufferOut.GetBuffer() );
- // //dlgTemplate.
- // }
- // } // if( hInst != NULL )
- }
- LRESULT CExtResPS::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lResult = CPropertySheet::WindowProc( message, wParam, lParam );
- switch( message )
- {
- case WM_CREATE:
- InitLocalizedChildren();
- break;
- } // switch( message )
- return lResult;
- }
- BOOL CExtResPS::OnInitDialog()
- {
- BOOL bRetVal = CPropertySheet::OnInitDialog();
- InitLocalizedChildren();
-
- //g_ResourceManager->DesiredFont_ChangeWindow( GetSafeHwnd(), 32766 );
- HWND hWnd = GetSafeHwnd();
- if( hWnd != NULL )
- {
- hWnd = ::GetWindow( hWnd, GW_CHILD );
- for( ; hWnd != NULL; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ) )
- g_ResourceManager->DesiredFont_ChangeWindow(
- hWnd,
- 32766
- );
- } // if( hWnd != NULL )
-
- return bRetVal;
- }
- void CExtResPS::BuildPropPageArray()
- {
- #if _MFC_VER < 0x700
- if( m_psh.ppsp != NULL )
- delete [] (PROPSHEETPAGE *) m_psh.ppsp;
- m_psh.ppsp = NULL;
- AFX_OLDPROPSHEETPAGE * ppsp =
- new AFX_OLDPROPSHEETPAGE[ m_pages.GetSize() ];
- ::memset( ppsp, 0, m_pages.GetSize() * sizeof(AFX_OLDPROPSHEETPAGE) );
- m_psh.ppsp = (LPPROPSHEETPAGE) ppsp;
- BOOL bWizard = ( m_psh.dwFlags & (PSH_WIZARD | __EXT_MFC_PSH_WIZARD97_MASK) );
- for( int i = 0; i < m_pages.GetSize(); i++ )
- {
- CPropertyPage * pPage = GetPage(i);
- __EXT_MFC_MEMCPY(
- &ppsp[i],
- sizeof(AFX_OLDPROPSHEETPAGE),
- & pPage->m_psp,
- pPage->m_psp.dwSize
- );
- CExtResPP * pExtResourcePropertyPage =
- DYNAMIC_DOWNCAST( CExtResPP, pPage );
- if( pExtResourcePropertyPage != NULL )
- pExtResourcePropertyPage->PreProcessPageTemplate(
- (PROPSHEETPAGE&) ppsp[i],
- bWizard
- );
- else
- {
- struct friendly_property_page_t : public CPropertyPage
- {
- public:
- friend class CExtResPS;
- };
- ((friendly_property_page_t *)pPage)->PreProcessPageTemplate(
- (PROPSHEETPAGE&) ppsp[i],
- bWizard
- );
- }
- } // for( int i = 0; i < m_pages.GetSize(); i++ )
- m_psh.nPages = m_pages.GetSize();
- #else
- if( m_psh.ppsp != NULL )
- {
- free((void*)m_psh.ppsp);
- m_psh.ppsp = NULL;
- }
- int i;
- int nBytes = 0;
- for( i = 0; i < m_pages.GetSize(); i++ )
- {
- CPropertyPage* pPage = GetPage(i);
- nBytes += pPage->m_psp.dwSize;
- }
- PROPSHEETPAGE * ppsp = (PROPSHEETPAGE *)malloc( nBytes );
- if( ppsp == NULL )
- AfxThrowMemoryException();
- ::memset( ppsp, 0, nBytes );
- m_psh.ppsp = ppsp;
- BOOL bWizard = (m_psh.dwFlags & (PSH_WIZARD | __EXT_MFC_PSH_WIZARD97_MASK));
- for( i = 0; i < m_pages.GetSize(); i++ )
- {
- struct friendly_property_page_t : public CPropertyPage
- {
- public:
- friend class CExtResPS;
- };
- friendly_property_page_t * pPage =
- (friendly_property_page_t *) GetPage(i);
- __EXT_MFC_MEMCPY(
- ppsp,
- sizeof(PROPSHEETPAGE),
- &pPage->m_psp,
- pPage->m_psp.dwSize
- );
- if (!pPage->m_strHeaderTitle.IsEmpty())
- {
- ppsp->pszHeaderTitle = pPage->m_strHeaderTitle;
- ppsp->dwFlags |= PSP_USEHEADERTITLE;
- }
- if (!pPage->m_strHeaderSubTitle.IsEmpty())
- {
- ppsp->pszHeaderSubTitle = pPage->m_strHeaderSubTitle;
- ppsp->dwFlags |= PSP_USEHEADERSUBTITLE;
- }
- CExtResPP * pExtResourcePropertyPage =
- DYNAMIC_DOWNCAST( CExtResPP, pPage );
- if( pExtResourcePropertyPage != NULL )
- pExtResourcePropertyPage->PreProcessPageTemplate(
- *ppsp,
- bWizard
- );
- else
- pPage->PreProcessPageTemplate(
- *ppsp,
- bWizard
- );
- (BYTE*&)ppsp += ppsp->dwSize;
- } // for( i = 0; i < m_pages.GetSize(); i++ )
- m_psh.nPages = (int)m_pages.GetSize();
- #endif
- }