The most classic SDK program structure Hellowin

Source: Internet
Author: User

Program run Effect: When creating the window, play a sound. and draw a sentence in the center of the client area of the window: Hello, Windows 98! No matter how the program moves or maximizes, the text is always in the center of the program.

The program is divided into six steps: definition, registration, creation, display, refresh, message loop. The definition section also includes a window callback function WndProc.

/*------------------------------------------------------------Hellowin. C--Displays "Hello, Windows 98!" In client area (c) Charles Petzold, 1998----------------------------- -------------------------------*/#include<windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);intWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, PSTR szcmdline,inticmdshow) {     //0th step, define variables in advance     StaticTCHAR szappname[] = TEXT ("Hellowin") ;//the class name of the windowHWND hwnd;//the handle that was obtained after the window was createdMSG msg;//Message loop for message variables (just one)//The first step is to define the window classWndclass wndclass; Wndclass.style= Cs_hredraw |Cs_vredraw; Wndclass.lpfnwndproc= WndProc;//Important Properties: Window functions (callback functions)Wndclass.cbclsextra =0 ; Wndclass.cbwndextra=0 ; Wndclass.hinstance=hinstance; Wndclass.hicon=LoadIcon (NULL, idi_application); Wndclass.hcursor=loadcursor (NULL, Idc_arrow); Wndclass.hbrbackground=(Hbrush) getstockobject (White_brush); Wndclass.lpszmenuname=NULL; Wndclass.lpszclassname= Szappname;//Important Properties: Window class name//Second Step, Register window class     if(! RegisterClass (&wndclass)) {MessageBox (NULL, TEXT ("This program requires Windows nt!"), Szappname, Mb_iconerror); return 0 ; }     //step three, create the window classhwnd = CreateWindow (Szappname,//window class nameTEXT ("The Hello program"),//Window CaptionWs_overlappedwindow,//window StyleCw_usedefault,//Initial x positionCw_usedefault,//Initial y positionCw_usedefault,//Initial x SizeCw_usedefault,//Initial y sizeNull//parent Window HandleNull//Window menu HandleHINSTANCE,//Program Instance handleNULL);//Creation Parameters//Fourth Step, display windowShowWindow (hwnd, icmdshow); //Fifth Step, refresh the windowUpdateWindow (HWND); //Sixth step, message loop      while(GetMessage (&msg, NULL,0,0) {translatemessage (&msg); DispatchMessage (&msg); }     //In the final step, the wparam parameter of the last message is returned to the main function as the result of the function     returnMsg.wparam;}     LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {HDC hdc;     Paintstruct PS;          Rect rect; Switch(message) { CaseWm_create:playsound (TEXT ("Hellowin.wav"), NULL, Snd_filename | Snd_async);//API          return 0 ;  CaseWM_PAINT:HDC= BeginPaint (hwnd, &AMP;PS);//APIGetClientRect (hwnd,&rect);//APIDrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, Dt_singleline| Dt_center | Dt_vcenter);//APIEndPaint (hwnd,&AMP;PS);//API          return 0 ;  CaseWm_destroy:postquitmessage (0) ;//API          return 0 ; }     returnDefWindowProc (HWND, message, WParam, LParam);//API}

The most classic SDK program structure Hellowin

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.