In the previous section, we learned the Create button, let's create a check box on the window, and make a click Action.
1, Open vc++6.0, Click File--open Workspace Select example1, Click ok, Open the Project.
2, Add code
Define Global variables First
HWND button1,checkbox1,checkbox2;
int checkboxvalve;
Change the callback function as follows
LRESULT CALLBACK winsunproc (HWND hwnd,uint umsg,wparam wparam,lparam LPARAM)//callback function definition
{
Switch (umsg)
{
Case Wm_create:
Button1=createwindow ("button", "first key", ws_visible| ws_child| ws_border|bs_pushbutton,10,10,100,30,hwnd,null, (hinstance) getwindowlong (hwnd, gwl_hinstance), NULL);//create key
Checkbox1=createwindow ("button", "first Check box", ws_visible| ws_child| ws_border|bs_autocheckbox,10,50,150,30,hwnd,null, (hinstance) getwindowlong (hwnd, gwl_hinstance), NULL);//create check box
Checkbox2=createwindow ("button", "second Check box", ws_visible| ws_child| ws_border|bs_autocheckbox,10,100,150,30,hwnd,null, (hinstance) getwindowlong (hwnd, gwl_hinstance), NULL);//create check box
Break
Case Wm_command:
If (HWND) lparam==button1)//determine if the message is from a key
{
MessageBox (NULL, "key 1 pressed", "hint", mb_ok);//popup prompt form
}
If ((HWND) LParam) = = CheckBox1)
{
checkboxvalve= (int) SendMessage (checkbox1,bm_getcheck,0,0);
If (checkboxvalve)
MessageBox (NULL, "check Box 1 is selected", "hint", mb_ok);//popup prompt form
Else
MessageBox (NULL, "check Box 1 is deselected", "hint", mb_ok);//popup prompt form
}
If ((HWND) LParam) = = CheckBox2)
{
checkboxvalve= (int) SendMessage (checkbox2,bm_getcheck,0,0);
If (checkboxvalve)
MessageBox (NULL, "check Box 2 is selected", "hint", mb_ok);//popup prompt form
Else
MessageBox (NULL, "check Box 2 is deselected", "hint", mb_ok);//popup prompt form
}
Break
Case wm_destroy://closed window is a message sent by the system
PostQuitMessage (0);//send Exit message getmessage return 0 when message is received, main function exits message loop
Break
Default
Return DefWindowProc (hwnd,umsg,wparam,lparam);//the message that is not processed is given to the system for Processing.
}
Return 0;
}
3, Compile and run, Press the button to try and see if there is a response
C Language Call WIN32 API learning 3 Create check box