|
|
|
|
#include<graphics.h>
|
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
|
|
class EasyTextBox {
|
|
|
|
|
private:
|
|
|
|
|
int left = 0, top = 0, right = 0, bottom = 0;
|
|
|
|
|
wchar_t* text = NULL;
|
|
|
|
|
size_t maxlen = 0;
|
|
|
|
|
public:
|
|
|
|
|
void create(int x1, int y1, int x2, int y2, int max) {
|
|
|
|
|
maxlen = max;
|
|
|
|
|
text = new wchar_t[maxlen];
|
|
|
|
|
text[0] = 0;
|
|
|
|
|
left = x1, top = y1, right = x2, bottom = y2;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
~EasyTextBox() {
|
|
|
|
|
if (text != NULL) delete[] text;
|
|
|
|
|
}
|
|
|
|
|
wchar_t* get_text() {
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
bool check(int x, int y) {
|
|
|
|
|
return left <= x && x <= right && top <= y && y <= bottom;
|
|
|
|
|
}
|
|
|
|
|
void show() {
|
|
|
|
|
// <20><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>ֵ
|
|
|
|
|
int old_line_color = getlinecolor();
|
|
|
|
|
int old_bk_color = getbkcolor();
|
|
|
|
|
int old_fill_color = getfillcolor();
|
|
|
|
|
|
|
|
|
|
setlinecolor(LIGHTGRAY);
|
|
|
|
|
setbkcolor(0xeeeeee);
|
|
|
|
|
setfillcolor(0xeeeeee);
|
|
|
|
|
fillrectangle(left, top, right, bottom);
|
|
|
|
|
outtextxy(left + 10, top + 5, (LPCTSTR)(&text[0]));
|
|
|
|
|
|
|
|
|
|
// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
setlinecolor(old_line_color);
|
|
|
|
|
setbkcolor(old_line_color);
|
|
|
|
|
setfillcolor(old_fill_color);
|
|
|
|
|
}
|
|
|
|
|
void on_message() {
|
|
|
|
|
// <20><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>ֵ
|
|
|
|
|
int old_line_color = getlinecolor();
|
|
|
|
|
int old_bk_color = getbkcolor();
|
|
|
|
|
int old_fill_color = getfillcolor();
|
|
|
|
|
|
|
|
|
|
setlinecolor(BLACK);
|
|
|
|
|
setbkcolor(WHITE);
|
|
|
|
|
setfillcolor(WHITE);
|
|
|
|
|
fillrectangle(left, top, right, bottom);
|
|
|
|
|
|
|
|
|
|
int width = textwidth((LPCTSTR)text);
|
|
|
|
|
int counter = 0;
|
|
|
|
|
bool binput = true;
|
|
|
|
|
|
|
|
|
|
ExMessage msg;
|
|
|
|
|
while (binput) {
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>
|
|
|
|
|
while (binput && peekmessage(&msg, EX_MOUSE | EX_CHAR, false)) {
|
|
|
|
|
if (msg.message == WM_LBUTTONDOWN) {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (msg.x < left || msg.x > right || msg.y < top || msg.y > bottom) {
|
|
|
|
|
binput = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (msg.message == WM_CHAR) {
|
|
|
|
|
size_t len = wcslen(text);
|
|
|
|
|
switch (msg.ch) {
|
|
|
|
|
case '\b': {
|
|
|
|
|
if (len > 0) {
|
|
|
|
|
text[len - 1] = 0;
|
|
|
|
|
width = textwidth((LPCTSTR)text);
|
|
|
|
|
counter = 0;
|
|
|
|
|
clearrectangle(left + 10 + width, top + 1, right - 1, bottom - 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case '\r':
|
|
|
|
|
case '\n':
|
|
|
|
|
binput = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (len < maxlen - 1) {
|
|
|
|
|
text[len++] = msg.ch;
|
|
|
|
|
text[len] = 0;
|
|
|
|
|
|
|
|
|
|
clearrectangle(left + 10 + width + 1, top + 3, left + 10 + width + 1, bottom - 3); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
width = textwidth((LPCTSTR)text);
|
|
|
|
|
counter = 0;
|
|
|
|
|
outtextxy(left + 10, top + 5, (LPCTSTR)text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
peekmessage(NULL, EX_MOUSE | EX_CHAR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ƹ<EFBFBD><C6B9>꣨<EFBFBD><EAA3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD>Ϊ 20ms * 32<33><32>
|
|
|
|
|
counter = (counter + 1) % 32;
|
|
|
|
|
if (counter < 16)
|
|
|
|
|
line(left + 10 + width + 1, top + 3, left + 10 + width + 1, bottom - 3);
|
|
|
|
|
else
|
|
|
|
|
clearrectangle(left + 10 + width + 1, top + 3, left + 10 + width + 1, bottom - 3); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// <20><>ʱ 20ms
|
|
|
|
|
Sleep(20);
|
|
|
|
|
}
|
|
|
|
|
clearrectangle(left + 10 + width + 1, top + 3, left + 10 + width + 1, bottom - 3); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
setlinecolor(old_line_color);
|
|
|
|
|
setbkcolor(old_bk_color);
|
|
|
|
|
setfillcolor(old_fill_color);
|
|
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ʵ<>ְ<EFBFBD>ť<EFBFBD>ؼ<EFBFBD>
|
|
|
|
|
class EasyButton {
|
|
|
|
|
private:
|
|
|
|
|
int left = 0, top = 0, right = 0, bottom = 0;
|
|
|
|
|
wchar_t* text = NULL; // <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void (*userfunc)() = NULL; // <20>ؼ<EFBFBD><D8BC><EFBFBD>Ϣ
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void create(int x1, int y1, int x2, int y2, const wchar_t* title, void(*func)()) {
|
|
|
|
|
text = new wchar_t[wcslen(title) + 1];
|
|
|
|
|
wcscpy_s(text, wcslen(title) + 1, title);
|
|
|
|
|
left = x1, top = y1, right = x2, bottom = y2;
|
|
|
|
|
userfunc = func;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
~EasyButton() {
|
|
|
|
|
if (text != NULL) delete[] text;
|
|
|
|
|
}
|
|
|
|
|
bool check(int x, int y) {
|
|
|
|
|
return left <= x && x <= right && top <= y && y <= bottom;
|
|
|
|
|
}
|
|
|
|
|
void show() {
|
|
|
|
|
int old_line_color = getlinecolor();
|
|
|
|
|
int old_bk_color = getbkcolor();
|
|
|
|
|
int old_fill_color = getfillcolor();
|
|
|
|
|
|
|
|
|
|
setlinecolor(BLACK); // <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
setbkcolor(WHITE); // <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
setfillcolor(WHITE); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
outtextxy(left + (right - left - textwidth((LPCTSTR)text) + 1) / 2, top + (bottom - top - textheight((LPCTSTR)text) + 1) / 2, (LPCTSTR)text);
|
|
|
|
|
|
|
|
|
|
setlinecolor(old_line_color);
|
|
|
|
|
setbkcolor(old_bk_color);
|
|
|
|
|
setfillcolor(old_fill_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void on_message() {
|
|
|
|
|
if (userfunc != NULL) userfunc();
|
|
|
|
|
}
|
|
|
|
|
};
|