1

I am working on a win32 project (visual studio 2012). User Can Enter several markers with their coordinates and names; Now I want to Add all the markers name in the Listbox as a separate item; but with the below code I don't see anything in listbox:

string MarkerNames[10];
CMarkerList *Modeless;

    if (!Modeless)
        Modeless = new CMarkerList;

    if (!::IsWindow(Modeless->GetSafeHwnd()))
        Modeless->Create(IDD_DIALOG2,NULL);

    Modeless->ShowWindow(SW_SHOW);  
    HWND hdlg = FindWindow(NULL,_T("Dialog"));


    int index1 = SendDlgItemMessage(hdlg, IDC_LIST2, LB_ADDSTRING, 0, (LPARAM)(MarkerNames[0].c_str()));

which Modeless is an object of my dialog and MarkerNames is an array which I saved the marker's name in; if I enter an explicit string such as "TEST" it works but there is a problem with passing parameter to it;

what is the problem and How can I correct that?

thank you so much for your help :)

user3811565
  • 29
  • 1
  • 5

1 Answers1

0

Your use of _T suggests that you are building the program for the unicode character set, which is the default. If that is the situation then you should use wstring instead of string.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • I must use the GetDlgItemText() function for getting the text from the edit control on the dialog and it must be in TCHAR type and I cant find a suitable convertion for switching between this types; – user3811565 Jul 09 '14 at 06:04
  • A conversion is not necessary: Edit controls and Listbox controls use the same text type. But std::string works only for 8 bit characters and std::wstring works only for 16 bit characters. Which size is TCHAR in your program? (It changes depending on whether you are building for unicode or not.) – ScottMcP-MVP Jul 09 '14 at 13:07