Hi All
I have Dialog include 20 pictures, on dialog initializing I try to take them off.
i write this code:

CString tempname, tempnum; // define temporary name and number
char tempvar [10]; // define temporary variable
for (int x=1;x<=20;x++) // x picture location 
{
tempname="IDC_"; // IDC_1...IDC_20
itoa(x,tempvar,10); // convert int to char
tempnum=tempvar; // convert char to CString 
tempname = tempname + tempnum; // building CStrting include the suitable IDC_: IDC_1 to IDC_20 
AfxMessageBox(tempname);

GetDlgItem(tempname)->ShowWindow(false);

my problem is that i do not know how to enter the tempname to the GetDlgItem
i need to enter IDC_1 to ADC_20
how can i do it?
thanks,

Recommended Answers

All 5 Replies

The IDC's aren't actually Strings, they're Integers that have been #defined.

So IDC_1 may actually have a value of 6001.

You may be better holding a list of controls in a vector and iterating the vector.
You can assign your form controls to code controls using DDX_Control(CDataExchange*, int, Control) in your DoDataExchange method.

eg.

void CMyForm::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_FORM_TITLE_LABEL, lblTitle);
}

Now you can access that control using lblTitle eg. lblTitle.ShowWindow(false);

Ketsuekiame thanks,
can you send me more details code?
lblTitle - equivalent to IDC_1?

I've shown you what you need to get started. The method I've given you is pretty much core to the whole thing. You should be able to google for the rest pretty easily.

If you get stuck again, post what you tried and I'll have another look. The problem is that you will have to use this a lot, so copy-pasta won't do you any good. ;)

u r right
i will google it and ask u again
thanks,

it is OK
Vector do the Job, Thanks,
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.