Print Page | Close Window

Loading Theme from other source

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=14652
Printed Date: 21 June 2025 at 7:11am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Loading Theme from other source
Posted By: Michl
Subject: Loading Theme from other source
Date Posted: 30 June 2009 at 4:09am
Hi,

how is it possible to load themes from an external dll?


CXTPOffice2007Images::CXTPOffice2007Images()
{
    m_mapImages.InitHashTable(XTP_OFFICE2007_IMAGES_HASH_TABLE_SIZE, FALSE);

    m_bFreeOnRelease = FALSE;
    m_hResource = 0;
    m_lpTextFile = 0;
    m_lpTextFileEnd = 0;
    m_pConnection = NULL;

    SetHandle(AfxGetInstanceHandle());

    m_pLayerBits = NULL;
    m_hbmLayer = CXTPImageManager::Create32BPPDIBSection(NULL, 512, 512, (LPBYTE*)&m_pLayerBits);

    HDC hdcScreen = ::GetDC(HWND_DESKTOP);
    m_dc.Attach(::CreateCompatibleDC(hdcScreen));
    ReleaseDC(HWND_DESKTOP, hdcScreen);

    ::InitializeCriticalSection(&m_cs);
}

This code expects the theme resources in the executable.

My resolution was after selecting theme:

    HMODULE hModule = LoadLibrary( _T("xyz.dll") );
    ASSERT( hModule );
    if (!hModule)
        return false;

    CXTPPaintManager* pPaintManager = XTPPaintManager();
    if (pPaintManager &&
        pPaintManager->GetCurrentTheme() == xtpThemeOffice2007 ||
        pPaintManager->GetCurrentTheme() == xtpThemeRibbon)
    {
        CXTPOffice2007Theme& pOffice2007PaintManager = *static_cast<CXTPOffice2007Theme*>(pPaintManager);
        pOffice2007PaintManager.SetImageHandle( hModule, style.GetResourceName() );
     }
     FreeLibrary( hModule );


This seems to work. But with current release, this runs into the warning:


void CXTPOffice2007Images::AssertValid()
{
    if (IsValid())
        return;

    XT_ERROR_MSG(
        "Error Locating Office2007 Resources.\n\n"
        "Make sure you have included the resources to your project's .rc2 file. For example to provide\n"
        "support for Office 2007 Black Visual Style by adding the following line to your project .rc2 file:\n\n"
        "#include <Styles/Office2007Black/Office2007Black.rc> to your project .rc2 file.\n\n"
        "Giving you access to the Office 2007 resources.");
}


Temporarly I documented out this code, but is there a better way to resolve this problem?

Thanks



Replies:
Posted By: Oleg
Date Posted: 01 July 2009 at 8:06am
Hi,
 
Guess problem in FreeLibrary( hModule ); you call.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Michl
Date Posted: 01 July 2009 at 8:16am
What do you mean?
Should I free library at shut down? I thought the resources will be load into memory?

It would be nice to set an resource handle before first time the resources will be loaded.


Posted By: kstowell
Date Posted: 01 July 2009 at 11:16am
Try making hModule a member variable and free it in your dtor, for example:

.h file:
private:
    HMODULE m_hModule;
.cpp file:

CFoo::CFoo()
{
    m_hModule = ::LoadLibrary( _T("xyz.dll") );
    ASSERT(m_hModule != NULL);
}
~CFoo::CFoo()
{
    if (m_hModule)
        ::FreeLibrary(m_hModule);
}
BOOL CFoo::SelectTheme()
{
    if (m_hModule)
    {
        CXTPPaintManager* pPaintManager = XTPPaintManager();
        if (pPaintManager &&
            pPaintManager->GetCurrentTheme() == xtpThemeOffice2007 ||
            pPaintManager->GetCurrentTheme() == xtpThemeRibbon)
        {
            CXTPOffice2007Theme& pOffice2007PaintManager = *static_cast<CXTPOffice2007Theme*>(pPaintManager);
            pOffice2007PaintManager.SetImageHandle(m_hModule, style.GetResourceName() );
            return TRUE;
        }
    }
 
    return FALSE;
}


-------------
Kirk Stowell, President and CEO
CODEJOCK SOFTWARE SOLUTIONS<


Posted By: __BornInUssr__
Date Posted: 06 April 2010 at 6:38am
Sorry, but I can't solve the same problem. Please help!

I use next code:

hResource = LoadLibrary(sPath);
if(hResource)
     AfxSetResourceHandle(hResource);

After, on my MainFrame called:

XTPPaintManager()->SetTheme(xtpThemeRibbon);

And this call brings me to the same crash in Codejock.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net