Click to See Complete Forum and Search --> : Locating a control on a dialog


Colin Smith
September 2nd, 1999, 11:55 AM
I am attempting to locate a control on a dialog window via it's ID name.
The difficulty is caused by the fact that the name is being generated
using the following function:


/*
* Get current component : returns a pointer to the image on the
* setup map currently being processed
*/
CStatic* CqcExpSetup::GetCurrentComponent(int x, int y)
{
char ControlName[10];
sprintf(ControlName, "IDC_SM%02d%02d", x, y);

return (CStatic*) ------------(ControlName);
} /^\
|



I can't find a function to do the job of the blanked out section. I have
tried GetDlgItem(nID), however this is expecting the int value for the
control. I need a function that takes the 10 character string calculated
from the x and y co-ordinates, finds a (CStatic) control of the same name
and returns it's id number for the GetDlgItem() function call.

Either that, or I need a function that can find the CStatic control with
the calculated name, and return a pointer to it.

Thanks for any assistance.

Colin Smith

Anthony Mai
September 2nd, 1999, 02:31 PM
Resource ID names such like IDC_MY_STATIC_CONTROL are for programmers to read, internally the computer represent each resource using it's numerical resource ID, if you open the resource.h file you will see how the resource IDs are defined as numbers.

In your case, you want to deal with the numerical resource ID, not the symbolic name of them. Your code can look like this:

UINT myReourceID;

myResourceID = IDC_SM_BASE + (x*100 + y);
return (CStatic *) GetDlgItem(myResourceID);

Be careful that any mixture of x and y would yield a valid resource ID that is actually used in your dialog box.


I hate fat programs as much as I hate being fat myself. I am lean and mean and so is my program.