admin管理员组文章数量:1344231
I am writing some code using the Windows API to open a window. But, for some reason, the window won't open. I tried to use breakpoints to check the code line by line, but even breakpoints aren't working. When checking the output window, it says:
The program exited with code 0x1
I tried to use the MessageBox()
function to gather some further information, but even MessageBox()
isn't showing. The program instantly closes.
#include "app_core.h"
LRESULT CALLBACK _Window_Procedure_(HWND, UINT, WPARAM, LPARAM);
_App_Core_::_App_Core_(const std::string_view &winName)
: _My_Name_(winName), _Core_Hwnd_(nullptr), _Core_Hinstance_(GetModuleHandle(NULL))
{
// _Class_Name_
std::wstring _Class_Name_ = _Convert_Char_To_Wchar_(_My_Name_.data(), TRUE, "_Class_");
// _Window_Class_
WNDCLASSEX _Window_Class_Ex_ = {};
{
_Window_Class_Ex_.cbSize = sizeof(WNDCLASSEX);
_Window_Class_Ex_.hInstance = _Core_Hinstance_;
_Window_Class_Ex_.lpszClassName = _Class_Name_.data();
_Window_Class_Ex_.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
_Window_Class_Ex_.hCursor = LoadCursor(NULL, IDC_ARROW);
_Window_Class_Ex_.hIcon = LoadIcon(NULL, IDI_WINLOGO);
_Window_Class_Ex_.lpfnWndProc = _Window_Procedure_;
_Window_Class_Ex_.lpszMenuName = 0;
_Window_Class_Ex_.style = 0;
}
// _Register_Class_Ex_
RegisterClassEx(&_Window_Class_Ex_);
// _Create_Window_Ex_
_Core_Hwnd_ = CreateWindowEx(
0,
_Class_Name_.data(),
_Convert_Char_To_Wchar_(_My_Name_.data(), false, "").c_str(),
WS_OVERLAPPED | WS_OVERLAPPEDWINDOW,
0, 0, 480, 360,
NULL, NULL, _Core_Hinstance_, NULL
);
// _Show_Window_Update_Window_
_Show_Window_Update_Window_(_Core_Hwnd_);
MessageBoxA(NULL, "A", "A", MB_OK); // Debug: Doesn't work (Window closes before showing it).
// _Get_Message_
for (MSG _Window_Message_ = {}; GetMessage(&_Window_Message_, NULL, 0, 0) > 0;)
{
DispatchMessage(&_Window_Message_);
TranslateMessage(&_Window_Message_);
}
}
HWND _App_Core_::_Parent_() const
{
// _Core_Hwnd_
return _Core_Hwnd_;
}
VOID _App_Core_::_Destroy_()
{
// _Destroy_Window_
if (_Core_Hwnd_)
DestroyWindow(_Core_Hwnd_);
_Core_Hwnd_ = nullptr;
_Core_Hinstance_ = nullptr;
}
LRESULT CALLBACK _Window_Procedure_(
HWND _Core_Hwnd_,
UINT _Un_Msg_,
WPARAM _Wide_Param_,
LPARAM _L_Wide_Param_)
{
// _Switch_Un_Msg_
switch (_Un_Msg_)
{
// _Wm_Destroy_
case 0x0002: // WM_DESTROY
PostQuitMessage(0);
return 0;
case 0x000F: // WM_PAINT
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(_Core_Hwnd_, &ps);
// All painting occurs here, between BeginPaint and EndPaint.
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(_Core_Hwnd_, &ps);
}
return 0;
}
return DefWindowProc(_Core_Hwnd_, _Un_Msg_, _Wide_Param_, _L_Wide_Param_);
}
本文标签: cWindow won39t openStack Overflow
版权声明:本文标题:c++ - Window won't open - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743737669a2530305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论