-2

So, I have a Listbox problem where the entries I want it to show are not being displayed in Visual C++ 6.

The code is as follows.

switch (m) {
    case WM_INITDIALOG: //To initiate the dialog box
    {
        HICON hicon = (HICON__ *)LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_ICONMAIN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
        SendMessageW(h, WM_SETICON, ICON_BIG, (long)hicon);
        RECT Rect;
        ::GetWindowRect(h, &Rect);
        ::SetWindowPos(h, HWND_TOPMOST, (::GetSystemMetrics(SM_CXSCREEN)/2 - ((Rect.right - Rect.left)/2)), (::GetSystemMetrics(SM_CYSCREEN)/2 - ((Rect.bottom - Rect.top)/2)), (Rect.right - Rect.left), (Rect.bottom - Rect.top), SWP_SHOWWINDOW);
        //Place items in listbox.
        const std::string StringArray[] = {"10", "20", "30", "40", "50", "60", "70"};
        SendMessage(h, LB_ADDSTRING, DROPDOWN1, (LPARAM)StringArray);
        return TRUE;
    }
PSXGamerPro1
  • 152
  • 10

1 Answers1

1

C++ is not C#. Raw arrays are not classes and do not have methods.

Use std::vector< std::string >.

But before that, get a good C++ book and learn C++.

ETA Since you took out your edits where you were trying to call a non-existant .Length on the StringArray variable to traverse it in a for loop...

What in the MSDN documentation for the LB_ADDSTRING message makes you think it will accept a std::string? std::string is not a NULL terminated character array. Why would you think that you could cast an array of std::string to an LPARAM?

What you want is more like: (I have not compiled this code.)

typedef std::vector< std::string > string_vec;
const string_vec StringArray{"10", "20", "30", "40", "50", "60", "70"};

for( const auto & s : StringArray )
{
    SendMessage(h, LB_ADDSTRING, DROPDOWN1, (LPARAM)( s.c_str() ) );
}

Range-based for

N.B. this is modern C++, not ancient, obsolete VC++ 6.

Community
  • 1
  • 1
Rob K
  • 8,757
  • 2
  • 32
  • 36