一个小挑战?

VS2017里面,新建一个控制台工程,输入名字(你不需要也成,有默认的),得到一个控制台工程。

好了,生成的代码,如下:

// Win32InConsole.cpp : This file contains the 'main' function. Program execution begins and ends there.
// #include "pch.h"
#include <iostream> int main()
{
std::cout << "Hello World!\n";
} // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file

这里有一大堆的废代码,但是,我还是把它放上来了,忘了说,我的VS2017语言版本是英文版的,为什么弄英文版呢?因为我不想遇到太多的与中文与VS2017相关的麻烦,反正就是,设置为英文,好外多多,你不会动不动因为这VS的一些BUG而导致工作流中断,最后,你找来找去,才发现,原来是VS的问题。

现在上正题,代码如下:

// Win32InConsole.cpp : This file contains the 'main' function. Program execution begins and ends there.
// #include "pch.h"
#include <iostream> #include <windows.h>
#define CLASS_NAME TEXT("First")
int NewWindow(); int main()
{
std::cout << "Hello World!\n";
return NewWindow();
} // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file //我就不声明了,在这里直接上代码
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0); //一定要加啊
break;
default:
break;
} return DefWindowProc(hWnd, message, wParam, lParam);
} int NewWindow()
{
WNDCLASS ws = { 0 };
ws.cbClsExtra = sizeof(ws);
ws.lpfnWndProc = WndProc;
ws.lpszClassName = CLASS_NAME;
if (!::RegisterClass(&ws)) return -1;
HWND hWnd = CreateWindow(CLASS_NAME, CLASS_NAME, WS_OVERLAPPEDWINDOW
, 100, 100, 800, 600, NULL, NULL, NULL, NULL);
if (!hWnd) return -2; ShowWindow(hWnd, SW_SHOW); MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam; }

好了,事情就是这么简单!!!

附上两个图:

关闭WIN32窗口后

如何在Console下面生成一个WIN32窗口的更多相关文章

  1. cmake 如何生成一个win32工程

    只需要加上下面一句连接选项就可以了. IF(WIN32) SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:W ...

  2. 要生成一个窗口,通常使用Window的子类Frame类进行实例化

    要生成一个窗口,通常使用Window的子类Frame类进行实例化,而不是直接使用Window 类,框架的外观就像平常Windows系统下的窗口,有标题.边框. 菜单 和大小等. setSize()方法 ...

  3. Nehe OpenGL教程第一课-创建一个OpenGL窗口(Win32)

       原文英文地址为:Creating an OpenGL Window (Win32),翻译的chm中文格式文档下载地址为:OpenGL教程电子书(chm格式)中文版,源代码在官网上也可以下载到,每 ...

  4. 如何在github上展示作品——为你的项目生成一个快速访问的网址如(DaisyWang88.github.io)

      (这里值针对Windos系统的,因为本人用的是Window系统,暂时没有条件在其他平台上测试)   1.创建命名为 <userName>.github.io的仓库.      这里的u ...

  5. 第一个手写Win32窗口程序

    第一个手写Win32窗口程序 一 Windows编程基础 1 Win32应用程序的基本类型 1.1 控制台程序 不需要完善的Windows窗口,可以使用DOS窗口 的方式显示. 1.2 Win32窗口 ...

  6. (7)nehe教程1 创建一个OpenGL窗口:

    不要用那个nehe ndk了 误人子弟! 转自: 一个窗口,代码可真多啊 http://www.yakergong.net/nehe/ 在这个教程里,我将教你在Windows环境中创建OpenGL程序 ...

  7. 如何在pyqt中给无边框窗口添加DWM环绕阴影

    前言 在之前的博客<如何在pyqt中通过调用SetWindowCompositionAttribute实现Win10亚克力效果>中,我们实现了窗口的亚克力效果,同时也用SetWindowC ...

  8. 让我们写一个 Win32 文本编辑器吧 - 2. 计划和显示

    让我们写一个 Win32 文本编辑器吧 - 2. 计划和显示 如果你已经阅读了简介,相信你已经对我们接下来要做的事情有所了解. 本文,将会把简介中基础程序修改为一个窗体应用程序.并对编辑器接下来的编辑 ...

  9. Win32 - 窗口

    Win32 - 窗口 目录 Win32 - 窗口 前言 流程图 创建项目 VS MinGW Win32API字符串 Unicode 和 ANSI 函数 TCHAR WinMain:Win32 Appl ...

随机推荐

  1. shutil模块(了解)

    目录 一.shutil模块 1.1 zipfile压缩解压缩 1.2 tarfile压缩解压缩 一.shutil模块 高级的文件.文件夹.压缩包处理模块. import shutil # shutil ...

  2. javascript中的闭包、函数的toString方法

    闭包: 闭包可以理解为定义在一个函数内部的函数, 函数A内部定义了函数B, 函数B有访问函数A内部变量的权力: 闭包是函数和子函数之间的桥梁: 举个例子: let func = function() ...

  3. Python连载53-UDP、TCP、FTP编程实例

    一.服务器程序要求永远运行,一般用死循环来处理 1.服务器改造版本V03(主程序 原封不动,这里只修改了运行的程序) if __name__ == "__main__": whil ...

  4. Python连载47-json文件、正则表达式初步

    一.在线工具 1.https://www.sojson.com/ 2.http://www.w3cshool.com.cn/json/ 3.http://www.runoob.com/json/jso ...

  5. MySQL中使用group_concat遇到的坑

    在使用group_concat的过程中遇到个问题,这里记录一下:在MySQL中有个配置参数group_concat_max_len,它会限制使用group_concat返回的最大字符串长度,默认是10 ...

  6. Algorithm: Prime & Euler Function & Productive Function

    素数筛 朴素算法 一般来说,可以用试除法判断某一个数是不是素数: bool isPrime(int n) { if(n < 2) return false; for(int i = 2; i & ...

  7. Linux war包部署jenkins

    一.介绍Jenkins 1.Jenkins概念 Jenkins是一个功能强大的应用程序,允许持续集成和持续交付项目,无论用的是什么平台.这是一个免费的源代码,可以处理任何类型的构建或持续集成.集成Je ...

  8. linux的ls命令详解

    概述 Linux ls命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录). 语法 ls [-alrtAFR] [name...] 参数 -a 显示所有文件及目录 (ls内定将文件名 ...

  9. 解决java导入project出现红叉

    1.右击,import,选择需要导入的文件组. D:\softwar\seeyon\A8\ApacheJetspeed\webapps\seeyon\WEB-INF\lib  全选,打开,finish ...

  10. 织梦DEDECMS本地后台操作卡顿的解决方法

    打开/data/common.inc.php,把默认的$cfg_dbhost = ‘localhost‘修改为$cfg_dbhost = ‘127.0.0.1’;保存.然后你会发现后台操作起来流畅多了 ...