看了一段時間的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 }