-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowWidget.cpp
More file actions
121 lines (98 loc) · 2.31 KB
/
WindowWidget.cpp
File metadata and controls
121 lines (98 loc) · 2.31 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "WindowWidget.h"
#include "mouseEvent.h"
#include "buttonEvent.h"
/**
* @brief 构造函数
* @param parent 父对象,为NULL则当前为单独窗口,不为空,则当前对象是子窗口
* @param className 窗口类的名称,可以系统注册好的,也可以自定义的
*/
WindowWidget::WindowWidget(WindowWidget* parent, LPCTSTR className) : ShowObject(parent), m_location(300,200) {
// TODO: 每次都要自己CreateWindow,想想办法给他整了,麻烦死了
// TODO: 还有每次都要自己弄当前句柄,忘记了啷个搞?必须封装了
// 设置属性
m_className = className;
// 根据是否有父对象,确认m_style和m_hwndParent的值
if (parent != NULL) {
m_style = WS_CHILD;
m_parentHwnd = parent->getHwnd();
parent->addShowList(this);
}
else {
m_style = WS_OVERLAPPEDWINDOW;
m_parentHwnd = NULL;
}
}
WindowWidget::~WindowWidget() {
if (m_hwnd)
DestroyWindow(m_hwnd);
}
/**
* @brief 设定文本或标题
*/
void WindowWidget::setText(LPCTSTR text) {
m_windowName = text;
SetWindowTextW(m_hwnd, text);
}
/**
* @brief 移动本窗口
* @param a_loc 目标位置,point对象
*/
void WindowWidget::move(Point loc) {
m_location = std::move(loc);
MoveWindow(m_hwnd, loc.x(), loc.y(), m_width, m_height, TRUE);
}
/**
* @brief 移动本窗口(重载
* @param a_x x坐标
* @param a_y y坐标
*/
void WindowWidget::move(int x, int y) {
m_location.setX(x);
m_location.setY(y);
MoveWindow(m_hwnd, x, y, m_width, m_height, TRUE);
}
/**
* @brief 重新设定窗口大小
* @param width 宽度
* @param height 高度
*/
void WindowWidget::resize(int width, int height) {
m_width = width;
m_height = height;
MoveWindow(m_hwnd, m_location.x(), m_location.y(), width, height, TRUE);
}
/**
* @brief 设置当前窗口句柄
* @param hwnd 窗口句柄
*/
void WindowWidget::setNowHwnd(HWND hwnd) {
if (hwnd == NULL) {
MessageBox(NULL, TEXT("ShowObject::setNowHwnd HWND == NULL"), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);
exit(0);
}
m_hwnd = hwnd;
}
/**
* @brief 展示自己和展示列表里面的所有元素
*/
void WindowWidget::show() {
ShowWindow(m_hwnd, TRUE);
UpdateWindow(m_hwnd);
for (auto showItem : getShowList())
{
if (!showItem->isShow())
continue;
showItem->show();
auto childVec = showItem->getShowList();
if (childVec.empty())
continue;
for (auto x : childVec)
x->show();
}
setVisiable(true);
}
void WindowWidget::hide()
{
setVisiable(false);
// Todo: 具体实现还没写
}