转载自:https://www.136.la/tech/show-149674.html
#include "Windows.h"
#include <iostream>
using namespace std;
#define MAX_LOADSTRING 100
// 全局变量:
HINSTANCE hInst; // 当前实例
std::wstring szTitle = L"RenderCore"; // 标题栏文本
std::wstring szWindowClass = L"WindowClass"; // 主窗口类名
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hRenderWnd;
// 指定窗口大小,窗口大小预设:
// 1279 718
// 800 600
int WindowsWidth = 1279;
int WindowsHeight = 718;
//
// 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, NULL);
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass.c_str();
wcex.hIconSm = LoadIcon(wcex.hInstance, NULL);
return RegisterClassExW(&wcex);
}
//
// 函数: InitInstance(HINSTANCE, int)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 将实例句柄存储在全局变量中
// 基于客户端面积区域计算窗口矩形大小
RECT R = { 0, 0, WindowsWidth, WindowsHeight };
AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false);
int width = R.right - R.left;
int height = R.bottom - R.top;
hRenderWnd = CreateWindowW(
szWindowClass.c_str(),
szTitle.c_str(),
WS_OVERLAPPEDWINDOW,
1000,
300,
width,
height,
nullptr,
nullptr,
hInstance,
nullptr
);
if (!hRenderWnd)
{
MessageBox(0, L"CreateWindow Failed.", 0, 0);
return FALSE;
}
ShowWindow(hRenderWnd, SW_SHOW);
UpdateWindow(hRenderWnd);
return TRUE;
}
//
// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目的: 处理主窗口的消息。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: 在此处添加使用 hdc 的任何绘图代码...
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
int main()
{
HINSTANCE hInstance = ::GetModuleHandle(NULL);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance(hInstance, SW_SHOW))
{
return FALSE;
}
MSG msg;
// 主消息循环:
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 原文地址:http://www.cnblogs.com/CJWBLOG/p/5638424.html