-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComMonitor.cpp
190 lines (168 loc) · 5.46 KB
/
ComMonitor.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <iostream>
#include <thread>
#include "gui/inc/gui.h"
#include "gui/inc/widget/window.h"
#include "gui/inc/widget/tab.h"
#include "gui/inc/widget/combo.h"
#include "gui/inc/widget/label.h"
#include "gui/inc/widget/button.h"
#include "gui/inc/widget/checkbox.h"
#include "gui/inc/widget/list_view.h"
#include "gui/inc/widget/edit.h"
#include "gui/inc/widget/rich_edit.h"
#include "gui/inc/widget/progress.h"
#include "gui/inc/layout/fit.h"
#include "gui/inc/layout/split.h"
#include "gui/inc/layout/grid.h"
#include "gui/inc/layout/eva.h"
using namespace gui;
#include <vector>
#include <string>
#include "CSerial/SerialWnd.h"
int main()
{
wnd<combo> cmb_com;
wnd<button> btn_com("open");
// ChildWin for MainWindow
wnd<label> lbl_name("name");
wnd<label> lbl_psw("password");
wnd<edit> edt_psw = new_<edit>()
.password_type(true)
.size(200, 100);
wnd<button> btn_ok("ok");
wnd<button> btn_cancel("cancel");
wnd<progress> prog = new_<progress>()
.size(100, 10);
// layout for MainWindow
auto& lay = *new layout::eva(5, 5);
lay.padding = padding(10, 10, 10, 10);
lay/**/ | 80 | 'x' | 'd' | 10 | 'd' |
'd' | lbl_name |cmb_com| '-' | '-' | btn_com |
3 | ' ' | ' ' | ' ' | ' ' | ' ' |
'd' | lbl_psw | prog | '-' | '-' | '-' |
'x' | ' ' | ' ' | ' ' | ' ' | ' ' |
'd' | ' ' | ' ' |btn_ok | ' ' | btn_cancel ;
wnd<window> w = new_<window>()
.text("login")
.size(300, 200)
.resizable(true)
.layout(&lay);
w->add_child(lbl_name,cmb_com,btn_com,
lbl_psw, prog,
btn_ok, btn_cancel);
// Event for ChildWind and MainWindow
btn_ok->event.click += [&]() { prog->step_it(); };
btn_cancel->event.click += [&]() {
prog->pos = 0;
prog->visible = false;
};
auto caret = []() {
POINT p;
GetCaretPos(&p);
std::cout << "caret:" << p.x << std::endl;
};
edt_psw->event.mouse_down += [&](wnd_msg&) {
std::cout << "mosue down" << std::endl;
caret();
};
w->event.move += [](const pos& p) {
std::cout << "window moved to ("
<< p.x_ << "| " << p.y_ << ")"
<< std::endl;
};
// Create Window
w->create();
std::vector<std::string> strPorts;
for (int n=0;n<10/*PORTNAME_MAX*/;n++){
char cstr[10]={"COM"};
sprintf(cstr, "COM%d", n);
if (CSerial::CheckPort((LPCTSTR)(cstr))
==CSerial::EPortAvailable){
strPorts.emplace_back(cstr);
std::cout << cstr<<std::endl;
}
}
for(const std::string& str:strPorts)
cmb_com->add_item(str);//必须在控件被create之后才能操作它!
btn_com->event.click +=[&](){
int index = cmb_com->get_sel();
std::string& str=strPorts[index];
std::cout <<str << std::endl;
};
//message loop
msg_loop();
}
/****************************
int main() {
// wnd<label> lbl_name("name"), lbl_psw("password");
wnd<edit> edt_psw = new_<edit>().password_type(true).size(200, 100);
// wnd<combo> cmb_psw;
// wnd<button> btn_ok("ok"), btn_cancel("cancel");
//
// wnd<progress> prog = new_<progress>().size(100, 10);
//
// btn_ok->event.click += [&]() { prog->step_it(); };
// btn_cancel->event.click += [&]() { prog->pos = 0; prog->visible = false;};
//
// auto& lay = *new layout::eva(5, 5);
// lay.padding = padding(10, 10, 10, 10);
//
// lay | 80 | 'x' | 'd' | 10 | 'd' |
// 'd' | lbl_name | edt_psw | '-' | '-' | '-' |
// 3 | ' ' | ' ' | ' ' | ' ' | ' ' |
// 'd' | lbl_psw | prog | '-' | '-' | '-' |
// 'x' | ' ' | ' ' | ' ' | ' ' | ' ' |
// 'd' | ' ' | ' ' | btn_ok | ' ' | btn_cancel ;
wnd<window> w = new_<window>().text("login").size(300, 60).resizable(true)
// .layout(&lay)
.layout(new layout::fit)
;
// wnd<edit> editor_name = new_<edit>().text("admin");
// wnd<edit> editor_psw = new_<edit>().text("123456").password_type(true);
// wnd<button> btn_login("login");
// wnd<button> btn_cancel = new_<button>().text("cancel");
// btn_login->event.click += [&]() {
// string psw = editor_psw->text;
// cout << (psw.compare("123456") ? "correct" : "wrong password") << endl;
// };
// btn_cancel->event.click += [&]() { quit_msg_loop(0); };
// wnd<list_view> lv;
// wnd<edit> edt;
auto caret = []() {
POINT p;
GetCaretPos(&p);
cout << "caret:" << p.x << endl;
};
edt_psw->event.mouse_down += [&](wnd_msg&) { cout << "mosue down" << endl; caret(); };
// wnd<button> b1("b1");
// wnd<button> b2("b2");
w->event.move += [](const pos& p) { cout << "window moved to (" << p.x << "| " << p.y << ")" << endl; };
w->add_child(
edt_psw
// lv
// lbl_name, edt_psw,
// lbl_psw, prog,
// btn_ok, btn_cancel
// wnd<tab>()->add_child(
// wnd<label>("name:")| editor_name|
// wnd<label>("password:")| editor_psw|
// btn_login| btn_cancel
// )
);
w->create();
// lv->event.db_click += [&]() {
// int row = lv->sel;
// cout << row << endl;
// };
// prog->range(0, 100);
// prog->step = 5;
// lv->add_col("aaa")->add_col("bbb");
// lv->add_row(3);
// lv->item(0, 0) = lv_item("x");
// lv->item(1, 0) = lv_item("y");
// lv->item(2, 0) = lv_item("z");
// lv->item(1, 1) = lv_item("a");
// lv->sel = 1;
msg_loop();
}
***********/