Collection of everything-win32 form

Source: Internet
Author: User

The following is the simplest win32 form.

# Include "stdafx. h"

Lresult callback MainWndProc (HWND, UINT, WPARAM, LPARAM );

Int APIENTRY WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
Int nCmdShow)
{
// TODO: Place code here.
Char szClassName [] = "MainWClass ";
WNDCLASSEX wndClass;

WndClass. cbSize = sizeof (wndClass );
WndClass. style = CS_HREDRAW | CS_VREDRAW;
WndClass. lpfnWndProc = MainWndProc;
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 = szClassName;
WndClass. hIconSm = NULL;
// Register this window class
: RegisterClassEx (& wndClass );
// Create the Main Window
HWND hwnd =: createmediawex (
0,
SzClassName,
"My frist Wndiows ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
HInstance,
NULL );
If (hwnd = NULL)
{
: MessageBox (NULL, "An error occurred while creating the window! "," Error ", MB_ OK );
Return-1;
}
// Display the window and refresh the customer area
: ShowWindow (hwnd, nCmdShow );
: UpdateWindow (hwnd );
// Retrieve the message from the message queue and send it to the window function for processing until GetMessage returns False to end the message loop.
MSG msg;
While (: GetMessage (& msg, NULL, 0, 0 ))
{
// Convert keyboard messages
: TranslateMessage (& msg );
// Send the message to the corresponding Window Function
: DispatchMessage (& msg );
}
// When GetMessage returns False, the program ends.
Return msg. wParam;
}
Lresult callback MainWndProc (
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
Char szText [] = "the simplest window program! ";
Switch (uMsg)
{
Case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
// Make invalid customer zones valid and obtain the device environment handle
Hdc =: BeginPaint (hwnd, & ps );
// Display text
: TextOut (hdc, 10, 10, szText, strlen (szText ));
: EndPaint (hwnd, & ps );
Return 0;
Case WM_DESTROY:
// Send a WM_QUIT message to the message queue, prompting the GetMessage function to return 0 and end the message loop.
: PostQuitMessage (0 );
Return 0;
}
Return: DefWindowProc (hwnd, uMsg, wParam, lParam );
}
From the code above, we can see the steps for displaying a form on the desktop:

1. Registration window class

2. Create a window

3. display the window on the desktop

4. Update the customer area in the window

5. Enter windows message loop

 

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.