// Win32.cpp : 定义应用程序的入口点。 // #include "stdafx.h" #include "Win32.h" void TRACE(LPCTSTR lpszFmt, ...);//调试信息 LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);//消息处理函数 int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { //定义窗口类 TCHAR *ClassName = _T("WIN32窗口程序"); WNDCLASS wndclass = {0}; wndclass.hbrBackground = (HBRUSH)COLOR_MENU; wndclass.lpfnWndProc = WindowProc; wndclass.lpszClassName = ClassName; wndclass.hInstance = hInstance; //注册窗口类 RegisterClass(&wndclass); HWND hwnd = CreateWindow( ClassName, _T("第一个窗口"), WS_OVERLAPPEDWINDOW, 100, 100, 600, 400, NULL, NULL, hInstance, NULL ); if (hwnd ==NULL) { return 0; } //显示窗口 ShowWindow(hwnd, SW_SHOW); //消息循环 MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } //TRACE(_T("%d %s"), 1243, a); return 0; } //调试信息输出 void TRACE(LPCTSTR lpszFmt, ...) { va_list args; va_start(args, lpszFmt); int len = _vsctprintf(lpszFmt, args) + 1; TCHAR *lpszBuf = (TCHAR*)_alloca(len*sizeof(TCHAR));//栈中分配, 不需要释放 _vstprintf_s(lpszBuf, len, lpszFmt, args); va_end(args); OutputDebugString(lpszBuf); } //消息回调函数 LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { return DefWindowProc(hwnd, uMsg, wParam, lParam); }