为什么列表框不显示使用视觉C++ 6 的元素
Why is Listboxes not displaying elements using Visual C++ 6?
因此,我遇到了一个列表框问题,其中我希望它显示的条目未显示在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::string
? std::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。
相关文章:
- 视觉studo 2019中的漫画和静态/动态绑定
- 如何改变c++应用程序的视觉效果
- 视觉工作室项目.提取源文件夹名称
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 视觉我希望一个函数在另一个函数C++中进行计算
- 视觉 如何循环访问C++中遵循类似格式的多个.txt文件?
- remove(str.begin(), str.end(), );无法正常工作(我正在使用视觉工作室 2012)
- 背包问题,视觉工作室问题
- 如何在视觉c ++项目中添加箭头键作为修饰键Microsoft
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 视觉C++未按所需顺序打印
- 视觉C++使用 map 来比较字符串中的每个单词
- C++11 中好友模板类的视觉C++错误
- 迭代器跳闸视觉C++ 2017 断言
- 视觉C++联盟,垃圾价值
- 无法安装由视觉C++制作的apk
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- 使用外部文件中的变量进行视觉C++