Click to See Complete Forum and Search --> : Using String Table in MFC Dialog App


adaca
December 6th, 2003, 11:56 PM
I am currently writing a simple MFC application in .Net 2003.
I am writing a simple room similar to the text adventure games we all grew up with. I have included all the desciptions in a string table already started by the MFC Dialog Wizard. The problem I am running into, is I have a static text box on my dialog window that I want to initialize with one of the strings and update them as the user selects different radio buttons to tell the user what to do inside the room. I've tried a couple different things, but it seems the string table passes back the ID number as an int when a string is expected. I think I might have to use LoadString, but am running into problems learning how to use that. The examples aren't working for my program. Any help on this, or would it help to include some code? (being my first MFC app, my code is really large for some reason; probably a lot of useless stuff)
Thanks in advance!

vicodin451
December 7th, 2003, 11:45 AM
LoadString is what you need:
String table from RC file is:

STRINGTABLE DISCARDABLE
BEGIN
IDS_MYSTRING "This is my string"
END


use like:

CString strMyStr;
strMyStr.LoadString( IDS_MYSTRING );
AfxMessageBox( strMyStr );


You can also construct a CString from a string resource:

CString strMyStr( MAKEINTRESOURCE( IDS_MYSTRING ) );
AfxMessageBox( strMyStr );

adaca
December 8th, 2003, 08:56 AM
I believe the code you gave me was the one I am tempted to resort to. If it is the same one, it brings up a message box with the string, correct? What I am kind of looking for is:
I created the main window with some sort of a static text box. It defaults a caption from the beginning (for a beginner programmer, you would create a window with a text box and change the caption to 'Hello World'). Right now, I have no caption and on initialization of the window, I want to assign the caption to be one of the string table strings.
I believe I worded my original question bad. Sorry.
Thanks!

vicodin451
December 8th, 2003, 09:02 AM
Is this what you're looking for?

CString strMyStr( MAKEINTRESOURCE( IDS_MYSTRING ) );
// to set the text for the static control...
StaticCtrlInstance.SetWindowText( strMyStr );
// or, to set the text for a CWnd-derived class from a member function
SetWindowText( strMyStr );