This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
widget.hpp
60 lines (52 loc) · 1.61 KB
/
widget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <Windows.h>
#include "ui_types.hpp"
namespace Win11SysCheck
{
namespace gui
{
using TMessageFunction = std::function <LRESULT(HWND, WPARAM, LPARAM)>;
using TMessagePair = std::pair <uint32_t, TMessageFunction>;
class CWidget
{
public:
CWidget(HWND hParentWnd = nullptr, HINSTANCE hInstance = nullptr, bool bIsWindow = false);
~CWidget();
bool Create(
const std::string& stClassName, const std::string& stWidgetName, rectangle& rcRectangle,
DWORD style, DWORD ex_style = 0, HMENU hMenu = nullptr
);
void AddMessageHandlers(const std::vector <TMessagePair>& vMessages);
void RemoveMessageHandler(uint32_t message);
bool SetText(const std::string& stText) const;
void SetInstance(HINSTANCE hInstance);
void SetVisible(bool bIsVisible);
void SetPosition(int x, int y);
void SetCenterPosition();
void Show();
void Hide();
HWND GetHandle() const;
HINSTANCE GetInstance() const;
bool IsVisible() const;
int GetScreenWidth() const;
int GetScreenHeight() const;
void GetWindowRect(RECT* pRC);
void GetClientRect(RECT* pRC);
void GetMousePosition(POINT* pPT);
auto GetRect() const { return m_rcCurrRect; };
public:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static std::unordered_map <HWND, CWidget*> m_upWidgets;
private:
std::unordered_map <uint32_t, TMessageFunction> m_umCustomMessages;
HFONT m_hFont;
HWND m_hWnd;
HWND m_hParentWnd;
HINSTANCE m_hInstance;
rectangle m_rcCurrRect;
WNDPROC m_pOriginalWndProc;
bool m_bIsWindow;
bool m_bVisible;
};
}
};