C Language Call WIN32 API Tutorial 2 Create button

Source: Internet
Author: User

In the previous section, we learned about creating a window, and then we created the button on the window and clicked the 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;

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,10,10,100,30,hwnd,null, (HINSTANCE) GetWindowLong (hwnd, gwl_hinstance), NULL);//Create Key
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
}
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 Tutorial 2 Create button

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.