[英]C++ Create and Add items to listbox
Sorry for this noob question but i'm new to C++ (coming from C#).抱歉这个菜鸟问题,但我是 C++(来自 C#)的新手。 I have a list of items from an array that i want to display on a listbox (just do display - nothing else).
我有一个数组中的项目列表,我想在列表框中显示(只显示 - 仅此而已)。 Adding a control in c++ was a lot harder than i thought.
在 c++ 中添加控件比我想象的要困难得多。
Here's what i have so far: I'm not sure how to proceed from here and how to get it to work.到目前为止,这是我所拥有的:我不确定如何从这里开始以及如何让它发挥作用。 Thanks in advance.
提前致谢。
// .rh file
#define IDC_LISTDIR 106
//in the .rc file
CONTROL "ListBox", IDC_LISTDIR, "listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_GROUP, 8, 80, 200, 60
//main
SendMessage(HANDLE, LB_ADDSTRING, 0, (LPARAM)L"Add This Text to listbox");
Also, i'm getting this: error C2275: 'HANDLE': illegal use of this type as an expression另外,我得到这个:错误C2275:'HANDLE':非法使用这种类型作为表达式
IDD_MAINWINDOW DIALOG 36, 54, 421, 252
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE
CAPTION "Listbox Test"
FONT 9, "MS Sans Serif"
{
CONTROL "&OK", IDOK, "button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 5, 40, 14
CONTROL "&Cancel", IDCANCEL, "button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 30, 30, 14
CONTROL "CheckBox", IDC_YESNO, "button", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_GROUP, 9, 55, 77, 22
CONTROL "ListBox", IDC_LISTDIR, "listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_GROUP, 8, 80, 200, 60
}
SendMessage()
takes an HWND
to send the message to. SendMessage()
采用HWND
将消息发送到。 HANDLE
is a type, not an HWND
variable. HANDLE
是一种类型,而不是HWND
变量。 You need the actual HWND
of the ListBox at runtime.您在运行时需要 ListBox 的实际
HWND
。 Use GetDlgItem()
to get that, eg:使用
GetDlgItem()
来获得它,例如:
HWND hwndLB = GetDlgItem(hwndDlg, IDC_LISTDIR);
SendMessage(hwndLB, LB_ADDSTRING, 0, (LPARAM)L"Add This Text to listbox");
Where hwndDlg
is the HWND
of the window that the ListBox is a child of.其中
hwndDlg
是 ListBox 的子 window 的HWND
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.