How to Load a String, passing in the ID of the resource, not the name?

Hello,

I would like to get the Caption for a String, from the String table,
by passing in the value of the String, not the ID of it.

For example, the String in my String table is:
(ID)IDS_STRINGEXAMPLE
(Value)105
(Caption) This is the text of the example

But I have many different strings in this table and in my code I want
to be able to get the String by passing in the int value of the
resource but I don't know how to do this?? (ie I want to pass a
variable such as 105, 1o6 etc to a function, not the IDS_STRINGTABLE
etc)

I know CString::LoadString(IDS_STRINGEXAMPLE) will give me what I need
by passing in the resource name/ ID but I want the same functionality
by passing in the integer value, ie something like :
CString::LoadStringFromID(105); - does such a function exist???


Thanks in advance for any help on this!
0
1/14/2005 3:57:53 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
712 Views

Similar Articles

[PageSpeed] 6

Suppose I have a function that I want to use to set a caption, 

void CWhatever::MySetCaption(UINT id)
   {
     CString s;
     s.LoadString(id);
     SetWindowText(s);
   }

LoadString does what you want! It would make no sense to pass a literal such as "105" to a
function because 105 has no particular meaning. So I might write something like

switch(whatever)
     {
       case something:
           MySetCaption(IDS_SOMETHING);
           break;
      case anything:
           MySetCaption(IDS_ANYTHING);
           break;
      case somethingelse:
           MySetCaption(IDS_SOMETHING_ELSE);
           break;
     }

Remember that the preprocessor has ALREADY converted
	LoadString(IDS_STRINGEXAMPLE);
to
	LoadString(105)
so what did you think IDS_STRINGEXAMPLE stands for? It stands for 105!
				joe

On 14 Jan 2005 07:57:53 -0800, mary_o_keeffe@yahoo.com (Mary) wrote:

>Hello,
>
>I would like to get the Caption for a String, from the String table,
>by passing in the value of the String, not the ID of it.
>
>For example, the String in my String table is:
>(ID)IDS_STRINGEXAMPLE
>(Value)105
>(Caption) This is the text of the example
>
>But I have many different strings in this table and in my code I want
>to be able to get the String by passing in the int value of the
>resource but I don't know how to do this?? (ie I want to pass a
>variable such as 105, 1o6 etc to a function, not the IDS_STRINGTABLE
>etc)
>
>I know CString::LoadString(IDS_STRINGEXAMPLE) will give me what I need
>by passing in the resource name/ ID but I want the same functionality
>by passing in the integer value, ie something like :
>CString::LoadStringFromID(105); - does such a function exist???
>
>
>Thanks in advance for any help on this!

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
1/14/2005 6:30:14 PM
CString::LoadString takes an integer as the parameter!  IDS_STRINGEXAMPLE
and 105 are one of the same.  True that IDS_STRINGEXAMPLE is not a number
but since it is a #define it turns into a number at compile time.  Hence
everywhere you use IDS_STRINGEXAMPLE in your program will be replaced with
105.

AliR.

"Mary" <mary_o_keeffe@yahoo.com> wrote in message
news:9755e141.0501140757.5524470@posting.google.com...
> Hello,
>
> I would like to get the Caption for a String, from the String table,
> by passing in the value of the String, not the ID of it.
>
> For example, the String in my String table is:
> (ID)IDS_STRINGEXAMPLE
> (Value)105
> (Caption) This is the text of the example
>
> But I have many different strings in this table and in my code I want
> to be able to get the String by passing in the int value of the
> resource but I don't know how to do this?? (ie I want to pass a
> variable such as 105, 1o6 etc to a function, not the IDS_STRINGTABLE
> etc)
>
> I know CString::LoadString(IDS_STRINGEXAMPLE) will give me what I need
> by passing in the resource name/ ID but I want the same functionality
> by passing in the integer value, ie something like :
> CString::LoadStringFromID(105); - does such a function exist???
>
>
> Thanks in advance for any help on this!


0
AliR1 (391)
1/14/2005 7:05:34 PM
Reply:

Similar Artilces:

Any XML Naming Conventions?
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and so on? Any referrals to resources that discuss or document XML Naming Conventions? -- <%= Clinton Gallagher, "Twice the Results -- Half the Cost" Architectural & e-Business Consulting -- Software Development NET csgallagher@REMOVETHISTEXTmetromilwaukee.com URL http://www.metromilwaukee.com/clintongallagher/ clintonG wrote: > Does the use of DTD, X...

Change of recipient/sender display name
Hi All, Environment :- Windows 2003 x64 with exchange 2007 (All in one role) Outlook client :- 2003, 2007 We have created a list of mail contacts (which under GAL) in exchange 2007, these mail contacts are associates with external email address, each of contact has a naming standard for display name, for example, display name is HD Finance Manager, external email address is fin_manager@hdemea.com I want to configure outlook client to show the display name according to mail contacts whenever the email address is match to mail contacts list (GAL), for example, an email sent from the email a...

Exporting file names to an excel spreadsheet.
I have a folder containing many many many .pdf files. Is there a way to export the filenames of these .pdf files into an excel spreadsheet? If this is a dumb question, I apologize. I didnt have any luck searching for the answer here. -- Kepf ------------------------------------------------------------------------ Kepf's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30611 View this thread: http://www.excelforum.com/showthread.php?threadid=547520 I use Jim Cone's fine Add-in called "ListFiles"for this sort of thing. It's available free (a...

cell looses name after sorting
Can someone help me with the following problem in Excel 2000: in a table I have attached serveral cells with unique cell names, the values in these cells are used in other sheets. the problem is that when I sort the table, the cell names stay in the original rowposition; they are not sorted! while their values are. So Cell names get different values, and other calculations on my other sheets get messed up! How can I make the cell names relative instead of absolute? thankx in advance, Jim --- Message posted from http://www.ExcelForum.com/ "jimfx >" <<jimfx.109zcv@exc...

Splitting First and Last Names
I have a spreadsheet where the Name feild contains both first and last names. I want to split this into two fields. How can I do this? Hi use 'Data - Text to<columns' for this -- Regards Frank Kabel Frankfurt, Germany Jamie wrote: > I have a spreadsheet where the Name feild contains both first and last > names. I want to split this into two fields. How can I do this? "Jamie" <pastorjman310@hotmail.com> wrote >I have a spreadsheet where the Name feild contains both >first and last > names. I want to split this into two fields. How can I do &g...

Subform in Datasheet View
Is there a way to have the datasheet view of a subform *not* show the "button-like" row that shows the field names? -- Thanks, tbl No there isn't. If you create a continuous style form, you can eliminate the headings. You can modify a continuous form so that it looks like a 'datasheet'. -- Joan Wild Microsoft Access MVP "tbl" <hateThatSpam@invalid.net> wrote in message news:4gqs13dds31nhu1bsmbrm5tt86adbfea1m@4ax.com... > Is there a way to have the datasheet view of a subform *not* > show the "button-like" row that shows the field n...

Passing a variable as a parameter value instead of a literal string to a child report?
In the Navigation section (Jump to URL), I have the following: ="javascript:void(window.open('http://localhost/reportserver?/Reports +Folder/My +Report&rs:Command=Render&StartDate=01/01/2009&FinishDate=12/31/2010'))" This works as designed - a new window pops up with the "My Report" report and the StartDate and FinishDate of 01/01/2009 and 12/31/2010 are passed respectively. But what is the syntax for changing the "01/01/2009" and "12/31/2010" to variables that point to the StartDate and FinishDate parameters of the PAR...

how to save a resource
Hello, my program creates for example a PHP script file. So I can crete a file by CFile and than use CFile::Write method. It's clear. But because this file is quite long, I had this idea. Save this file to resources and when I will need create this file, just load this file from resources and save it to disk. Is it possible? I really do not how :-( Thank you for your advice Robert See Using Text File Resources in VC++ By DGoins http://www.codeproject.com/cpp/usingtextfile_resources.asp -- Un saludo Rodrigo Corral Gonz´┐Żlez [MVP] microsoft.public.es.vc FAQ http://vcfaq.europe.w...

Filter records that include certain text strings
I want to create customized reports where a user can enter text strings, then the program will search for all records that contain that text string and display them. The filter functions are exclusive. -- W Dean Welch On Jul 6, 6:34 pm, Dean Welch <wdeanwe...@bellsouth.net> wrote: > I want to create customized reports where a user can enter text strings, then > the program will search for all records that contain that text string and > display them. The filter functions are exclusive. > -- > W Dean Welch In the same field? Just pass a filter in the open event of the ...

Application hanging on file load...
Okay, I'm having the strangest problem, and I'm hoping somebody here will be able to give me an idea of how to attack it... I have an MFC application that does some networked communication, multi-threading, fun stuff... I also load and save xml configuration files. Now, on most of the computers I've run my software on, I have absolutely no problems. On SOME boxes, however, whenever I use my menu to try to load or save a file... before the File Dialog box even comes up... the application hangs. All the boxes I've tried this on have been Windows 2000 boxes with Service Pack 4....

Forcing String Literal as Wide Character Unicode
Hello, I am under the impression that using _T("...") will convert my string literal to either a char or a wchar depending on what is defined, but I would like to force my string literal to be a Unicode String ( i.e wchar_t ) How would I do that? Would it be something like: wchar_t string[] = "hi"; something like that? Or is there a way to force my literal string to be unicode? "sleeper" <TheFakeJon@gmail.com> wrote in message news:1159489470.136737.259600@b28g2000cwb.googlegroups.com... > Hello, I am under the impression that using _T("...&q...

MSExchangeIS Event ID 9556
One user suddenly couldn't connect to the Exchange server (SBS 2003). Other users could log in to his PC and get their mail, and he could get his mail if he logged into another PC. (Although I'd like to know why on some other PCs he could go right into it, and one others he had to set up an Exchange account. It did not matter if the PC had 2k or XP. There are no roaming profiles.) I thought it might be a corrupt profile, so I deleted his Windows profile on his PC and created a new one, but it made no difference. (I don't know if the MAPI profile is part of the Windows profile ...

Comparing first and last names in two lists
I have two data sources that each contain about 8000 names in seperate fields for first and last name. I can put them on seperate worksheets or append one to the other. I need to make them match and find out where they don't. Messed with consolidate but not sure if that will work for more than one column at a time. FYI data set one is from a school transportation database and data set two is from the main student database from the same school district. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages dir...

Problems with loading xml from XmlTextWriter
I use an XmlTextWriter to generate xml data. The declaration is: System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); XmlTextWriter w = new XmlTextWriter(sw); And I write to it using .... w.WriteElementString("foo","bar"); When the creation is done, I need to load it into DOM to select an XmlNode or an XmlElement to apply to another method (which I cannot control). I thought I could do it with: XmlDocument xDoc = new XmlDocument(); xDoc.Load(sb.ToString()); XmlNode node = xDoc.SelectSingleNode(&...

Change License / Company name
Hi, we tried CRM 1.2 with the MSDN license key. Now my company bought a 25 user Proffesional Suite license and I want to change the key on the production server. Is there an easy way to do this?? The only solution I see, is via the Data Migration Framework. Erik. How about the re-deploy tool? "Erik" <none> wrote in message news:u0SXdbXlEHA.3452@TK2MSFTNGP15.phx.gbl... > Hi, > we tried CRM 1.2 with the MSDN license key. Now my company bought a 25 > user > Proffesional Suite license and I want to change the key on the production > server. Is there an easy wa...

what is the name of a sub form download from microsoft website
i need to add a sub form to a form created in access. i tried to start the wizard but the feature is not currently installed. i try to install but it is looking for a disk for me to insert. i do not have a disk to insert. can i go to microsoft website and download the sub form feature for access? if yes, what is the name of the download. Are you sure it is not installed? Open your main form in design view. Click the Toolbox button in the menu at the top. There are two buttons at the top of the Toolbox, an Arrow and a wand. Is the Wand highlighted. If not, click on it then click on th...

New Named Range Created Each Time Data Imported into Excel via Macro
I have noticed that each time I import data into an Excel spreadsheet via a macro, a new named range (for the same range) is created. This does not pose a problem, but after a while, I'll have a huge number of named ranges that will never be used. Why does Excel name the range and how can I stop this? I noticed in the recorded macro, there was a line .Name = "drd_5". I commented this out to see what would happen, but it just renamed the range "ExternalData_5". The next one was "ExternalData_6", etc. Thanks, Carroll Rinehart You could refresh with differen...

Event ID 9554
Hello, I'm getting the following error on two Win2k3 Standard edition servers, running MS Exchange 2003 enterprise edition, every 30 minutes. The servers are in two different sites in two seperate physical location. Both Exchange servers are in the same Exchange Admin group. The second Exchange server is not used in production and runs on a DC (I'm aware this is not best practice. Limited budget.). Event Type: Warning Event Source: MSExchangeIS Event Category: General Event ID: 9554 Date: 11/1/2005 Time: 5:25:22 AM User: N/A Computer: CONTEX01 Description: Unable to updat...

ComboBox passing values from selected
In my form (Items_frm) I have a combo box (Itemcbx) that displays 4 columns (Item, Makebuy, Revision, IsActive) but is bound to the first column. However, I would like to pass the other values from the remaining columns to other fields in my form after the selection. Is this possible? Can someone provide a sample code? You can use the Column() attribute. Me.Itemcbx.Column(1) etc. Note that the index for combo box columns is zero-based so 0 is the first, 1 is the second and so on... Steve "Angel G" wrote: > In my form (Items_frm) I have a combo box (Itemcbx) that displ...

OWA Inbox hangs at Loading...
I have Exchange 2000 sp3 sitting on a Win2000 Server sp4. Exchange works well, except when trying to access via OWA. the users can log in alright, when asked, but then all that loads is the buttons at the top of the page and the folder links on the right hand side. The inbox stops loading at Loading... any help would be appreciated... thanks Tony. I'm having this same problem with a server in our test lab. Although it didn't help me, see http://support.microsoft.com/default.aspx?scid=kb;en-us;280823 - maybe it will solve your problem. I even did a reinstall with no luck. I...

Named ranges
Excel 2003 I have a total sheet that gets data from three different shift sheets (all in the same workbook) for a monthly report. I have named ranges on each shift sheet for each month's production data (S1M1, S1M2, S1M3, S2M1...) where S1M1 =A2:AC147, S1M2 = A148:AC329, etc. The old formula was:=SUMIF('SHIFT 1'!$L$1:$L$147,"BB",'SHIFT 1'!$T$1:$T$147). I'm stumped as to what the new formula would be - how would I direct Excel to column L of S1M1 to search for "BB", then add the contents of column T? The range changes each month, and I tho...

DAO, Access, zero-length strings?
How can you set that you want to allow zero-length strings in a MS Access database with DAO? Also, how can you set that you want default values? Access doesn't seem to allow "DEFAULT" property... ...

name badge labels
Now we have Office 2007 and I cannot figure out how to create a sheet of name badge labels. Are you using mail merge? If you are, select the your label from the page setup. If you are manually typing your badge labels, measure your labels and setup your page with grid guides. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Carol in Texas" <CarolinTexas@discussions.microsoft.com> wrote in message news:626CC158-3AF1-4809-9BCE-C54E1FF42861@microsoft.com... > Now we have Office 2007 and I cannot figure out how to...

NDR's not being received, EVENT ID 1028 ist not fullfilled
The sender of an message does not receive the NDR. But the administrator is informed successfully. The Event ID shows successful EVENT ID=B4s in this order: 1025 Sender OK 1025 Administrator OK 1024 Sender OK 1024 Administrator OK 1033 Sender OK 1033 Administrator OK 1021 Sender OK 1021 Administrator OK 1036 Sender OK 1036 Administrator OK 1023 Sender OK 1023 Administrator OK 1028 Administrator OK The sender does not get an successful 1028 and does not receive the NDR. Any clues? Best regards, GS. I solved this issue. There were two accounts with the same email adress. Error Mes...

Import excel named range into Access error 3011
Hi, I've read a few posts on this topic, but none addresses my particular problem. I use Office 2003 on an XP SP3 machine. I am using transferspreadsheet to import a named range in an excel file into Access. This has worked beautifully until suddenly it stopped working. I find now that if I extract the address of the named range from within the Access VBA code, it looks like this: =#REF!$A$1:$Z$166 rather than this, which is what it should be: =Data!$A$1:$Z$166 When I open the spreadsheet and get the address of the named range in the immediate window, it also has the #REF error....