3 Replies - 827 Views - Last Post: 10 February 2013 - 02:41 PM Rate Topic: -----

#1 Sammdahamm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 14-February 12

Adding a String to a list box in WinAPI

Posted 08 February 2013 - 05:13 AM

Hey!
I'm having a bit of trouble simply adding a string to an empty listbox in C++ WinAPI. The Listbox is initialised as follows:
#
hwndObjList = CreateWindowEx(0, TEXT("LISTBOX"), TEXT(""),
                WS_CHILD | WS_VISIBLE | WS_BORDER| LBS_STANDARD|LBS_HASSTRINGS, 20, 185, 170, 95, hwndObjectives,
                (HMENU)  IDOBJLIST , NULL, NULL);



I've tried adding a string as follows, but to no avail: (I have only included relevant lines)
string szObjectivesArray[noObjectives][2];
string* buffer = &szObjectivesArray[0][0];

for (int Counter = 0; Counter < noObjectives; Counter++)
        {
            GetFirstIndex(file, ((Counter + 1) * 2) - 1, szObjectivesArray[Counter][0]);
            GetSecondIndex(file, ((Counter + 1) * 2) - 1, szObjectivesArray[Counter][1]);
        }
SendMessage(hwndObjList, LB_ADDSTRING, NULL, (LPARAM)buffer);



I've tried one or two other methods of adding a string, but I can't see why this isn't working. the output is just an empty list box
(this code is included under a WM_CREATE message under the hwndObjectives window which contains the list box)

Is This A Good Question/Topic? 0
  • +

Replies To: Adding a String to a list box in WinAPI

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3463
  • View blog
  • Posts: 10,669
  • Joined: 05-May 12

Re: Adding a String to a list box in WinAPI

Posted 08 February 2013 - 06:32 AM

LB_ADDSTRING takes a pointer to a C-string. You are trying to pass a pointer to a C++ string.
Was This Post Helpful? 0
  • +
  • -

#3 Sammdahamm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 14-February 12

Re: Adding a String to a list box in WinAPI

Posted 10 February 2013 - 08:08 AM

View PostSkydiver, on 08 February 2013 - 06:32 AM, said:

LB_ADDSTRING takes a pointer to a C-string. You are trying to pass a pointer to a C++ string.


I've changed it to a cstring and unfortunately this still didn't fix the problem :(
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3463
  • View blog
  • Posts: 10,669
  • Joined: 05-May 12

Re: Adding a String to a list box in WinAPI

Posted 10 February 2013 - 02:41 PM

Can you show us your code where you are now using a cstring (sic)? Are you sure you aren't using the MFC CString? I deliberately put the dash there so that you would use a C-string. Or in other words, a C-style string where there is a buffer that contains characters and is null terminated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1