Windows programming 1

Source: Internet
Author: User

One of the simplest windows must include two functions:

1. Entry function: WinMain

2. Window procedure callback function: WndProc

The structure is as follows:

1#include <windows.h>2 3 //window procedure callback function4 LRESULT CALLBACK WndProc (HWND hwnd, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)5 {6     //processing of various messages7     Switch(msg)8     {9      Casewm_create:Ten          One          Break; A  -  -     default: the          Break; -     } -  -     returnDefWindowProc (hwnd, MSG, wparam, lparam);//send the message to the system to handle it. + } -  +  A //equivalent to the main function in the C language. Returns the parameters of the message at intWINAPI WinMain (HInstance hinstance,//Current instance handle - hinstance Hprevinsttance, - PSTR CmdLine, -                    intcmdshow) - { - msg msg; in     //1. Create a window - wndclass wndclass; to         //1.1 Design window class +Wndclass.lpfnwndproc =(WNDPROC) WNDPROC; -           //set the remaining properties of Wndclass the         //2.2 Register window class *           if(! RegisterClass (&wndclass)) $               return 0;Panax Notoginseng         //2.3 Creating Windows -HWND hwd = CreateWindow ("Z","X", the Ws_overlappedwindow, +                -, A               0, the                -, +                $, - NULL, $ NULL, $ hinstance, - NULL); -         //2.4 Displaying and updating Windows the ShowWindow (HWD, cmdshow); - UpdateWindow (HWD);Wuyi     //2. Message Loops the            while(GetMessage (&msg,null,0,0))//getmessage The message in the message queue and put it in Msg. -           { WuTranslateMessage (&AMP;MSG);//translating keyboard Messages -DispatchMessage (&AMP;MSG);//Send to WndProc processing About           } $     returnMsg.wparam;//returns the parameters of the message -}

Windows programming 1

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.