2020-02-29 10:33:37 +01:00

113 lines
3.1 KiB
C++

#include "Logger.h"
eg3d::Logger gLogger;
namespace eg3d {
const char * Logger::sDEF_LoggerCaption = "Logger";
bool Logger::sWindowClassInitialized = false;
Logger::Logger()
{
// új window class létrehozása
if (!sWindowClassInitialized) {
WNDCLASSEX wcl;
wcl.hInstance = gEntryArgs.hThisInstance;
wcl.lpszClassName = "LoggerWndClass";
wcl.lpfnWndProc = smLoggerWindowFunc;
wcl.style = 0;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(nullptr, IDI_WINLOGO);
wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcl.lpszMenuName = nullptr;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = static_cast<HBRUSH>(GetStockObject(DKGRAY_BRUSH));
if (!RegisterClassEx(&wcl))
{
ERRBOX("Couldn't register window class for eg3d::Window");
}
sWindowClassInitialized = true;
}
// ablak létrehozása
mHWND = CreateWindowA("LoggerWndClass",
"logger",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
nullptr,
gEntryArgs.hThisInstance,
nullptr);
SetWindowLongA(mHWND, GWL_STYLE, GetWindowLongA(mHWND, GWL_STYLE) ^ (WS_THICKFRAME | WS_MAXIMIZEBOX));
UpdateWindow(mHWND);
ShowWindow(mHWND, SW_SHOW);
SetWindowTextA(mHWND, sDEF_LoggerCaption);
// listbox létrehozása
mhListBox = CreateWindow("LISTBOX",
nullptr,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL,
0, 0, sDEF_width, sDEF_height,
mHWND,
nullptr,
gEntryArgs.hThisInstance,
nullptr);
// átméretezés
RECT winRect;
GetWindowRect(mHWND, &winRect);
// terület beállítása
winRect.right = winRect.left + sDEF_width;
winRect.bottom = winRect.top + sDEF_height;
// keret hozzáadása
AdjustWindowRect(&winRect, GetWindowLong(mHWND, GWL_STYLE), false);
//SetWindowPos(mHWND, HWND_TOP, winRect.left, winRect.top, width, height, 0);
SetWindowPos(mHWND, HWND_TOP, winRect.top, winRect.left, winRect.right - winRect.left, winRect.bottom - winRect.top, 0);
UpdateWindow(mHWND);
}
Logger::~Logger()
{
DestroyWindow(mhListBox);
}
void Logger::log(const std::string& text) const
{
SendMessageA(mhListBox, LB_ADDSTRING, 0, (LPARAM)text.c_str());
SendMessageA(mhListBox, WM_VSCROLL, SB_BOTTOM, (LPARAM) nullptr);
}
LRESULT Logger::smLoggerWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message)
{
// case WM_DESTROY:
// PostQuitMessage(0);
// break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
}