c++ - Visual C++中的打开窗口程序
问题描述
我刚开始学习用 C++ 开发 Windows 应用程序,我在 Microsoft 文档上找到了一些程序代码,它应该做的就是打开简单的窗口。我试图在visual studio上构建它并且它已经构建但它没有运行。当我尝试使用本地调试器编译和运行它时,我遇到了一些我不知道它是什么的错误。我想得到一些帮助。
这是代码和错误消息。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
解决方案
推荐阅读
- jquery - 如何用 jquery 监听输入类型范围?
- c# - 如何在 mvc c# List 中获取存储过程输出类型值
输入公共函数 - .net - 计划任务抛出 System.IO.IOException
- reporting-services - 使用时间值 SSRS 的表达式更改背景颜色
- c++ - ++ 后面关于引用和作为返回值的语法逻辑
- .net - 有没有办法创建一个可以保证在任何具有 .NET 框架版本 4 的机器上工作的可重复的字符串散列?
- python - 如何通过 requirements.txt 安装 .zip 包?
- windows - WinAPI中全大写的函数名是什么意思?
- python - 存储 pcolormesh 的 Python matplotlib 函数的输出并重建它
- php - 在 Debian 中使用 PDO 读取 mdb 文件返回“分段错误”错误