Windows notes-A simple Windows GUI application

Source: Internet
Author: User

#include <windows.h>//write header files that Windows programs must contain

LRESULT CALLBACK WndProc (Hwnd,uint,wparam,lparam); declaring window function prototypes

int WINAPI WinMain (hinstance hinstance,
HInstance hPrevInstance,
LPSTR lpCmdLine,
int nshowcmd)
{
HWND hwnd; Defining window Handles
MSG msg; Define a variable to store the message
TCHAR lpszclassname[] = TEXT ("window");

WNDCLASS WC; Defining a window class variable
Wc.style = Cs_hredraw | Cs_vredraw;
Wc.lpfnwndproc = WndProc;
Wc.cbclsextra = 0;
Wc.cbwndextra = 0;
Wc.hinstance = hinstance;
Wc.hicon =:: LoadIcon (Null,idi_application);
Wc.hcursor =:: LoadCursor (Null,idc_arrow);
Wc.hbrbackground = (hbrush):: Getstockobject (White_brush);
Wc.lpszmenuname = NULL;
Wc.lpszclassname = lpszClassName;

:: RegisterClass (&WC); Registration window

Hwnd= CreateWindow (lpszClassName,//Create window
TEXT ("Windows"),
Ws_overlappedwindow,
120,50,800,600,
Null
Null
HINSTANCE,
NULL);

:: ShowWindow (Hwnd,sw_shownormal); Display window
:: UpdateWindow (HWND);

while (:: GetMessage (&msg,null,0,0))//message loop
{
:: TranslateMessage (&MSG);
::D ispatchmessage (&msg);
}
return msg.wparam;
}


window functions for processing messages
LRESULT CALLBACK WndProc (HWND hwnd,
UINT message,
WPARAM WPARAM,
LPARAM LPARAM)
{
Switch (message)
{
Case WM_LBUTTONDOWN://left mouse button under message
{
:: MessageBeep (0); API functions that can emit sounds
}
Break
Case Wm_destroy:
::P ostquitmessage (0);
Break
Default
return::D Efwindowproc (Hwnd,message,wparam,lparam);
}
return 0;
}

Style macros Explain
Ws_border Single-Line border
Ws_caption Window with Title box (including Ws_boder style)
Ws_popup As a pop-up window
Ws_child As a subform (mutex with Ws_popup)
Ws_disabled The window cannot be initialized and the interaction with the user is masked
Ws_dlgframe The window looks similar to the dialog box
Ws_group As a control for a form, you can combine it with other controls
Ws_hscroll The window has a horizontal scroll bar
Ws_vscroll The window has a vertical scroll bar
Ws_maximize window with the initial state as maximized
Ws_maximizebox The top right corner of the window has a maximize button
Ws_minimize window with the initial state minimized
Ws_minimizebox The top right corner of the window has a minimized button
Ws_overlappedwindow This is a macro combination. For ease of writing, it is equivalent to ws_overlapped| ws_caption| ws_sysmenu| ws_thickframe| Ws_minimizebox| Ws_maximizebox
Ws_overlapped window with border overlap
Ws_sizebox The borders of the window can vary
Ws_sysmenu In the top left corner of the title bar of the window, there is a window menu
Ws_tabstop Window as a control, and the interaction can rest on the control
Ws_visible The initial state of the window establishment is visible
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.