我用c ++完成了这段代码,我想问为什么当我按下一个CheckBox时,所有这些代码都会改变状态。 例如:
CB1 =已检查 CB2 = UnChecked
CB1 =按
CB1 = UnChecked CB2 =已检查
我只想把它们中的一个做成,而不是同时做两个。
这里有代码:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
//Load the background image
HWND hWndBackground;
HANDLE hBitmap;
hBitmap = LoadImage(NULL, TEXT("\header.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBitmap != NULL)
{
hWndBackground = CreateWindow(TEXT("STATIC"), TEXT("image box"),
WS_CHILD | WS_VISIBLE | SS_BITMAP,
0, 0, 470, 130,
hwnd, (HMENU)2000, NULL, NULL);
SendMessage(hWndBackground, STM_SETIMAGE, IMAGE_BITMAP, LPARAM(hBitmap));
}
//Load CheckBox1
CreateWindow(TEXT("button"), TEXT("Show Title"),
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
25, 220, 114, 45,
hwnd, (HMENU)1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
CheckDlgButton(hwnd, 1, BST_CHECKED);
//Load Textbox1
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("140"),
WS_CHILD | WS_VISIBLE,
115, 230, 50, 25,
hwnd, NULL, NULL, NULL);
//Load Label1
CreateWindowW(L"Static", L"0",
WS_CHILD | WS_VISIBLE, 0, 0, 10, 30, hwnd, (HMENU)1, NULL, NULL);
//Load CheckBox2
CreateWindow(TEXT("button"), TEXT("Show Title1"),
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
25, 250, 114, 45,
hwnd, (HMENU)2, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
CheckDlgButton(hwnd, 2, BST_UNCHECKED);
break;
}
case WM_COMMAND:
{
BOOL checked = IsDlgButtonChecked(hwnd, 1);
if (checked) {
CheckDlgButton(hwnd, 1, BST_UNCHECKED); //SetWindowText(hwnd, title or TEXT("algo");
}
else {
CheckDlgButton(hwnd, 1, BST_CHECKED);
//action("chatlim", 150, 0, 0);
}
BOOL checked1 = IsDlgButtonChecked(hwnd, 2);
if (checked1) {
CheckDlgButton(hwnd, 2, BST_UNCHECKED);
}
else {
CheckDlgButton(hwnd, 2, BST_CHECKED);
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
答案 0 :(得分:0)
修正了,只需要使用开关和外壳。
答案 1 :(得分:0)
如果有人想知道作者是如何解决的,我将在此处保留此代码。
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case 1:
{
BOOL checked = IsDlgButtonChecked(hwnd, 1);
if (checked) {
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
}
else {
CheckDlgButton(hwnd, 1, BST_CHECKED);
}
break;
}
break;
case 2:
{
BOOL checked1 = IsDlgButtonChecked(hwnd, 2);
if (checked1) {
CheckDlgButton(hwnd, 2, BST_UNCHECKED);
}
else {
CheckDlgButton(hwnd, 2, BST_CHECKED);
}
break;
}
break;
}
}