I want to generate 17 service names in the List Control. How can i use a formatted string variable inside a _T wrapper ?
// TODO: Add extra initialization here
#define MAX_VALUE 17
int numberOfService = 0;
CString StringServiceName;
StringServiceName.Format(_T("Sense Counter %d"), numberOfService);
for (numberOfService; numberOfService < MAX_VALUE; numberOfService++) {
int nIndex = m_List.InsertItem(0, _T("")); //This variable i want to use in a _T wrapper - StringServiceName.Format(_T("Sense Counter %d"), numberOfService)
}
m_List.InsertColumn(0, _T("Názov služby"), LVCFMT_LEFT,150);
m_List.InsertColumn(1, _T("Status"), LVCFMT_LEFT, 90);
m_List.InsertColumn(2, _T(""), LVCFMT_LEFT, 90);
int nIndex = m_List.InsertItem(0, _T("Sense Counter 1"));
m_List.SetItemText(nIndex, 1, _T("Running"));
m_List.SetItemText(nIndex, 2, _T("✓"));
nIndex = m_List.InsertItem(1, _T("Sense Counter 2"));
m_List.SetItemText(nIndex, 1, _T("Stopped"));
m_List.SetItemText(nIndex, 2, _T("✓"));
>Solution :
You can’t – _T is just a macro to generate narrow or wide string constants, depending on whether you’re compiling for Unicode or not.
I’m not over-familiar with CString, but perhaps you meant this:
for (numberOfService; numberOfService < MAX_VALUE; numberOfService++) {
StringServiceName.Format(_T("Sense Counter %d"), numberOfService)
int nIndex = m_List.InsertItem(0, (LPCTSTR) StringServiceName);
}
(The cast may not be necessary here, although Microsoft recommends it – try without.)