Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to MFC and here i am converting CString to UINT, I have tried
C++
UINT iEditId = _ttoi((LPCSTR)sTempString); 

sTempString value is "IDC_EDIT5" and I am getting iEditId=0.
I can't convert it into proper value.
Posted
Updated 1-Jun-15 1:29am
v2
Comments
[no name] 1-Jun-15 7:27am    
Of course it will be 0. What is it exactly are you trying to do?
Mahesh Vanama 29-May-19 1:32am    
I've something like this too.
#define IDS_ERR 30

Now I've this name of the macro in CString.
CString temp = "IDS_ERR";
How can i get to 30 from 'temp'?

Thank you guys for your suggestions. I found the solution after searching a lot. Actually I wanted set of unique IDs to be assigned to a set of dynamically generated CEdit objects, so i was planning to convert from CString to UINT. If i use the following line where iEditId value is 1005(From resource.h)

unsigned int iEditId = IDC_EDIT5;

so next time i can simply increase the ID value by just increment the variable iEditId.

For(iIndex=0;iIndex<=5;iIndex++)
{
pEdit[iIndex]->Create(WS_CHILD | WS_VISIBLE | WS_DLGFRAME | ES_AUTOHSCROLL | WS_TABSTOP, CRect(110, (30 + iSize * 30), 260, (50 + iSize * 30)), this, iEditId + iIndex);
}
 
Share this answer
 
This code works fine and returns "12":
C++
CString abc = _T("12/12/2014");   
int date = _ttoi(abc.Left(2));


You surely don't want the integer value of "IDC_EDIT5" but the integer value of the content of the CEdit, don't you?
 
Share this answer
 
v2
You are using the tag in the wrong way: IDC_EDIT5 is already defined in one of your header files, something like:
C++
#define IDC_EDIT5 1005

You just use that label as is to get its value, possibly to get an item like:
C++
item = GetDlgItem(hDlg, IDC_EDIT5);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900