我有以下用C ++编写的代码,而不是只有一个复选框显示“ Show Title”,我希望能够为不同/更多的复选框传递多个字符串。如何为多个复选框的CreateWindowW函数提供多个字符串?并且应该在Select函数还是WndProc函数中修改CreateWindowW函数?
xf = crossfilter(data);
编辑:这是新代码
void Select(vector<string>& ret)
{
HINSTANCE hInstance = NULL; //NULL = the current process
WNDCLASSW wc = { 0 };
MSG msg;
wc.lpszClassName = L"Check Box";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassW(&wc);
CreateWindowW(wc.lpszClassName, L"Check Box",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
150, 150, 230, 150, 0, 0, hInstance, 0);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
bool checked = true;
switch (msg) {
case WM_CREATE:
CreateWindowW(L"button", L"Show Title",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
20, 20, 185, 35, hwnd, (HMENU)1,
NULL, NULL);
CheckDlgButton(hwnd, 1, BST_CHECKED);
break;
case WM_COMMAND:
checked = IsDlgButtonChecked(hwnd, 1);
if (checked) {
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
SetWindowTextW(hwnd, L"");
}
else {
CheckDlgButton(hwnd, 1, BST_CHECKED);
SetWindowTextW(hwnd, L"Check Box");
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
答案 0 :(得分:1)
如何为
CreateWindowW
函数的多个复选框提供多个字符串?
CreateWindow()
每次呼叫只能创建1个窗口/控件。您将必须手动分割字符串,然后为每个单独的复选框分别调用CreateWindow()
。
假设您的vector<string>
包含复选框字符串,则可以通过vector
的{{1}}参数将lpParam
传递到窗口,然后在{{ 1}}消息处理程序,例如:
CreateWindow()