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