Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - translations not showing on toolbar for help about
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

translations not showing on toolbar for help about

 Post Reply Post Reply
Author
Message
RyanCoder View Drop Down
Newbie
Newbie


Joined: 03 July 2024
Location: Canada
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote RyanCoder Quote  Post ReplyReply Direct Link To This Post Topic: translations not showing on toolbar for help about
    Posted: 03 July 2024 at 8:24pm
I have a C++/MFC application that has a CXTPToolbar. All The tooltips when I hover over the toolbar icons show correctly except for ones with ID's "ID_CONTEXT_HELP", "ID_FILE_PRINT", "ID_HELP" and "ID_APP_ABOUT". We have an resource file (.rc file) for english and one for every other language German, French, Spanish, etc. The toolbar icon's tooltip with ID with "ID_SHIFT_LEFT" works. An example of how I set the description/tooltip text in rc files below : 

In file "AAA.rc"

STRINGTABLE
BEGIN
    ID_SHIFT_FLEFT          "Find Data Left\nFind Data Left"

ID_FILE_PRINT           "Print the active document\nPrint"
    ID_CONTEXT_HELP         "Context help\nContext help"
END

---------------------

in file "AAA_deu.rc"
STRINGTABLE
BEGIN
ID_SHIFT_FLEFT          "Verbleibende Daten suchen\nVerbleibende Daten suchen"

        ID_HELP                 "Zeigt Hilfe zum aktuellen Vorgang oder Befehl an.\nHilfe"
ID_APP_ABOUT            "Programminformationen, Versionsnummer und Urheberrechte anzeigen\nDie Info"
ID_FILE_PRINT           "Drucken des aktiven Dokuments\nDrucken"
ID_CONTEXT_HELP         "Anzeigen der Hilfe für Schaltflächen, Menüs und Fenster, die angeklickt wurden\nKontexthilfe"
END

I am assuming there is something special that XTP is doing with the toolbar buttons with these id's "ID_CONTEXT_HELP", "ID_FILE_PRINT", "ID_HELP" and "ID_APP_ABOUT"?

I have looked at XTP example program "MultiLangCommandBars" at "\Program Files (x86)\Codejock Software\MFC\Xtreme ToolkitPro v22.1.0\Samples\CommandBars\MultiLangCommandBars\" and I see this example is loading resources from xml files for each language. I tried to do something similar in my program but I don't want to ship the application with xml files. I would like the xml file contents in the resource of the executable. When I use code below it appears to work as the tooltip text is set but later in our application an error about resource with id "<string id="9148" value="\nOptionen für Symbolleisten"/>" (german xml file MultiLangCommandBars.ResourceDe.xml) is missing... If I load in the xml resource file from disk, instead of from resources in executable the tooltip works and I don't get the error about id="9148". Could this be a bug in XTP Toolkit? Is it possible to load the xml from a resource in the executable?

error is in code :


 

BOOL CXTPResourceManagerXML::LoadString(CString* pString, UINT nIDResource)

{

if (!m_bValid || m_pResourceRoot == NULL)

return CXTPResourceManager::LoadString(pString, nIDResource);

 

CString strPattern;

strPattern.Format(_T("string[@id = \"%i\"]"), nIDResource);


 // DEBUG! strPattern = L"string[@id = \"9148\"]"

if (!m_pResourceRoot->IsSectionExists(strPattern)) 

return CXTPResourceManager::LoadString(pString, nIDResource);

 

CXTPPropExchangeSection secString(m_pResourceRoot->GetSection(strPattern));

PX_String(&secString, _T("value"), *pString);

 

return TRUE;

}


I can see if I can come up a small example program if this helps.

Thanks,

Back to Top
RyanCoder View Drop Down
Newbie
Newbie


Joined: 03 July 2024
Location: Canada
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote RyanCoder Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2024 at 11:52am

CString sResXML = "<?xml version="1.0" encoding="utf-8"?>
<resource CompactMode="1" Language="German (Germany)" LANGID="1031">
<string id="57670" value="Zeigt Hilfe zum aktuellen Vorgang oder Befehl an.\nHilfe"/>
<string id="57664" value="Programminformationen, Versionsnummer und Urheberrechte anzeigen\nDie Info"/>
<string id="57607" value="Drucken des aktiven Dokuments\nDrucken"/>
<string id="57669" value="Anzeigen der Hilfe für Schaltflächen, Menüs und Fenster, die angeklickt wurden\nHilfe"/>
</resource>";
CXTPPropExchangeXMLNode xtpXMLNode(TRUE, NULL, L"resource");
xtpXMLNode.LoadFromString(sResXML);
CXTPResourceManager *pResMgr = XTPResourceManager();
if (pResMgr)
{
// commented out code below works. 
//CString strPath(_T("c:\\temp\\MultiLangCommandBars.ResourceDe.xml"));
//CXTPResourceManagerXML* p = new CXTPResourceManagerXML(strPath);
//XTPResourceManager()->SetResourceManager(p);

// Code below has errors later in our code as resource id
pResMgr->SetResourceManager(new CXTPResourceManagerXML(&xtpXMLNode));
}
Back to Top
RyanCoder View Drop Down
Newbie
Newbie


Joined: 03 July 2024
Location: Canada
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote RyanCoder Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2024 at 12:29pm
I took the sample program "MultiLangCommandBars" and replaced function "CMultiLangCommandBarsApp::SetLocale" with this code below:

BOOL CMultiLangCommandBarsApp::SetLocale(LCID Locale, LPCTSTR szLocale, LPCTSTR szFileName,
BOOL bIsRTL)
{
if (szFileName)
{
if (CXTPPropExchangeXMLNode::IsXMLSupported()) // Try to load from XML. Needs IE 4.0
   // installed
{
CString strPath;
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance,
   strPath.GetBufferSetLength(_MAX_PATH), _MAX_PATH));
strPath.ReleaseBuffer();

int nIndex = strPath.ReverseFind(_T('\\'));
if (nIndex > 0)
strPath = strPath.Left(nIndex + 1);
else
strPath.Empty();

strPath = strPath + _T("Translations\\") + szFileName + _T(".xml");

// My code changes are bolded below:
CString sResXML = L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
"<resource CompactMode=\"1\" Language=\"German (Germany)\" LANGID=\"1031\">\n" 
"<string id=\"57670\" value=\"Zeigt Hilfe zum aktuellen Vorgang oder Befehl an.\\nHilfe\"/>\n"
"<string id=\"57664\" value=\"Programminformationen, Versionsnummer und Urheberrechte anzeigen\\nDie Info\"/>\n"
"<string id=\"57607\" value=\"Drucken des aktiven Dokuments\\nDrucken\"/>\n"
"<string id=\"57669\" value=\"Anzeigen der Hilfe für Schaltflächen, Menüs und Fenster, die angeklickt wurden\\nHilfe\"/>\n"
"</resource>";

CXTPPropExchangeXMLNode xtpXMLNode(TRUE, NULL, L"resource");
xtpXMLNode.LoadFromString(sResXML);
CXTPResourceManager* pResMgr = XTPResourceManager();
if (pResMgr)
{
// commented out code below works. 
//CString strPath(_T("c:\\temp\\MultiLangCommandBars.ResourceDe.xml"));
//CXTPResourceManagerXML* p = new CXTPResourceManagerXML(strPath);
//XTPResourceManager()->SetResourceManager(p);

// Code below has errors later in our code as resource id
pResMgr->SetResourceManager(new CXTPResourceManagerXML(&xtpXMLNode));
}

//if (!XTPResourceManager()->SetResourceManager(new CXTPResourceManagerXML(strPath)))
// return FALSE;
}
else
{
CString strPath;
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance,
   strPath.GetBufferSetLength(_MAX_PATH), _MAX_PATH));
strPath.ReleaseBuffer();

int nIndex = strPath.ReverseFind(_T('\\'));
if (nIndex > 0)
strPath = strPath.Left(nIndex + 1);
else
strPath.Empty();

strPath = strPath + _T("Translations\\") + szFileName + _T(".dll");

XTPResourceManager()->SetResourceManager(new CXTPResourceManager());
XTPResourceManager()->SetResourceFile(strPath);
}
}
else
{
if (!XTPResourceManager()->SetResourceManager(new CXTPResourceManager()))
return FALSE;
}

::SetThreadLocale(MAKELCID(Locale, SORT_DEFAULT));
::_tsetlocale(LC_ALL, szLocale);

m_curLanguage = Locale;
SetRTLLayout(bIsRTL);
ReloadDefaultMenu();
return TRUE;
}
lpszSection = 0x0000024069d50cd8 L"menu[@id = \"129\"]"


BOOL CXTPPropExchangeXMLNode::IsSectionExists(LPCTSTR lpszSection)
{
if (!OnBeforeExchange())
return FALSE;

CXTPDOMNodePtr xmlNodePtr;

// Exception is thrown here:
HRESULT hr = m_xmlSectionNode->raw_selectSingleNode(CT2BSTR(lpszSection), &xmlNodePtr);

if (FAILED(hr) || xmlNodePtr == NULL)
return FALSE;

return TRUE;
}

When I run the application I get the exception below:

Exception thrown at 0x00007FFD2D03F2E2 (msxml3.dll) in MultiLangCommandBars.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

CallStack:

> msxml3.dll!Model::Model(struct TLSDATA *,class Object *) Unknown
  msxml3.dll!OMReadLock::OMReadLock(struct TLSDATA *,class DOMNode *) Unknown
  msxml3.dll!DOMNode::selectSingleNode(unsigned short *,struct IXMLDOMNode * *) Unknown
  MultiLangCommandBars.exe!CXTPPropExchangeXMLNode::IsSectionExists(const wchar_t * lpszSection) Line 756 C++
  MultiLangCommandBars.exe!CXTPResourceManagerXML::LoadMenuW(CMenu * lpMenu, unsigned int nIDResource) Line 1213 C++
  MultiLangCommandBars.exe!CMainFrame::ResetCommandBars() Line 161 C++
  MultiLangCommandBars.exe!CMultiLangCommandBarsApp::ReloadDefaultMenu() Line 391 C++
  MultiLangCommandBars.exe!CMultiLangCommandBarsApp::SetLocale(unsigned long Locale, const wchar_t * szLocale, const wchar_t * szFileName, int bIsRTL) Line 291 C++
  MultiLangCommandBars.exe!CMultiLangCommandBarsApp::OnLanguageGerman() Line 316 C++
  MultiLangCommandBars.exe!CMultiLangCommandBarsApp::InitInstance() Line 166 C++
  [External Code]
  MultiLangCommandBars.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26 C++
  [External Code]

Does anyone have an idea's on what is wrong?

Thanks,
Back to Top
RyanCoder View Drop Down
Newbie
Newbie


Joined: 03 July 2024
Location: Canada
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote RyanCoder Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2024 at 4:00pm
Fyi - I figured out the problem with why our program was crashing after loading the xml file contents from a xml resource file in the executable. I was declaring the "xtpXMLNode" as a local variable. It needed to be an allocated object that doesn't get deallocated until CXTPResourceManager gets closed/destroyed...


Fixed example code is below:

CString sResXML = L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
"<resource CompactMode=\"1\" Language=\"German (Germany)\" LANGID=\"1031\">\n" 
"<string id=\"57670\" value=\"Zeigt Hilfe zum aktuellen Vorgang oder Befehl an.\\nHilfe\"/>\n"
"<string id=\"57664\" value=\"Programminformationen, Versionsnummer und Urheberrechte anzeigen\\nDie Info\"/>\n"
"<string id=\"57607\" value=\"Drucken des aktiven Dokuments\\nDrucken\"/>\n"
"<string id=\"57669\" value=\"Anzeigen der Hilfe für Schaltflächen, Menüs und Fenster, die angeklickt wurden\\nHilfe\"/>\n"
"</resource>";
pXtpXMLNode = std::make_unique<CXTPPropExchangeXMLNode>(TRUE, NULL, L"resource");
pXtpXMLNode->LoadFromString(sResXML);
CXTPResourceManager* pResMgr = XTPResourceManager();
if (pResMgr)
{
CXTPPropExchangeXMLNode *ppp = pXtpXMLNode.release();
XTPResourceManager()->SetResourceManager(new CXTPResourceManagerXML(ppp));
}


Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 273
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 11 July 2024 at 4:26am
Hello,

Have you solved your problem?

Regards,
Artem Gontarenko
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.172 seconds.