VC ++ Win32 programming-Basic window

Source: Internet
Author: User

# Include <windows. h>

Lresult callback wndproc (hwnd, uint, wparam, lparam );

Int winapi winmain (hinstance, hinstance hprevinstance, pstr sz1_line, int icmdshow)
{
Tchar szappname [] = text ("simple window ");
Hwnd;
MSG;

wndclass;
wndclass. style = cs_hredraw | cs_vredraw;
wndclass. lpfnwndproc = wndproc;
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;

If (! Registerclass (& wndclass ))
{
MessageBox (null, text ("this program requires Windows NT! "),
Szappname, mb_iconerror );
Return 0;
}

Hwnd = createwindow (szappname, // window class name
Szappname, // window caption
Ws_overlappedwindow, // window style
Cw_usedefault, // initial X position
Cw_usedefault, // initial y position
Cw_usedefault, // initial X size
Cw_usedefault, // initial y size
Null, // parent window handle
Null, // Window menu handle
Hinstance, // program instance handle
Null); // creation Parameters

Showwindow (hwnd, icmdshow );
Updatewindow (hwnd );

While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return msg. wparam;
}

Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Switch (Message)
{
Case wm_destroy:
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}

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.