Create a simple window program

Source: Internet
Author: User

function prototypes for #include  <windows.h>/* window functions */lresult callback mainwndproc (hwnd, uint,  Wparam, lparam); Int apientry winmain (hinstance hinstance, hinstance  Hprevinstance, lpstr lpcmdline, int ncmdshow) {    char  szclassname[] =  "Mainwclass";    wndclassex wndclass;         /* fills the wndclassex structure with the parameters describing the main window */    wndclass.cbsize =  sizeof (WNDCLASS); the size of the              /* structure */     wndclass.style = CS_HREDRAW | CS_VREDRAW;        /* specifies that if the size changes, redraw */    wndclass.lpfnwndproc = mainwndproc;              /* window function Pointer */     Wndclass.cbclsextra = 0;                         /* no additional class memory */    wndclass.cbwndextra = 0;                          /* no additional window memory */    wndclass.hinstance = hinstance;                  /* instance handle */     wndclass.hicon = loadicon (null, idi_application);/* Use predefined icons */     wndclass.hcursor = loadcursor (null, idc_arrow);   /* Use predefined Cursors */     wndclass.hbrBackground =  (Hbrush) getstockobject (White_brush)  /* using a white background brush */     wndclass.lpszMenuName = NULL;                    /* do not specify a menu */    wndclass.lpszclassname = szclassname;            /* the name of the window class */&NBSP;&NBSP;&NBSP;&NBSP;WNDCLASS.HICONSM  = NULL;                         /* Small icons with no class */         /* Register this window */    registerclassex (&wndclass);         /* Creating the main window */    hwnd hwnd = createwindowex (         0,                          /*dwExStyle,  Extended Style */         szClassName,                /*lpclassname,  class name */         "my first window!",         /*lpWindowName,  title */         WS_OVERLAPPEDWINDOW,       /*dwStyle,  window Style */         CW_USEDEFAULT,              /*X,  initial X-coordinate */        cw_usedefault,              /*Y,  initial Y-coordinate */         CW_USEDEFAULT,              /*nwidth, Width */        cw_usedefault,              /*nHeight,  Height */         NULL,                       /*hWndParent,  parent Window Handle */        null,                        /*hMenu,  Menu Handle */        hinstance,                  /*hInstance,  Program Instance handle */         null);                        /*lpParam,  User Data */         if (hwnd == null)     {         messagebox (null,  "error build the window!",  " Error ", &NBSP;MB_OK);        return -1;    }         /* display window, Refresh window client area */    showwindow (hwnd, ncmdshow);     updatewindow (HWND);         /* remove the message from the message queue and give it to the window function processing, Returns false directly to GetMessage, ending the message loop */    msg msg;    while (GetMessage ( &msg, null, 0, 0))     {         /* Convert keyboard message */        translatemessage (&AMP;MSG);         /* sends the message to the appropriate window function */        dispatchmessage (& msg);     }        /* when GetMessage returns FALSE, the program ends */     return msg.wparam;} Lresult callback mainwndproc (Hwnd hwnd, uint message, wparam wparam,  lparam lparam) {    char sztext[] =  "The simplest window program! ";     switch (message)     {         case wm_paint:  /* window client area need to redraw */        {             HDC hdc;             PAINTSTRUCT ps;                         /* makes the invalid client area effective, and get the device environment handle */            hdc = beginpaint ( HWND,&NBSP;&AMP;PS);             /* display text */             textout (Hdc, 10, 10, sztext,  strlen (Sztext));    &Nbsp;        endpaint (HWND,&NBSP;&AMP;PS);             return 0;         }        case wm_destroy: /* is destroying the window */             /* post a WM_QUIT message to the message queue, prompting the GetMessage function to return 0, ending the message loop */             postquitmessage (0);             return 0;    }    /* Handing out messages we don't handle to the system to do the default processing */    return defwindowproc (hwnd, message, wparam,  LParam);}


Create a simple window program

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.