C++窗体应用程序

  看了一段时间的C++了,于是就想实战一下,看了网上的一些教程,用vs写一个窗体程序,拉起一个窗口,

本人想着从初级的入门开始,到以后可以根据自己的需求,写出一些上位机软件和一些工具方便自己调试单片机

用。

 1 #include <windows.h>
 2 #include <stdio.h>
 3 #include <tchar.h>
 4 #define WIN32_LEAN_AND_MEAN 
 5 #include <stdlib.h>
 6 #include <malloc.h>
 7 #include <memory.h>
 8 #include "targetver.h"
 9 #include "resource.h"
10 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
11 
12 
13 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
14     _In_opt_ HINSTANCE hPrevInstance,
15     _In_ LPWSTR    lpCmdLine,
16     _In_ int       nCmdShow) {
17     char szClassName[] = "MainWClass";
18     WNDCLASSEX wndclass;
19 
20     wndclass.cbSize = sizeof(wndclass);
21     wndclass.style = CS_HREDRAW | CS_VREDRAW;
22     wndclass.lpfnWndProc = WndProc;
23     wndclass.cbClsExtra = 0;
24     wndclass.cbWndExtra = 0;
25     wndclass.hInstance = hInstance;
26     wndclass.hIcon = ::LoadIcon(NULL,IDI_APPLICATION);
27     wndclass.hCursor = ::LoadCursor(NULL,IDC_ARROW);
28     wndclass.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
29     wndclass.lpszClassName = szClassName;
30     wndclass.lpszMenuName = NULL;
31     wndclass.hIconSm = NULL;
32 
33     ::RegisterClassEx(&wndclass);
34 
35     //创建主窗口
36     HWND hWnd = ::CreateWindowEx(0,
37         szClassName, //类名
38         "GUI",
39         WS_OVERLAPPEDWINDOW,
40         CW_USEDEFAULT,
41         CW_USEDEFAULT,
42         CW_USEDEFAULT,
43         CW_USEDEFAULT,
44         NULL,
45         NULL,
46         hInstance,
47         NULL);
48 
49     if (!hWnd) {
50         ::MessageBox(NULL,"FAIL","ERROR",MB_OK);
51         return FALSE;
52     }
53 
54     //显示窗口
55     ::ShowWindow(hWnd,nCmdShow);
56     ::UpdateWindow(hWnd);
57 
58     //从消息队列中不断的轮询消息
59     MSG msg;
60     while (::GetMessage(&msg, NULL, 0, 0)) {
61         ::TranslateMessage(&msg);
62         ::DispatchMessage(&msg);
63     }
64 
65     return (int)msg.wParam;
66 
67 }
68 
69 
70 
71 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam) {
72     switch (message)
73     {
74     case WM_DESTROY:
75         ::PostQuitMessage(0);
76         break;
77     default:
78         break;
79     }
80     return DefWindowProc(hWnd,message,wparam,lparam);
81 }
Windows 窗体

 

posted @ 2020-05-03 10:44  flyingswallow  阅读(1565)  评论(0编辑  收藏  举报