win32程序启用控制台

 1 #include <cstdio>
 2 #define USE_WIN32_CONSOLE
 3 
 4 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
 5                      _In_opt_ HINSTANCE hPrevInstance,
 6                      _In_ LPWSTR    lpCmdLine,
 7                      _In_ int       nCmdShow)
 8 {
 9     UNREFERENCED_PARAMETER(hPrevInstance);
10     UNREFERENCED_PARAMETER(lpCmdLine);
11 
12 #ifdef USE_WIN32_CONSOLE
13     AllocConsole();
14     freopen("CONIN$", "r", stdin);
15     freopen("CONOUT$", "w", stdout);
16     freopen("CONOUT$", "w", stderr);
17 #endif
18 
19     // TODO: Place code here.
20 
21     // Initialize global strings
22     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
23     LoadStringW(hInstance, IDC_WIN32TEST, szWindowClass, MAX_LOADSTRING);
24     MyRegisterClass(hInstance);
25 
26     // Perform application initialization:
27     if (!InitInstance (hInstance, nCmdShow))
28     {
29         return FALSE;
30     }
31 
32     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32TEST));
33 
34     MSG msg;
35 
36     // Main message loop:
37     while (GetMessage(&msg, nullptr, 0, 0))
38     {
39         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
40         {
41             TranslateMessage(&msg);
42             DispatchMessage(&msg);
43         }
44     }
45 
46 #ifdef USE_WIN32_CONSOLE
47     FreeConsole();
48 #endif
49 
50     return (int) msg.wParam;
51 }

主要是12-17行,46-48行的部分.

转载于:https://www.cnblogs.com/rok-aya/p/5211951.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值