C Language Call WIN32 API learning 3 Create check box

Source: Internet
Author: User
Tags function definition

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.