请问手动复选框和自动复选框有什么区别?
我按照书上敲入的一个程序,为什么设置为手动复选框的那个复选框选定后不能再设置为UNCHECK(前面的勾点不去了)?//SOURCE代码
IDD_DIALOG DIALOG DISCARDABLE 0, 0, 187, 98
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 10, "System"
BEGIN
DEFPUSHBUTTON "OK",IDOK,130,28,50,14
PUSHBUTTON "Cancel",IDCANCEL,130,65,50,14
CHECKBOX "CheckBox1",ID_CB1,22,16,53,10
CONTROL "CheckBox2",ID_CB2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
20,47,53,10
END//代码
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include "Resource.h"LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);char szWinName[ ] = "MyWin"; /* name of window class */
HINSTANCE hInst;/* holds status of check boxes */
int cbstatusl=BST_UNCHECKED, cbstatus2=BST_UNCHECKED;int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
HACCEL hAccel;
/* Define a window class. */
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst; /* handle to this instance */
wcl.lpszClassName = szWinName; /* window class name */
wcl.lpfnWndProc = WindowFunc; /* window function */
wcl.style = 0; /* default style */
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* standard icon */
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO); /* small icon */
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
wcl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); /* main menu */
wcl.cbClsExtra = 0; /* no extra */
wcl.cbWndExtra = 0; /* information needed */ /* Make the window white. */
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
/* Register the window class. */
if(!RegisterClassEx(&wcl)) return 0; /* Now that a window class has been registered, a window
can be created. */
hwnd = CreateWindow(
szWinName, /* name of window class */
"Using Check Boxes", /* title */
WS_OVERLAPPEDWINDOW, /* window style - normal */
CW_USEDEFAULT, /* X coordinate - let Windows decide */
CW_USEDEFAULT, /* Y coordinate - let Windows decide */
CW_USEDEFAULT, /* width - let Windows decide */
CW_USEDEFAULT, /* height - let Windows decide */
HWND_DESKTOP, /* no parent window */
NULL, /* no override of class menu */
hThisInst, /* handle of this instance of the program */
NULL /* no additional arguments */
);
hInst = hThisInst; /* save the current instance handle */
/* Load accelerators. */
hAccel = LoadAccelerators(hThisInst, MAKEINTRESOURCE(IDR_ACCELERATOR));
/* Display the window. */
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd); /* Create the message loop. */
while(GetMessage(&msg, NULL, 0, 0))
{
if(!TranslateAccelerator(hwnd, hAccel, &msg))
{
TranslateMessage(&msg); /* translate keyboard messages */
DispatchMessage(&msg); /* return control to Windows 98 */
}
}
return msg.wParam;
}/* This function is called by Windows 98 and is passed
messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
char str[255];
int response;
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_DIALOG:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), hwnd, (DLGPROC) DialogFunc);
break;
case IDM_EXIT:
response = MessageBox(hwnd, "Quit the Program?",
"Exit", MB_YESNO);
if(response == IDYES) PostQuitMessage(0);
break;
case IDM_STATUS: /* show check box status */
if(cbstatusl == BST_CHECKED)
strcpy(str, "Checkbox 1 is checked\n");
else strcpy(str, "Checkbox 1 is not checked\n");
if(cbstatus2 == BST_CHECKED)
strcat(str, "Checkbox 2 is checked");
else strcat(str, "Checkbox 2 is not checked");
MessageBox(hwnd, str, "Status", MB_OK);
break;
case IDM_HELP:
MessageBox(hwnd, "Not Implemented", "Help", MB_OK);
break;
}
break;
case WM_DESTROY: /* terminate the program */
PostQuitMessage(0);
break;
default:
/* Let Windows 98 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
/* A simple dialog function. */
LRESULT CALLBACK DialogFunc(HWND hdwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hdwnd, 0);
return 0;
case IDOK:
/* update global checkbox status variables */
cbstatusl = SendDlgItemMessage(hdwnd, ID_CB1,
BM_GETCHECK, 0, 0);
cbstatus2 = SendDlgItemMessage(hdwnd, ID_CB2,
BM_GETCHECK, 0, 0);
EndDialog(hdwnd, 0);
return 1;
case ID_CB1:
/* user selected 1st check box, so check it */
SendDlgItemMessage(hdwnd, ID_CB1,
BM_SETCHECK, BST_CHECKED, 0);
return 1;
}
}
return 0;
}
我按照书上敲入的一个程序,为什么设置为手动复选框的那个复选框选定后不能再设置为UNCHECK(前面的勾点不去了)?//SOURCE代码
IDD_DIALOG DIALOG DISCARDABLE 0, 0, 187, 98
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 10, "System"
BEGIN
DEFPUSHBUTTON "OK",IDOK,130,28,50,14
PUSHBUTTON "Cancel",IDCANCEL,130,65,50,14
CHECKBOX "CheckBox1",ID_CB1,22,16,53,10
CONTROL "CheckBox2",ID_CB2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
20,47,53,10
END//代码
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include "Resource.h"LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);char szWinName[ ] = "MyWin"; /* name of window class */
HINSTANCE hInst;/* holds status of check boxes */
int cbstatusl=BST_UNCHECKED, cbstatus2=BST_UNCHECKED;int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
HACCEL hAccel;
/* Define a window class. */
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst; /* handle to this instance */
wcl.lpszClassName = szWinName; /* window class name */
wcl.lpfnWndProc = WindowFunc; /* window function */
wcl.style = 0; /* default style */
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* standard icon */
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO); /* small icon */
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
wcl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); /* main menu */
wcl.cbClsExtra = 0; /* no extra */
wcl.cbWndExtra = 0; /* information needed */ /* Make the window white. */
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
/* Register the window class. */
if(!RegisterClassEx(&wcl)) return 0; /* Now that a window class has been registered, a window
can be created. */
hwnd = CreateWindow(
szWinName, /* name of window class */
"Using Check Boxes", /* title */
WS_OVERLAPPEDWINDOW, /* window style - normal */
CW_USEDEFAULT, /* X coordinate - let Windows decide */
CW_USEDEFAULT, /* Y coordinate - let Windows decide */
CW_USEDEFAULT, /* width - let Windows decide */
CW_USEDEFAULT, /* height - let Windows decide */
HWND_DESKTOP, /* no parent window */
NULL, /* no override of class menu */
hThisInst, /* handle of this instance of the program */
NULL /* no additional arguments */
);
hInst = hThisInst; /* save the current instance handle */
/* Load accelerators. */
hAccel = LoadAccelerators(hThisInst, MAKEINTRESOURCE(IDR_ACCELERATOR));
/* Display the window. */
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd); /* Create the message loop. */
while(GetMessage(&msg, NULL, 0, 0))
{
if(!TranslateAccelerator(hwnd, hAccel, &msg))
{
TranslateMessage(&msg); /* translate keyboard messages */
DispatchMessage(&msg); /* return control to Windows 98 */
}
}
return msg.wParam;
}/* This function is called by Windows 98 and is passed
messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
char str[255];
int response;
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_DIALOG:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), hwnd, (DLGPROC) DialogFunc);
break;
case IDM_EXIT:
response = MessageBox(hwnd, "Quit the Program?",
"Exit", MB_YESNO);
if(response == IDYES) PostQuitMessage(0);
break;
case IDM_STATUS: /* show check box status */
if(cbstatusl == BST_CHECKED)
strcpy(str, "Checkbox 1 is checked\n");
else strcpy(str, "Checkbox 1 is not checked\n");
if(cbstatus2 == BST_CHECKED)
strcat(str, "Checkbox 2 is checked");
else strcat(str, "Checkbox 2 is not checked");
MessageBox(hwnd, str, "Status", MB_OK);
break;
case IDM_HELP:
MessageBox(hwnd, "Not Implemented", "Help", MB_OK);
break;
}
break;
case WM_DESTROY: /* terminate the program */
PostQuitMessage(0);
break;
default:
/* Let Windows 98 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
/* A simple dialog function. */
LRESULT CALLBACK DialogFunc(HWND hdwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hdwnd, 0);
return 0;
case IDOK:
/* update global checkbox status variables */
cbstatusl = SendDlgItemMessage(hdwnd, ID_CB1,
BM_GETCHECK, 0, 0);
cbstatus2 = SendDlgItemMessage(hdwnd, ID_CB2,
BM_GETCHECK, 0, 0);
EndDialog(hdwnd, 0);
return 1;
case ID_CB1:
/* user selected 1st check box, so check it */
SendDlgItemMessage(hdwnd, ID_CB1,
BM_SETCHECK, BST_CHECKED, 0);
return 1;
}
}
return 0;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货