Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you get the integer value from a control ID

Status
Not open for further replies.

ed9871

Programmer
Jan 15, 2002
14
0
0
US
I am providing a way for the user to customize some screen settings, and I am storing the control IDs in a database as strings, ie "IDC_EDIT_BOX", etc. Is there any way I can take my string and use it as a constant? For example if I have:

CString m_sControl="IDC_EDIT_BOX";

I want to be able to do:

GetDlgItem(IDC_EDIT_BOX)->EnableWindow(TRUE);

Is there any way to change my string into a constant or am I going about this the wrong way?

Ed
 
The IDxxx are #defined in resource.h. That means, the compiler only sees the values instead of the names. Therefore, you have to to use the integer value instead. If you really have to use the name, you have to map the name to the integer value in your program.

For example:
[tt]
#include "resource.h"

struct ResourceIDtoName
{
int nID;
LPCTSTR lpszName;
};

#define RESOURCE_ID_NAME(x) { x, #x }

ResourceIDtoName IDtoName[] =
{
RESOURCE_ID_NAME(IDC_EDIT_BOX),
RESOURCE_ID_NAME(IDC_COMBO_BOX),
...

{0, NULL}
};
[/tt]
In your code, you can write code to lookup ID from name or vice versa.

HTH
Shyan
 
Thats what I was afraid of, I was hoping for an stoc() or some other function I didn't know about. Thanks very much!

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top