Написал небольшой класс который в будущем будет выступать в роли полноценного фреймворка, все работает, утечек вроде бы нет, нет никаких ошибок, но вот деструктор... Как будто в нем чего-то не хватает.
#ifndef FRAME_WORK_H
#define FRAME_WORK_H
#include <Windows.h>
#ifdef UNICODE
#define set_window_title set_window_title_w
#define get_window_title get_window_title_w
#define init init_w
#define _(x) L##x
#else
#define set_window_title set_window_title_a
#define get_window_title get_window_title_a
#define init init_a
#define _(x) x
#endif
class frame_work
{
public:
frame_work();
~frame_work();
void run();
int run_rv();
bool init_a();
bool init_w();
bool init_a(HINSTANCE application_instance);
bool init_w(HINSTANCE application_instance);
bool init_a(HINSTANCE application_instance, const char* window_title);
bool init_w(HINSTANCE application_instance, const wchar_t* window_title);
bool init_a(HINSTANCE application_instance, const char* window_title, int x, int y);
bool init_w(HINSTANCE application_instance, const wchar_t* window_title, int x, int y);
bool init_a(HINSTANCE application_instance, const char* window_title, int x, int y, int w, int h);
bool init_w(HINSTANCE application_instance, const wchar_t* window_title, int x, int y, int w, int h);
HWND get_hwnd() const;
char* get_window_title_a() const;
wchar_t* get_window_title_w() const;
bool set_window_title_a(char* window_title);
bool set_window_title_w(wchar_t* window_title);
private:
HINSTANCE m_app_instance_;
HWND m_window_handle_;
char* m_window_class_name_a_;
char* m_window_title_a_;
wchar_t* m_window_class_name_w_;
wchar_t* m_window_title_w_;
};
#endif // FRAME_WORK_H
#include "frame_work.h"
LRESULT CALLBACK window_proc(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
switch (umsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return
#ifdef UNICODE
DefWindowProcW(hWnd, umsg, wParam, lParam);
#else
DefWindowProcA(hWnd, umsg, wParam, lParam);
#endif
}
return 0;
}
frame_work::frame_work(): m_app_instance_(nullptr), m_window_handle_(nullptr), m_window_class_name_a_(nullptr),
m_window_title_a_(nullptr), m_window_class_name_w_(nullptr), m_window_title_w_(nullptr)
{
}
frame_work::~frame_work()
{
#ifdef UNICODE
UnregisterClassW(m_window_class_name_w_, m_app_instance_);
#else
UnregisterClassA(m_window_class_name_a_, m_app_instance_);
#endif
m_window_handle_ = nullptr;
m_window_class_name_w_ = nullptr;
m_window_class_name_a_ = nullptr;
m_window_title_w_ = nullptr;
m_window_title_a_ = nullptr;
}
void frame_work::run()
{
MSG msg;
memset(&msg, 0, sizeof(MSG));
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, nullptr, 0, 0L, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
int frame_work::run_rv()
{
MSG msg;
memset(&msg, 0, sizeof(MSG));
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, nullptr, 0, 0L, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return static_cast<int>(msg.wParam);
}
bool frame_work::init_a()
{
return init_a(GetModuleHandleA(nullptr));
}
bool frame_work::init_w()
{
return init_w(GetModuleHandleW(nullptr));
}
bool frame_work::init_a(const HINSTANCE application_instance)
{
return init_a(application_instance, "Untitled Window");
}
bool frame_work::init_w(const HINSTANCE application_instance)
{
return init_w(application_instance, L"Untitled Window");
}
bool frame_work::init_a(const HINSTANCE application_instance, const char* window_title)
{
return init_a(application_instance, window_title, 0, 0);
}
bool frame_work::init_w(const HINSTANCE application_instance, const wchar_t* window_title)
{
return init_w(application_instance, window_title, 0, 0);
}
bool frame_work::init_a(const HINSTANCE application_instance, const char* window_title, const int x, const int y)
{
return init_a(application_instance, window_title, x, y, 640, 480);
}
bool frame_work::init_w(const HINSTANCE application_instance, const wchar_t* window_title, const int x, const int y)
{
return init_w(application_instance, window_title, x, y, 640, 480);
}
bool frame_work::init_a(const HINSTANCE application_instance, const char* window_title, const int x, const int y,
const int w, const int h)
{
m_app_instance_ = application_instance;
m_window_title_a_ = const_cast<char*>(window_title);
m_window_class_name_a_ = "AnimeWatchFrameWorkWindowClassName";
WNDCLASSEXA wc;
memset(&wc, 0, sizeof(WNDCLASSEXA));
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.cbSize = sizeof(WNDCLASSEXA);
wc.hCursor = LoadCursorA(nullptr, MAKEINTRESOURCEA(32512));
wc.hIcon = LoadIconA(nullptr, MAKEINTRESOURCEA(32512));
wc.hIconSm = LoadIconA(nullptr, MAKEINTRESOURCEA(32512));
wc.hbrBackground = reinterpret_cast<HBRUSH>(6);
wc.hInstance = m_app_instance_;
wc.lpszClassName = m_window_class_name_a_;
wc.lpszMenuName = nullptr;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = window_proc;
if (!RegisterClassExA(&wc))
{
OutputDebugStringA("Unable to register window class\n");
return false;
}
m_window_handle_ = CreateWindowExA(0L, m_window_class_name_a_, m_window_title_a_, WS_OVERLAPPEDWINDOW, x, y, w, h,
nullptr, nullptr, m_app_instance_, nullptr);
if (!m_window_handle_)
{
OutputDebugStringA("Unable to create window\n");
return false;
}
UpdateWindow(m_window_handle_);
ShowWindow(m_window_handle_, SW_SHOW);
SetForegroundWindow(m_window_handle_);
SetFocus(m_window_handle_);
return true;
}
bool frame_work::init_w(const HINSTANCE application_instance, const wchar_t* window_title, const int x, const int y,
const int w, const int h)
{
m_app_instance_ = application_instance;
m_window_title_w_ = const_cast<wchar_t*>(window_title);
m_window_class_name_w_ = L"AnimeWatchFrameWorkWindowClassName";
WNDCLASSEXW wc;
memset(&wc, 0, sizeof(WNDCLASSEXW));
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.hCursor = LoadCursorW(nullptr, MAKEINTRESOURCEW(32512));
wc.hIcon = LoadIconW(nullptr, MAKEINTRESOURCEW(32512));
wc.hIconSm = LoadIconW(nullptr, MAKEINTRESOURCEW(32512));
wc.hbrBackground = reinterpret_cast<HBRUSH>(6);
wc.hInstance = m_app_instance_;
wc.lpszClassName = m_window_class_name_w_;
wc.lpszMenuName = nullptr;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = window_proc;
if (!RegisterClassExW(&wc))
{
OutputDebugStringW(L"Unable to register window class\n");
return false;
}
m_window_handle_ = CreateWindowExW(0L, m_window_class_name_w_, m_window_title_w_, WS_OVERLAPPEDWINDOW, x, y, w, h,
nullptr, nullptr, m_app_instance_, nullptr);
if (!m_window_handle_)
{
OutputDebugStringW(L"Unable to create window\n");
return false;
}
UpdateWindow(m_window_handle_);
ShowWindow(m_window_handle_, SW_SHOW);
SetForegroundWindow(m_window_handle_);
SetFocus(m_window_handle_);
return true;
}
HWND frame_work::get_hwnd() const
{
return m_window_handle_ ? m_window_handle_ : nullptr;
}
char* frame_work::get_window_title_a() const
{
return m_window_title_a_;
}
wchar_t* frame_work::get_window_title_w() const
{
return m_window_title_w_;
}
bool frame_work::set_window_title_a(char* window_title)
{
m_window_title_a_ = window_title;
return SetWindowTextA(m_window_handle_, window_title);
}
bool frame_work::set_window_title_w(wchar_t* window_title)
{
m_window_title_w_ = window_title;
return SetWindowTextW(m_window_handle_, window_title);
}
Оборудование для ресторана: новинки профессиональной кухонной техники
Частный дом престарелых в Киеве: комфорт, забота и профессиональный уход
Допустим у меня есть сущность loan, у нее поле countryЯ хотел бы как-то реагировать на случай превышения некоторого числа запросов на секунду времени...
Есть простой интерфейс, при нажатии кнопки запускается процесс обработки загруженных данных
вчем разница между variable, object,type and class