为什么列表框不显示使用视觉C++ 6 的元素

Why is Listboxes not displaying elements using Visual C++ 6?

本文关键字:C++ 视觉 元素 列表 显示 为什么      更新时间:2023-10-16

因此,我遇到了一个列表框问题,其中我希望它显示的条目未显示在Visual C++ 6中。

代码如下。

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;
    }

C++不是C#。原始数组不是类,也没有方法。

使用 std::vector< std::string > .

但在此之前,找一本好C++书,C++学习。

ETA 由于您进行了编辑,尝试在 StringArray 变量上调用不存在的.Length以在 for 循环中遍历它......

LB_ADDSTRING消息的 MSDN 文档中的哪些内容使您认为它会接受std::stringstd::string不是以 NULL 结尾的字符数组。为什么你会认为你可以将一系列std::string投射到LPARAM

你想要的更像是:(我没有编译这段代码。

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() ) );
}

基于范围的

注意:这是现代C++,而不是古老的、过时的 VC++ 6。