LunaHook-mirror/LunaHost/GUI/window.h

67 lines
1.6 KiB
C
Raw Normal View History

2024-02-07 20:59:24 +08:00
#ifndef LUNA_BASE_WINDOW_H
#define LUNA_BASE_WINDOW_H
class control;
2024-07-21 19:28:47 +08:00
class basewindow
{
2024-02-07 20:59:24 +08:00
public:
HWND winId;
2024-07-21 19:28:47 +08:00
virtual void setgeo(int, int, int, int);
virtual void on_size(int w, int h);
2024-02-07 20:59:24 +08:00
RECT getgeo();
std::wstring text();
2024-07-21 19:28:47 +08:00
void settext(const std::wstring &);
operator HWND() { return winId; }
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
struct Font
{
std::wstring fontfamily;
float fontsize;
bool bold;
bool italic;
float calc_height() const
{
return MulDiv(fontsize, GetDeviceCaps(GetDC(NULL), LOGPIXELSY), 72);
}
HFONT hfont() const
{
return CreateFontIndirect(&logfont());
}
LOGFONT logfont() const
{
LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
wcscpy_s(lf.lfFaceName, fontfamily.c_str());
if (bold)
lf.lfWeight = FW_BOLD;
lf.lfItalic = italic;
lf.lfHeight = calc_height();
return lf;
}
};
class mainwindow : public basewindow
{
HFONT hfont = 0;
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
void setfont(const Font &);
2024-04-25 15:44:28 +08:00
void visfont();
2024-07-21 19:28:47 +08:00
std::vector<control *> controls;
std::vector<mainwindow *> childrens;
mainwindow *parent;
2024-02-07 20:59:24 +08:00
HWND lastcontexthwnd;
2024-07-21 19:28:47 +08:00
control *layout;
2024-02-07 20:59:24 +08:00
virtual void on_show();
virtual void on_close();
2024-07-21 19:28:47 +08:00
void on_size(int w, int h);
mainwindow(mainwindow *_parent = 0);
2024-02-07 20:59:24 +08:00
LRESULT wndproc(UINT message, WPARAM wParam, LPARAM lParam);
static void run();
void show();
void close();
2024-07-21 19:28:47 +08:00
void setcentral(int, int);
std::pair<int, int> calculateXY(int w, int h);
void setlayout(control *);
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
HICON GetExeIcon(const std::wstring &filePath);
2024-02-07 20:59:24 +08:00
#endif