当前位置:网站首页>Vs2019 desktop app quick start
Vs2019 desktop app quick start
2022-07-06 11:24:00 【imxlw00】
Create project
choice windows Desktop wizard 
Configuration items

Choose the type of program

Write code

#include <windows.h> // The underlying implementation window The header file
//6 Process window
//CALLBACK representative __stdcall The order in which parameters are passed : From right to left To stack , And before the function returns Empty stack
LRESULT CALLBACK WindowProc(
HWND hwnd, // The window handle to which the message belongs
UINT uMsg, // Specific message name WM_XXXX Message name
WPARAM wParam, // Keyboard additional messages
LPARAM lParam // Mouse attached message
)
{
switch (uMsg)
{
case WM_CLOSE:
// all xxxWindow The way to end , Will not enter the message queue , I'm going to do it directly
DestroyWindow(hwnd); //DestroyWindow Send another message WM_DESTROY
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN: // Press the left mouse button
{
int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam);
char buf[1024];
wsprintf(buf,TEXT("x = %d,y = %d"), xPos, yPos);
MessageBox(hwnd, buf, TEXT(" Press the left mouse button "), MB_OK);
break;
}
case WM_KEYDOWN: // keyboard
MessageBox(hwnd, TEXT(" Press the keyboard "), TEXT(" Press the keyboard "), MB_OK);
break;
case WM_PAINT: // mapping
{
PAINTSTRUCT ps; // Drawing structure
HDC hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 100, 100, TEXT("HELLO"), strlen("HELLO"));
EndPaint(hwnd, &ps);
}
break;
}
// The default processing method is used for the return value
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
// Program entry function
//WINAPI representative __stdcall The order in which parameters are passed : From right to left To stack , And before the function returns Empty stack
int WINAPI WinMain(
HINSTANCE hInstance, // Application instance handle
HINSTANCE hPrevInstance, // Last application handle , stay win32 In the environment , The parameter is generally NULL, It doesn't work
LPSTR lpCmdLine, //char * argv[]
int nShowCmd) // Show command Maximize 、 To minimize the normal
{
//1、 Design window
//2、 Registration window
//3、 create a window
//4、 Display and update
//5、 Get message through loop
//6、 Process the message ( Window procedure )
//1、 Design window
WNDCLASS wc;
wc.cbClsExtra = 0; // Class
wc.cbWndExtra = 0; // Extra memory for Windows
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // Set the background
wc.hCursor = LoadCursor(NULL, IDC_HAND); // Set the cursor If the first parameter is NULL, Represents using the cursor provided by the system
wc.hIcon = LoadIcon(NULL, IDI_ERROR); // Icon If the first parameter is NULL, Represents using the cursor provided by the system
wc.hInstance = hInstance; // Application instance handle Pass in WinMain The formal parameter in the
wc.lpfnWndProc = WindowProc; // Callback function Window procedure
wc.lpszClassName = TEXT("WIN"); // Specify the window class name
wc.lpszMenuName = NULL; // Menu name
wc.style = 0; // Display style 0 Represents the default style
//2、 Register window class
RegisterClass(&wc);
//3、 create a window
/* lpClassName, Class name lpWindowName, Title name dwStyle, WS_OVERLAPPEDWINDOW style x, Show coordinates CW_USEDEFAULT The default value is y, nWidth, Wide and high nHeight, hWndParent, The parent window NULL hMenu, menu NULL hInstance, Instance handle hInstance lpParam) Added value NULL */
HWND hwnd = CreateWindow(wc.lpszClassName, TEXT("WINDOWS"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
//4、 Display and update
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
//5、 Get message through loop
/* HWND hwnd; Main window handle UINT message; Specific message name WPARAM wParam; Additional messages Keyboard messages LPARAM lParam; Additional messages Mouse message DWORD time; Message generation time POINT pt; Additional messages Mouse message x y */
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
/* _Out_ LPMSG lpMsg, news _In_opt_ HWND hWnd, Capture window fill NULL For capturing all windows _In_ UINT wMsgFilterMin, // Minimum and maximum filtered messages Generally fill in 0 _In_ UINT wMsgFilterMax) // fill 0 Capture all messages on behalf of */
//if (GetMessage(&msg, NULL, 0, 0) == FALSE)
//{
// break;
//}
// Translate the news
TranslateMessage(&msg);
// Not for false
// Distribution message
DispatchMessage(&msg);
}
return 0;
}
Running results

边栏推荐
- Machine learning notes week02 convolutional neural network
- Aborted connection 1055898 to db:
- Record a problem of raspberry pie DNS resolution failure
- Asp access Shaoxing tourism graduation design website
- Introduction to the easy copy module
- MySQL completely uninstalled (windows, MAC, Linux)
- Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
- MySQL的一些随笔记录
- [recommended by bloggers] C WinForm regularly sends email (with source code)
- Ubuntu 20.04 安装 MySQL
猜你喜欢

double转int精度丢失问题

When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page

Cookie setting three-day secret free login (run tutorial)

Learn winpwn (2) -- GS protection from scratch

图片上色项目 —— Deoldify

软件测试与质量学习笔记3--白盒测试

Asp access Shaoxing tourism graduation design website
![[download app for free]ineukernel OCR image data recognition and acquisition principle and product application](/img/1b/ed39a8b9181660809a081798eb8a24.jpg)
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application

Swagger、Yapi接口管理服务_SE

Pytorch基础
随机推荐
vs2019 使用向导生成一个MFC应用程序
How to build a new project for keil5mdk (with super detailed drawings)
图片上色项目 —— Deoldify
How to configure flymcu (STM32 serial port download software) is shown in super detail
QT creator shape
Record a problem of raspberry pie DNS resolution failure
[number theory] divisor
Codeforces Round #753 (Div. 3)
MTCNN人脸检测
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
neo4j安装教程
How to set up voice recognition on the computer with shortcut keys
L2-004 这是二叉搜索树吗? (25 分)
MySQL other hosts cannot connect to the local database
Ubuntu 20.04 安装 MySQL
UDS learning notes on fault codes (0x19 and 0x14 services)
数据库高级学习笔记--SQL语句
Antlr4 uses keywords as identifiers
Copie maître - esclave MySQL, séparation lecture - écriture
解决安装Failed building wheel for pillow