|
Hi,
I'm having difficulties using CString's LoadString under VC++ 8.0. I'm not sure what to make of it. I'm attempting to load a string from resources and getting back an incomplete string, e.g. "This application is registered to %1 %2For use on the computer named %3 only." and getting back, "This application is registered to %1????". The '?' are inserted into the string. I'm a total newbee to VC++ 8.0.
It seems to be random, cause loading strings from the resource seems to work correctly in the instances above the lines of code before calling the last LoadString.
e.g.
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString cs0, cs1, cs2, cs3, cs4;
DWORD dwSizeUserName, dwSizeComputerName, dwError;
char szUserName[MAX_COMPUTERNAME_LENGTH + 1];
char szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
dwSizeUserName = MAX_COMPUTERNAME_LENGTH + 1;
dwSizeComputerName = MAX_COMPUTERNAME_LENGTH + 1;
szUserName[0]=0;
szComputerName[0]=0;
m_nAppIcon.SetIcon(::LoadIcon(theApp.m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)) );
cs0.Empty();
cs0.LoadString(AFX_IDS_APP_TITLE);
AfxSetWindowText(::GetDlgItem(this->m_hWnd, IDC_STATICTEXTAPPNAME), cs0);
cs0.Empty();
cs1.Empty();
cs2.Empty();
cs3.Empty();
cs4.Empty();
cs1.LoadString(IDS_STRABOUTAPPINFO);
// IDS_STRABOUTAPPINFO =
// File Version: %s\nProduct Version: %s\nApplication Info: %s\n\n%s by
// %s. All Rights Reserved.
cs2.LoadString(IDS_FILEINFOCOMMENTS);
// IDS_FILEINFOCOMMENTS = Comments
cs3.LoadString(IDS_FILEINFOLEGALCOPYRIGHT);
// IDS_FILEINFOLEGALCOPYRIGHT = LegalCopyRight
cs4.LoadString(IDS_FILEINFOCOMPANYNAME);
// IDS_FILEINFOCOMPANYNAME = CompanyName
cs0.Format( cs1,
CAppUtilitylFunctions::GetFileVersionX(),
CAppUtilitylFunctions::GetProductVersionX(),
CAppUtilitylFunctions::GetVersionInfo(NULL, cs2),
CAppUtilitylFunctions::GetVersionInfo(NULL, cs3),
CAppUtilitylFunctions::GetVersionInfo(NULL, cs4));
AfxSetWindowText(::GetDlgItem(this->m_hWnd, IDC_STATICTEXT1), cs0);
if( !(::GetUserName(szUserName, &dwSizeUserName)) )
{
dwError = GetLastError ();
}
if( !(::GetComputerName(szComputerName, &dwSizeComputerName)) )
{
dwError = GetLastError ();
}
else
{
cs0.Empty();
cs1.Empty();
// THIS LOAD FAILS TO LOAD ALL OF THE STRING IN THE RESOURCE
cs1.LoadString(IDS_ABOUTAPPINFO);
// IDS_ABOUTAPPINFO =
// This application is registered to %1 %2For use on the computer
// named %3 only.
cs0.FormatMessage( cs1,
szUserName,
"\n",
szComputerName);
AfxSetWindowText(::GetDlgItem(this->m_hWnd, IDC_STATICTEXT2), cs0);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Can someone shed some light on this for me? I'm thinking that it must have something to do with project settings....
Thanks!
Jon68z
|
|
|
|
|
Jon68z wrote: // THIS LOAD FAILS TO LOAD ALL OF THE STRING IN THE RESOURCE
cs1.LoadString(IDS_ABOUTAPPINFO);
// IDS_ABOUTAPPINFO =
// This application is registered to %1 %2For use on the computer
// named %3 only.
Can you check its return value ? Its BOOL .
To narrow down the problem , can you check value in cs1, by showing it in message box?
|
|
|
|
|
Hi,
Thanks for the reply. using bool bRet, e.g. bRet = cs1.LoadString(IDS_ABOUTAPPINFO); The return value is 'true'. The string returned however is truncated and contains, cs1 "This application is registered to %?????" ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > as reported in the VC++ 8.0 IDE 'Autos' tab.
If I use a line like 'CString cs5(MAKEINTRESOURCE(IDS_ABOUTAPPINFO));' cs5 is equal to the same malformed string as if I loaded it from the resource string table above.
Do I have to specify something in my project settings ?
Or is something getting screwed up in the string table....
Thanks!
Jon68z
|
|
|
|
|
Problem seems to be with format specifiers you have mentioned. Can you see same problem with strings without format specifiers(%).
|
|
|
|
|
Hi,
Thanks for your reply. Actually, if I move the string loading to the top of the function, it works correctly. The entire string is loaded. I've tried several locations to narrow down where the load string gets truncated, but have not found the problem.
This is driving me mad, as I know something else is wrong, and it is not LoadString() per se, but have not been able to find the problem.
Thanks!
Jon68z
|
|
|
|
|
Hi,
I've changed the previous Format to FormatMessage and the specifiers to %1, %2, %3, etc. and all seems to be fine with the string loading as it should. It is hard for me to believe that using CString Format could screw up memory on an unrelated LoadString.... Hmmm.
Any body have any ideas on this?
Please help....
Thanks!
Jon68z
|
|
|
|
|
There is difference bet'n Format and FormatMessage , the way format specifiers are mentioned.
::FormatMessage documentation in MSDN can through some light on it.
Jon68z wrote: It is hard for me to believe that using CString Format could screw up memory on an unrelated LoadString.... Hmmm.
Actually , instead of using same variable(using Empty ), try using different variables.(this is just wild try).
|
|
|
|
|
Hi,
I have a CPropertySheet embeded in a CPropertyPage.
Can anyone tell me how to move or size the embeded property sheet?
Thanks in advance
Ferdinand
|
|
|
|
|
Hi everyone,
I have again question I read about Certification from microsoft MCAD/MCSD
here[^] but i want to know
for which languages is it for VC++
|
|
|
|
|
You should read the full page, in particular the content of the exams. ASP.NET, VB.NET, C#.NET... Think of .NET as an extension to all of the programing languages.
|
|
|
|
|
Thanks waldermort for help i read full page but i cant find that VC is in these exams or not and i want to know do you have any document for VC like document for C# or ASP.NET
|
|
|
|
|
Hi everyone,
When i want to open my project i get this error
Project 'C:\MyBook\MyBook.vcproj' failed to open.
Thanks
|
|
|
|
|
try deleting all of the extra files that VS adds to the directory. But make sure not to delete the .dsp and .dsw files.
|
|
|
|
|
I dont have .dsp or .dsw i use VS2003 which files i need to delete
|
|
|
|
|
Hi,
I want to get the active childframe in a MDI application when I am in the ViewClass. I need a pointer of CWnd to use it as parameter for MDIActivate.
Can someone tell me how to get it?
Thanks for help
yummi
|
|
|
|
|
Hello
1- CWnd::GetActiveWindow() . Doesn't it work with you?
2- Or even better CWnd::GetTopWindow() .
Regards
|
|
|
|
|
Hi Nader,
thanks for your reply. So I got the window, but I can't use it for what I want to do.
In my MDI application I open new childframes automaticly but I want to stay the actually childframe in front.
I tried this way:
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CErgebnislisteView *pView = (CErgebnislisteView *) pChild->GetActiveView();
for(i=0; i< arrVerz.GetSize(); i++)
{
theApp.OnOldTurnier();
}
pChild->SetActiveView(pView);
Do you have an idea how do do it?
yummi
|
|
|
|
|
yummi wrote: CErgebnislisteView *pView = (CErgebnislisteView *) pChild->GetActiveView(); //Open new childframes for(i=0; i< arrVerz.GetSize(); i++) { //set some variables and open it with the next line theApp.OnOldTurnier(); } //activate the old childframe pChild->SetActiveView(pView); //nothing happens
pView is already active view. why you are setting it to active again. It must be working.
|
|
|
|
|
Hi Prasad,
thanks for your reply. I want to reach, that after I opened a few new childframes, that the chilframe that was on top before I open the new ones, is on top again. With the line pChild->SetActiveView(pView) I tried to reach it.
grettings
yummi
|
|
|
|
|
Hi Pasrad,
with your hint I find the solution. Thank you very much.
Before I open the new childframes I get the state of the childframe with
pChild->GetWindowPlacement(&lpwndpl);
and after I opened the new childframes I only do
pChild->SetWindowPlacement(&lpwndpl);
That works
Many Many Thanks
|
|
|
|
|
welcome.
yummi wrote: Hi Pasrad
I hope,you want to say 'Prasad',
|
|
|
|
|
Thanks
modified 28-Sep-16 7:30am.
|
|
|
|
|
You probably need to call ShowWindow for your controls after you create them.
Software Zen: delete this;
|
|
|
|
|
Hi all,
i play a sound using:
PlaySound(MAKEINTRESOURCE(IDR_WAVE),AfxGetInstanceHandle(),SND_PURGE | SND_RESOURCE | SND_ASYNC);
i stop this sound using:
PlaySound(NULL,AfxGetInstanceHandle(),SND_PURGE | SND_RESOURCE | SND_ASYNC);
But when i call the above line again (PlaySound with NULL), the sound is being played again
is there a way to avoid this problem?
thanks
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hi all,
all the links that appear in CRichEdit Ctrl are based on the window scheme i am using.
is there a way to tell the rich edit that all my link will apear in a blue color regardless the window scheme i am using?
thanks in advanced
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|