初次学习windows编程, 环境是vs2013,想要画个矩形,结果编译后就成这个样子了,希望得到前辈的解答
1 #include <Windows.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <tchar.h> 5 6 // Global variables 7 // The main window class name 8 TCHAR szWindowClass[] = _T("Win32app"); 9 10 // The string that appear in the application's title bar 11 TCHAR szTitle[] = _T("Win32"); 12 HINSTANCE hInst; 13 14 // Forward declaration of function 15 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 16 17 18 int WINAPI WinMain(HINSTANCE hInstance, 19 HINSTANCE hPrevInstace, 20 LPSTR lpCmdLine, 21 int nCmdShow) 22 { 23 WNDCLASSEX wcex; 24 25 wcex.cbSize = sizeof(WNDCLASSEX); 26 wcex.style = CS_HREDRAW | CS_VREDRAW; 27 wcex.lpfnWndProc = WndProc; 28 wcex.cbClsExtra = 0; 29 wcex.cbWndExtra = 0; 30 wcex.hInstance = hInstance; 31 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); 32 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 33 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 34 wcex.lpszMenuName = NULL; 35 wcex.lpszClassName = szWindowClass; 36 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); 37 38 if (!RegisterClassEx(&wcex)) 39 { 40 MessageBox(NULL, 41 _T("Call to RegisterClassEx failed!"), 42 _T("Win32 Guided Tour"), 43 NULL); 44 45 return 1; 46 } 47 48 hInst = hInstance; // Store instance handle in our global variable. 49 50 51 HWND hWnd = CreateWindow( 52 szWindowClass, 53 szTitle, 54 WS_OVERLAPPEDWINDOW, 55 CW_USEDEFAULT, CW_USEDEFAULT, 56 500, 100, 57 NULL, 58 NULL, 59 hInstance, 60 NULL); 61 62 if (!hWnd) 63 { 64 MessageBox(NULL, 65 _T("Call to CreateWindow failed!"), 66 _T("Win32 Guided Tour"), 67 NULL); 68 69 return 1; 70 } 71 72 ShowWindow(hWnd, nCmdShow); 73 UpdateWindow(hWnd); 74 75 MSG msg; 76 77 while (GetMessage(&msg, NULL, 0, 0)) 78 { 79 TranslateMessage(&msg); 80 DispatchMessage(&msg); 81 } 82 83 return (int)msg.wParam; 84 } 85 86 87 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 88 { 89 switch (message) 90 { 91 92 case WM_PAINT: 93 { 94 PAINTSTRUCT ps; 95 BeginPaint(hWnd, &ps); 96 97 RECT rc; 98 GetClientRect( 99 hWnd, 100 &rc 101 ); 102 103 104 HGDIOBJ original = NULL; 105 original = SelectObject( 106 ps.hdc, 107 GetStockObject(DC_PEN) 108 ); 109 110 HPEN blackPen = CreatePen(PS_SOLID, 3, 0); 111 112 113 SelectObject(ps.hdc, blackPen); 114 115 Rectangle( 116 ps.hdc, 117 rc.left + 100, 118 rc.top + 100, 119 rc.right - 100, 120 rc.bottom - 100); 121 122 DeleteObject(blackPen); 123 124 125 SelectObject(ps.hdc, original); 126 127 EndPaint(hWnd, &ps); 128 } 129 return 0; 130 } 131 132 }