Advertisement

Getting the info out of string tables..

Started by January 21, 2001 03:47 AM
2 comments, last by Quantum 24 years ago
Anyone know how to get information out of the string table that MSVC resource editor creates when you set the Prompt field of a menu item? I want to be able to display that info when the mouse is over a specific menu item, which I can do, but it''s a pain to have a huge switch statement and set the status text in this.
I''m not sure how clear this is going to be, but here goes.

All strings in a String table have some numeric identifier, such as 100, 101, 102, 103... etc. So do menu items.

What you need to do is to create the string table to match the elements in the menu.

Let''s say you have a menu

File
--New IDM_NEW (100)
--Open IDM_OPEN (101)
--Exit IDM_EXIT (102)

Your corresponding string table should be declared like something like this

"New item" IDS_NEW 200
"Open existing Item" IDS_OPEN 201
"Exit the program" IDS_EXIT 202

When you handle the message for selecting a menu item, you''ll get the ID of the Menu item being selected (we''ll store it in uMenuID).

Now minus the value of IDM_NEW from uMenuID so that we get the id of the menu item starting from 0, instead of 100.
uMenuID -= IDM_NEW;

Now, if IDM_NEW was selected, the uMenuID will be 0, if it was IDM_EXIT, the uMenuID will be 2.

So, in order to load the appropriate string, call LoadString(hInst, IDS_NEW + uMenuID, szBuffer, nBufLen);

That ought to do the trick. You should be able to get the general picture from there.

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
Sweet, I got it working thanks a lot.
Although I don''t know what your logic is in subtracting IDM_NEW from uMenuID then adding it when you call LoadString, especially because uMenuID is unsigned, and when nothing is selected it will contain 0, subtracting 100 might not be the best thing to do
I don't have my MSDN CDs with me (stupid lab computers), but I think there's something like WM_MENUSELECT that gets sent when you move your mouse over the menu items.

based on my previous example, when you select IDM_NEW, what we should do is store the LOWORD(wParam) in uMenuID. That means that the ID of the menu being selected is stored in uMenuID, in this case 100 (IDM_NEW).

Then we minus IDM_NEW from uMenuID, so that we get the ID of the Menus starting from 0, thus IDM_NEW will be 0 (100 - 100), IDM_OPEN will be 1 (101 - 100), and IDM_EXIT will be 2 (102 - 100).

So when you call LoadString(hInst, IDS_NEW + uMenuID, szBuffer, nBufLen);, you'll load correct string.

Here's a trace (virtual, of course

If IDM_NEW is selected, uMenuID will be 0 (100 - 100). IDS_NEW + uMenuID will result in 200, which is what we want.

if IDM_OPEN is selected, uMenuID will be 1 (101 - 100). IDS_NEW + uMenuID will result in 201, which corresponds to IDS_OPEN.

If IDM_EXIT is selected, uMenuID will be 2 (102 - 100). IDS_NEW + uMenuID will result in 202, which corresponds to IDS_EXIT.

That does work. I've implemented it before Hope I made that clearer this time.


{ADDENDUM}
If nothing is selected, WM_MENUSELECT will not be sent, thus this whole fragment of code will not be processed. So we're quite safe. No subtracting 100 from 0 in an unsigned integer.



Edited by - NuffSaid on January 21, 2001 11:59:06 AM
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

This topic is closed to new replies.

Advertisement