我开始使用 C++ 进行编程,并想开始使用图形和用户界面制作应用程序。
我看过很多关于这个主题的教程, 并已完成本教程的第一部分 但是窗口拒绝弹出,我知道它正在工作,因为没有错误, 我可以看到它在任务管理器中运行。 请帮忙。
听到的是代码:
$(function() {
let lop = "<ol>";
$('.boxes-section .box-section-item .btText h2 strong').each(function() {
let uid = "ID-"+Math.floor(Math.random() * Math.floor(99999));
lop += "<li data-trigger='"+uid+"'>"+$(this).text()+"</li>";
$(this).attr('id', uid);
});
lop += "</ol>";
$('.listofparticipants').html(lop).show();
$(document).on("click", ".listofparticipants ol li", function() {
var extraspace = $('header#header').height() + $('#wpadminbar').height() + $('#wpfront-notification-bar').height();
extraspace = extraspace + 40;
$('html, body').delay(2000).animate({scrollTop: $("#" + $(this).attr('data-trigger')).offset().top - extraspace}, 1000);
});
});
答案 0 :(得分:3)
窗口拒绝弹出,我知道它正在工作,因为那里 没有错误,我可以看到它在任务管理器中运行。
您没有检查 RegisterClass 和 CreateWindowA 函数调用的错误。
查看RegisterClass()
的返回值会发现返回值为零,表示失败。要获取扩展错误信息,请调用 GetLastError。
CreateWindowA()
也失败,返回值为 NULL。要获取扩展错误信息,请调用 GetLastError
。
如果您使用这些函数的 ANSI 版本,请将 WNDCLASS
更改为 WNDCLASSA
,将 RegisterClass
更改为 RegisterClassA
。
您在两个函数中都遗漏了类名。以下是基于您提供的代码使窗口显示的示例。你可以试试。
CHAR clsName[] = "test";
WNDCLASSA window_class = {};
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.lpszClassName = clsName;
window_class.lpfnWndProc = windows_callback;
//register clases
ATOM atom = RegisterClassA(&window_class);
if (0 == atom)
{
DWORD err = GetLastError();
return 0;
}
// create window
HWND window = CreateWindowA(clsName, "game stuff", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 720, 360, 0, 0, hInstance, 0);
if (NULL == window)
{
DWORD err = GetLastError();
return 0;
}
更多参考:“Your First Windows Program”、“Unicode in the Windows API”。
更新:
<块引用>为什么有中文名(窗口名显示unexecpted)
为了使用上面的示例代码来显示预期的窗口名称,您可以将项目设置更改为“使用多字节字符集”,如下所示:
或者您可以将 UNICODE API(RegisterClassW
和 CreateWindowW
)与项目设置“使用 Unicode 字符集”一起使用。
或者您可以使用RegisterClassEx
和CreateWindowEx
等宏,它会自动选择UNICODE或ASCII版本API以及您的项目设置。