Structure of Window Program

Source: Internet
Author: User

    • WinMain () function
int WINAPI WinMain (    hinstance hinstance,    hinstance hprevinstance,    LPSTR lpcmdline,    int  ncmdshow    ) {    return0;}

The hinstance:hinstance type, which points to the handle of an instance, is a running program.

lpCmdLine: A pointer to a string containing the command-line character of the launcher.

nCmdShow: Determines the appearance of the created window.

    • Window procedure Functions

messages that a application receives from the operating system. " This function handles many messages that the application receives from the operating system.  ok button when the user Clicks the button, the operating system sends the application a message, the button was clicked. " > wndproc  is responsible for responding to the event.  

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    • Specifying the program window

Wndclssex: A special struct type that contains the data used to specify the window.

struct tagwndclassex {  UINT      cbsize;       The size, in bytes, of this structure.     UINT      style;  WNDPROC   Lpfnwndproc;   int        Cbclsextra;   int        Cbwndextra;  HINSTANCE hinstance;  Hicon     Hicon;  Hcursor   hcursor;  Hbrush    Hbrbackground;  LPCTSTR   Lpszmenuname;  LPCTSTR   lpszClassName;  Hicon     *pwndclassex;

Constructs a Wndclassex type object and fills in the value of an object member

static LPCTSTR Szappname = L "APP";

Wndclassex Windowclass; Windowclass.cbsize=sizeof(Wndclassex); Windowclass.style= Cs_hredraw | Cs_vredraw;//to change the width or height of a window, redraw the windowWindowclass.lpfnwndproc =WndProc;//stores a pointer to a function that handles messages in a programWindowclass.cbclsextra =0;//Extra space for special useWindowclass.cbwndextra =0;//Extra space for special useWindowclass.hinstance = hinstance;//Handle to accommodate the current application instanceWindowclass.hicon = LoadIcon (hinstance, Makeintresource (idi_application));//defines the icon for the application when minimizedWindowclass.hcursor = LoadCursor (NULL, Idc_arrow);//defines the cursor used by the windowWindowclass.hbrbackground = (hbrush) (Color_window +1);//defines the background color of the window's workspaceWindowclass.lpszmenuname = NULL;//name of the resource that defines the Window menuWindowclass.lpszclassname = Szappname;//stores the name provided to identify that particular window class, typically using the name of the application to assign a value to the memberWINDOWCLASS.HICONSM = LoadIcon (Windowclass.hinstance, Makeintresource (idi_application));//identifies a small icon that is associated with the window class
    • To create a program window

Registered wound type

RegisterClassEx (&windowclass);

Creating a window, using the function CreateWindow (), and other real differences passed to the CreateWindow () function adds some additional attributes that return a handle to the window that was created.

HWND WINAPI CreateWindow (  _in_opt_  lpctstr lpclassname,  _in_opt_  lpctstr lpwindowname,  _in _      DWORD dwstyle,  _in_      int  x,  _in_      int  y,  _in_       int nwidth,  _in_      int  nheight,  _in_opt_  HWND hwndparent,  _in_opt_  HMENU HMENU,  _in_opt_  hinstance hinstance,  _in_opt_  lpvoid lpparam);
HWND hwnd; HWnd=CreateWindow (Szappname,//The class name used to identify the wndclassex struct previously passed in the RegisterClassEx () function callSzTitle,//define the text that appears on the title barWs_overlappedwindow,//defines the style that the window should have after it is createdCw_usedefault, Cw_usedefault, -, -,//define the position and size of the window on the screenNull//handle to parent windowNull//No menus requiredHINSTANCE,//specifies a handle to the current program instance that is passed to the program by WindowsNull//Multi-Document interface);

Display window

ShowWindow (HWnd, ncmdshow);

Redraw window

UpdateWindow (HWND);

Structure of Window Program

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.