Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Loading Theme from other source
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Loading Theme from other source

 Post Reply Post Reply
Author
Message
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post Topic: Loading Theme from other source
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2009 at 8:06am
Hi,
 
Guess problem in FreeLibrary( hModule ); you call.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
kstowell View Drop Down
Admin Group
Admin Group


Joined: 25 January 2003
Location: MIchigan, USA
Status: Offline
Points: 496
Post Options Post Options   Thanks (0) Thanks(0)   Quote kstowell Quote  Post ReplyReply Direct Link To This Post 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<
Back to Top
__BornInUssr__ View Drop Down
Newbie
Newbie


Joined: 06 April 2010
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote __BornInUssr__ Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.078 seconds.