ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
`` ``` #include "stdafx.h" #include <tchar.h> #include <windows.h> #include <stdio.h> #include "resource.h" #include <locale.h> #include <process.h> #include "Project1win2console181010a.h" #define MAX_LOADSTRING 100 // 全局变量: HINSTANCE hInst; // 当前实例 WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本 WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名 // 此代码模块中包含的函数的前向声明: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // AllocConsole(); #pragma warning(disable:4996) _tfreopen(TEXT("CONOUT$"), TEXT("w"), stdout); _tfreopen(TEXT("CONOUT$"), TEXT("w"), stderr); _tfreopen(TEXT("CONIN$"), TEXT("r"), stdin); #pragma warning(default:4996) _tsetlocale(LC_ALL, TEXT("chs")); printf("pi:"); printf("%lf", 3.1415926); printf("%d", 3.1415); // // TODO: 在此处放置代码。 // 初始化全局字符串 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_PROJECT1WIN2CONSOLE181010A, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } ``` 重点是头文件; 和: `` int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) 函数当中的: (第40行左右的):打开 AllocConsole()窗口语句: ``` AllocConsole(); #pragma warning(disable:4996) _tfreopen(TEXT("CONOUT$"), TEXT("w"), stdout); _tfreopen(TEXT("CONOUT$"), TEXT("w"), stderr); _tfreopen(TEXT("CONIN$"), TEXT("r"), stdin); #pragma warning(default:4996) _tsetlocale(LC_ALL, TEXT("chs")); ```