这边先弄个项目文件。
/**
* @file button.h
* @brief the EGE control:button
* @author StudyC.cn@gmail.com
* @date 2011-08-09
*/
#ifndef _EGE_BUTTON_H_
#define _EGE_BUTTON_H_
#ifndef _EGE_H_
#error include "button.h" must after include "ege.h" or "graphics.h"
#endif
#include "egecontrolbase.h"
#include <algorithm>
#ifdef DEBUG
#include "ege/label.h"
#else
#define logout(msg)
#endif
/**
* @brief 按钮控件
*/
class button : public egeControlBase
{
public:
//overrides
// 屏幕更新后会被调用,用于更新逻辑
// 以下虚函数都不要直接相互调用
// 以下函数如果返回非0则不向子控件传递键盘鼠标消息
/**
* @brief 响应空格与回车的按下
*
* @param key
* @param flag
*
* @return 0
*/
virtual int onKeyDown(int key, int flag) {
if((key==13)||(key==32)){
_pushed=true;
redraw();
}
return 0;
}
/**
* @brief 响应空格与回车的弹起
*
* @param key
* @param flag
*
* @return 0
*/
virtual int onKeyUp(int key, int flag) {
if(((key==13)||(key==32))&&_pushed){
if(_on_click){
if(!_on_click(callback_param)){
onClick();
}
}else{
onClick();
}
}
_pushed=false;
redraw();
return 0;
}
/**
* @brief 响应鼠标左键点击
*
* @param x
* @param y
* @param flag
*
* @return 0
*/
virtual int onMouse(int x, int y, int flag) {
if((flag&mouse_flag_left)&&(flag&mouse_msg_down)){
capmouse(true);
_pushed=true;
redraw();
}else if((flag&mouse_flag_left)&&(flag&mouse_msg_up)){
if(_pushed){
if(_on_click){
if(!_on_click(callback_param)){
onClick();
}
}else{
onClick();
}
capmouse(false);
_pushed=false;
}
redraw();
}
return 0;
}
/**
* @brief 屏幕更新后会被调用,用于更新逻辑
*
* @return 0
*/
virtual int onUpdate() {
return 0;
}
/**
* @brief 在要获得焦点时调用,返回值一般返回0表示获取键盘输入焦点,返回非0放弃获得输入焦点
*
* @return 0
*/
virtual int onGetFocus() {
return 0;
}
/**
* @brief 失去输入焦点时调用
*/
virtual void onLostFocus() {
_pushed=false;
redraw();
}
// 设置尺寸前调用,自定义修正函数
virtual void onSizing(int *w, int *h) {
//egeControlBase::onSizing(w,h);
}
// 响应尺寸变化函数
virtual void onSize(int w, int h) {
//egeControlBase::onSize(w,h);
updatesidewidth();
redraw();
}
// 重绘函数,尽量请画到pimg上,以便能控制绘画目标
virtual void onDraw(PIMAGE pimg) const {
}
// 尺寸变化时调用,用于重画过滤缓冲区内容
virtual void onResetFilter() {
}
//virtual void onAddChild(egeControlBase* pChild) {}
//virtual void onDelChild(egeControlBase* pChild) {}
//virtual void onIdle() {} // 保留接口,未用
// 这里以上的函数可以自行定义(注意声明要一致,不要漏掉OnDraw里的const)
//init
CTL_PREINIT(button, egeControlBase) {
// do sth. before sub objects' construct function call
} CTL_PREINITEND;
button(CTL_DEFPARAM) : CTL_INITBASE(egeControlBase) {
CTL_INIT; // must be the first line
size(64, 32);
_font_height = 12;
strcpy(_face, "宋体");
_line_color=BLACK;
_bg_color=RGB(100,100,100);
_text_color=BLACK;
_shadow_color=RGB(50,50,50);
updatesidewidth();
_on_click=NULL;
callback_param=NULL;
_pushed=false;
_alpha=0xff;
#ifdef DEBUG
_logger=NULL;
#endif
//redraw();
//blendmode(true);
}
//member functions
/**
* @brief 在回调函数指针为NULL或回调函数返回0时被调用
*/
virtual void onClick(){
}
/**
* @brief 重绘控件
*/
virtual void redraw() const {
PushTarget targer(buf());
setbkcolor_f(RED);
setcolor(RED);
cleardevice();
setbkmode(TRANSPARENT);
setfillstyle(_bg_color,SOLID_FILL);
bar(0, 0, getw()-1, geth()-1);
setfont(_font_height, 0, _face);
setcolor(_text_color);
//settextjustify(LEFT_TEXT,CENTER_TEXT);
//outtextrect(_side_width, _side_width, getw()-_side_width, geth()-_side_width, _caption);
//outtextrect(0, 0, getw(), geth(), _caption);
int x=(getw()-textwidth(_caption))/2;
int y=(geth()-textheight(_caption))/2;
outtextxy(x,y,_caption);
setbkcolor(_line_color);
rectangle(0,0,getw(),geth());
rectangle(_side_width,_side_width,getw()-_side_width,geth()-_side_width);
setfillstyle(_shadow_color,SOLID_FILL);
if(_pushed){
int points[12]={
0,0,
getw()-1,0,
getw()-_side_width, _side_width-1,
_side_width-1,_side_width-1,
_side_width-1, geth()-_side_width-1,
0,geth()-1,
};
fillpoly(6,points);
}else{
int points[12]={
0,geth()-1,
_side_width-1,geth()-_side_width,
getw()-_side_width, geth()-_side_width,
getw()-_side_width, _side_width-1,
getw()-1,0,
getw()-1,geth()-1,
};
fillpoly(6,points);
}
line(getw()-_side_width, _side_width, getw(), 0);
line(_side_width-1, geth()-_side_width, 0, geth());
//line(getw()-_side_width, geth()-_side_width, getw(), geth());
//line(0,0, _side_width, _side_width);
setbkcolor_f(RGB(_alpha, _alpha, _alpha), filter());
cleardevice(filter());
}
//attributes
/**
* @brief 设置alpha值
*
* @param alpha 0x00 - 0xff
*/
void alpha(int alpha){
if(alpha<0){
_alpha=0;
}else if(alpha>0xff){
_alpha=0xff;
}else{
_alpha=alpha;
}
if(_alpha<0xff){
blendmode(true);
}else{
blendmode(false);
}
}
/**
* @brief 返回alpha值
*
* @return alpha
*/
int alpha() const{
return _alpha;
}
/**
* @brief 设置背景色
*
* @param color 背景色
*/
void bgcolor(COLORREF color){
_bg_color=color;
redraw();
}
/**
* @brief 返回背景色
*
* @return 背景色
*/
COLORREF bgcolor() const{
return _bg_color;
}
/**
* @brief 设置按钮点击回调函数
*
* @param fun 回调函数指针,当且仅当返回值为0时会自动调用onClick
* @param param 附加参数,将会原样传递给回调函数
*/
void callback(int (*fun)(void*),void* param){
callback_param=param;
_on_click=fun;
redraw();
}
/**
* @brief 返回回调函数指针
*
* @return 回调函数指针;若未设置,返回NULL
*/
template <typename T>
T callback() const{
return _on_click;
}
/**
* @brief 设置文本
*
* @param text 文本
*/
void caption(const char* text) {
strcpy(_caption, text);
redraw();
}
/**
* @brief 返回文本
*
* @return 文本
*/
const char* caption() const{
return _caption;
//redraw();
}
/**
* @brief 设置字体
*
* @param fontface 字体名
*/
void font(const char* fontface) {
strcpy(_face, fontface);
redraw();
}
/**
* @brief 返回字体
*
* @return 字体名
*/
const char* font() const{
return _face;
//redraw();
}
/**
* @brief 设置字体尺寸,待续
*
* @param height
*/
void fontsize(int height) {
_font_height = height;
redraw();
}
/**
* @brief 返回字体尺寸
*
* @return 字体尺寸
*/
int fontsize() const{
return _font_height;
}
/**
* @brief 设置按钮的线条颜色
*
* @param color 颜色
*/
void linecolor(COLORREF color){
_line_color=color;
redraw();
}
/**
* @brief 返回按钮线条颜色
*
* @return 线条颜色
*/
COLORREF linecolor() const{
return _line_color;
}
#ifdef DEBUG
/**
* @brief 设置调试信息出口
*
* @param logger
*/
void logger(label* logger){
_logger=logger;
}
/**
* @brief 返回调试信息出口
*
* @return
*/
label* logger() const{
return _logger;
}
#endif
/**
* @brief 设置阴影颜色
*
* @param color 阴影颜色
*/
void shadowcolor(COLORREF color){
_shadow_color=color;
redraw();
}
/**
* @brief 返回阴影颜色
*
* @return 阴影颜色
*/
COLORREF shadowcolor() const{
return _shadow_color;
}
/**
* @brief 设置文本颜色
*
* @param color 文本颜色
*/
void textcolor(COLORREF color){
_text_color=color;
redraw();
}
/**
* @brief 返回文本颜色
*
* @return 文本颜色
*/
COLORREF textcolor() const{
return _text_color;
}
protected:
/**
* @brief 修正边的宽度
*/
void updatesidewidth(){
_side_width=std::min(geth(),getw())*0.2;
}
#ifdef DEBUG
/**
* @brief 输出调试信息
*
* @param msg 调试信息文本
*/
void logout(const char* msg){
if(_logger){
_logger->setcaption(msg);
}
}
#endif
bool _pushed;
int (*_on_click)(void*);
char _caption[1024];
char _face[32];
COLORREF _line_color;
COLORREF _bg_color;
COLORREF _text_color;
COLORREF _shadow_color;
int _side_width;
int _font_height;
int _alpha;
void* callback_param;
#ifdef DEBUG
label* _logger;
#endif
};
#endif /* _EGE_BUTTON_H_ */
再完善一下主页。
#ifndef _EGECONTROLBASE_H_
#define _EGECONTROLBASE_H_
#ifndef _EGE_H_
#error include "egectlbase.h" must after include "ege.h" or "graphics.h"
#endif
namespace ege {
class PushTarget {
public:
PushTarget() { m_target = gettarget(); }
PushTarget(PIMAGE target) { m_target = gettarget(); settarget(target); }
~PushTarget() { settarget(m_target); }
private:
PIMAGE m_target;
};
#define CTL_PREINIT(classname, parent) \
struct preinit_obj { \
preinit_obj(classname* This, int inheritlevel) { \
pre_init(inheritlevel); \
} \
}_preinit_obj; \
enum inherit_e { inherit_level_e = parent::inherit_level_e + 1, }; \
static void firstinit(ege::egeControlBase* This) { \
((classname*)This)->m_inheritlevel = 1; \
} \
void pre_init(int inheritlevel) {\
(void)inheritlevel;
#define CTL_PREINITEND }
#define CTL_DEFPARAM int inherit = inherit_level_e, ege::egeControlBase* pParent = NULL
#define CTL_INITBASE(parent) _preinit_obj(this, inherit_level_e), parent(inherit, (ege::egeControlBase*)pParent)
#define CTL_INIT InitObject iobj(this, inherit_level_e);\
ege::PushTarget _pushtarget(buf());
#define EGECTRL_INITEND() }
class egeControlBase
{
public:
enum ROP {
COPY = SRCCOPY,
XOR = SRCINVERT,
AND = SRCAND,
OR = SRCPAINT,
};
enum blendmode_e {
SOLIDCOPY = 0,
ALPHABLEND = 1,
};
enum inherit_e {
inherit_level_e = 0,
};
// 构造函数可以自定义,但要按需要选择使不使用宏,详见前面代码或者文档示例代码
egeControlBase();
egeControlBase(int inherit, egeControlBase* pParent);
~egeControlBase();
// 以下虚函数都不要直接相互调用
virtual LRESULT onMessage(UINT message, WPARAM wParam, LPARAM lParam) { (void)message; (void)wParam; (void)lParam; return 0; }
// 以下函数如果返回非0则不向子控件传递键盘鼠标消息
virtual int onMouse(int x, int y, int flag) { (void)x; (void)y; (void)flag; return 0; }
virtual int onKeyDown(int key, int flag) { (void)key; (void)flag; return 0; }
virtual int onKeyUp(int key, int flag) { (void)key; (void)flag; return 0; }
virtual int onKeyChar(int key, int flag) { (void)key; (void)flag; return 0; }
// 屏幕更新后会被调用,用于更新逻辑
virtual int onUpdate() { return 0; }
// 以下GetFocus在要获得焦点时调用,返回值一般返回0表示获取键盘输入焦点,返回非0放弃获得输入焦点
virtual int onGetFocus() { return 0; }
// 失去输入焦点时调用
virtual void onLostFocus() { }
// 设置尺寸前调用,自定义修正函数
virtual void onSizing(int *w, int *h) { (void)w; (void)h; }
// 响应尺寸变化函数
virtual void onSize(int w, int h) { (void)w; (void)h; }
// 重绘函数,尽量请画到pimg上,以便能控制绘画目标
virtual void onDraw(PIMAGE pimg) const { (void)pimg; }
// 尺寸变化时调用,用于重画过滤缓冲区内容
virtual void onResetFilter() {
setbkcolor(BLACK, m_mainFilter);
cleardevice(m_mainFilter);
}
virtual void onAddChild(egeControlBase* pChild) { (void)pChild; }
virtual void onDelChild(egeControlBase* pChild) { (void)pChild; }
virtual void onIdle() {} // 保留接口,未用
// 这里以上的函数可以自行定义(注意声明要一致,不要漏掉OnDraw里的const)
// 这里以下的public函数可以调用,不可自定义,任何预定义变量都不要直接访问,请使用预定义函数来控制
public:
PIMAGE buf() { return m_mainbuf; }
PIMAGE filter() { return m_mainFilter; }
egeControlBase* parent() { return m_parent; }
PIMAGE buf() const { return m_mainbuf; }
PIMAGE filter() const { return m_mainFilter; }
const egeControlBase* parent() const { return m_parent; }
void blendmode(int mode) { m_AlphablendMode = mode; }
void setrop(int rop) { m_rop = rop; } // 请用枚举类型ROP里所定义的
void directdraw(bool bdraw) { m_bDirectDraw = (bdraw ? 1 : 0); }
bool isdirectdraw() const { return (m_bDirectDraw != 0); }
void autoredraw(bool bautoredraw) { m_bAutoDraw = (bautoredraw ? 1 : 0); }
bool isautoredraw() const { return (m_bAutoDraw != 0); }
void visible(bool bvisible) { m_bVisible = (bvisible ? 1 : 0); }
bool isvisible() const { return (m_bVisible != 0); }
void enable(bool benable) { m_bEnable = (benable ? 1 : 0); }
bool isenable() const { return (m_bEnable != 0); }
void capture(bool bcapture) { m_bCapture = (bcapture ? 1 : 0); }
bool iscapture() const { return (m_bCapture != 0); }
void capmouse(bool bcapmouse) { m_bCapMouse = (bcapmouse ? 1 : 0); }
bool iscapmouse() const { return (m_bCapMouse != 0); }
bool isfocus() const { return (m_bInputFocus != 0); }
void move(int x, int y) { m_x = x; m_y = y; }
void size(int w, int h) {
onSizing(&w, &h);
m_w = w; m_h = h;
resize(m_mainbuf, w, h);
resize(m_mainFilter, w, h);
onSize(w, h);
onResetFilter();
}
void zorderup();
void zorderdown();
void zorderset(int z);
int getx() const { return m_x; }
int gety() const { return m_y; }
int getw() const { return m_w; }
int geth() const { return m_h; }
int width() const { return m_w; }
int height() const { return m_h; }
int addchild(egeControlBase* pChild);
int delchild(egeControlBase* pChild);
void draw(PIMAGE pimg);
void update();
void mouse(int x, int y, int flag);
void keymsgdown(unsigned key, int flag);
void keymsgup(unsigned key, int flag);
void keymsgchar(unsigned key, int flag);
bool operator < (const egeControlBase& pbase) const {
if (m_zOrderLayer != pbase.m_zOrderLayer)
return m_zOrderLayer < pbase.m_zOrderLayer;
if (m_zOrder == pbase.m_zOrder)
return this < &pbase;
else
return m_zOrder < pbase.m_zOrder;
}
protected:
int allocId();
int allocZorder();
class InitObject {
public:
InitObject(egeControlBase* pThis, int inherit_level);
~InitObject();
private:
egeControlBase* m_this;
int m_inherit_level;
};
void (* m_preinit_func )(egeControlBase*);
private:
void init(egeControlBase* parent);
void fixzorder();
void sortzorder();
#if _MSC_VER <= 1200
public:
#endif
void initok();
private:
PIMAGE m_mainbuf; // 主缓冲
PIMAGE m_mainFilter; // 过滤器
private:
int m_bVisible; // 是否可见
int m_bEnable; // 是否可获得输入(键盘和鼠标)
int m_bAutoDraw; // 是否自动绘画到窗口上
int m_bCapture; // 是否可获得键盘输入焦点
int m_bInputFocus; // 是否已经获得输入焦点
int m_bCapMouse; // 是否捕捉鼠标(即使不在所在区域内)
int m_zOrderLayer; // Z次序层(值较大者在前,值较小者会被其它控件遮挡)
int m_zOrder; // Z次序(值较大者在前,值较小者会被其它控件遮挡)
int m_allocId; // 分配id
int m_allocZorder; // 分配Z次序
egeControlBase* m_parent;
static int s_maxchildid; // 下一次子控件分配ID值
#ifdef _GRAPH_LIB_BUILD_
public:
#else
private:
#endif
void* m_childmap; // 子控件
void* m_childzorder; // 子控件排序
protected:
int m_x, m_y; // 左上角坐标
int m_w, m_h; // 宽高
protected:
DWORD m_rop; // 混合方式
int m_AlphablendMode; // 绘画混合过滤方式
int m_bDirectDraw; // 启用直接绘画
#if _MSC_VER <= 1200
public:
#endif
int m_inheritlevel; // 继承层次
};
} /* namespace ege */
#endif /* _EGECONTROLBASE_H_ */
项目文件2
#ifndef _EGE_FPS_H_
#define _EGE_FPS_H_
#ifndef _EGE_H_
#error include "fps.h" must after include "ege.h" or "graphics.h"
#endif
#include "egecontrolbase.h"
namespace ege {
class fps : public egeControlBase
{
public:
CTL_PREINIT(fps, egeControlBase) {
// do sth. before sub objects' construct function call
} CTL_PREINITEND;
fps(CTL_DEFPARAM) : CTL_INITBASE(egeControlBase) {
CTL_INIT; // must be the first line
directdraw(true);
enable(false);
}
void onDraw(PIMAGE pimg) const {
char str[16] = "fps ", *pstr = str;
double fps = getfps() + 0.005;
int a = (int)fps, b = (int)((fps - a) * 100);
while (*pstr) ++pstr;
pstr[-1] = (char)(b % 10 + '0');
pstr[-2] = (char)(b / 10 + '0');
pstr[-3] = '.';
pstr -= 4;
for ( ; a > 0; --pstr) {
pstr[0] = a % 10 + '0';
a /= 10;
}
setcolor(WHITE, pimg);
setfillcolor(BLACK, pimg);
setbkmode(OPAQUE, pimg);
setfont(12, 0, "", pimg);
outtextxy(0, 0, str, pimg);
}
};
} // namespace ege
#endif /*_EGE_FPS_H_*/
项目文件3
#ifndef _EGE_LABEL_H_
#define _EGE_LABEL_H_
#ifndef _EGE_H_
#error include "label.h" must after include "ege.h" or "graphics.h"
#endif
#include "egecontrolbase.h"
class label : public egeControlBase
{
public:
CTL_PREINIT(label, egeControlBase) {
// do sth. before sub objects' construct function call
} CTL_PREINITEND;
label(CTL_DEFPARAM) : CTL_INITBASE(egeControlBase) {
CTL_INIT; // must be the first line
size(64, 16);
m_color = WHITE;
m_bkcolor = BLACK;
m_fontheight = 12;
m_alpha = 0xff;
m_transparent = false;
strcpy(m_face, "");
redraw();
}
void caption(const char* text) {
strcpy(m_caption, text);
redraw();
}
const char* caption() const {
return m_caption;
}
void fontsize(int height) {
m_fontheight = height;
redraw();
}
int fontsize() const {
return m_fontheight;
}
void font(const char* fontface) {
strcpy(m_face, fontface);
redraw();
}
const char* font() const {
return m_face;
}
void color(color_t color) {
m_color = color;
redraw();
}
color_t color() const {
return m_color;
}
void bkcolor(color_t color) {
m_bkcolor = color;
redraw();
}
color_t bkcolor() const {
return m_bkcolor;
}
void transparent(bool t) {
m_transparent = t;
redraw();
}
bool transparent() const {
return m_transparent;
}
void alpha(int alpha) {
if (alpha < 0) alpha = 0;
if (alpha > 0xff) alpha = 0xff;
m_alpha = alpha;
redraw();
}
int alpha() const {
return m_alpha;
}
void redraw() {
PushTarget targer(buf());
if (m_alpha < 0xff || m_transparent) blendmode(true);
else blendmode(false);
setbkcolor_f(m_bkcolor);
setcolor(m_color);
cleardevice();
setbkmode(TRANSPARENT);
setfont(m_fontheight, 0, m_face);
outtextrect(0, 0, getw(), geth(), m_caption);
if (m_transparent) {
setbkcolor_f(BLACK, filter());
cleardevice(filter());
if (m_alpha < 0xff) {
setcolor(RGB(m_alpha, m_alpha, m_alpha), filter());
} else {
setcolor(0xFFFFFF, filter());
}
setbkmode(TRANSPARENT, filter());
setfont(m_fontheight, 0, m_face, filter());
outtextrect(0, 0, getw(), geth(), m_caption, filter());
} else {
if (m_alpha < 0xff) {
setbkcolor_f(RGB(m_alpha, m_alpha, m_alpha), filter());
cleardevice(filter());
}
}
}
protected:
char m_caption[1024];
char m_face[32];
color_t m_color;
color_t m_bkcolor;
int m_alpha;
bool m_transparent;
int m_fontheight;
};
#endif /* _EGE_LABEL_H_ */
项目文件4
#ifndef _EGE_SYS_EDIT_H_
#define _EGE_SYS_EDIT_H_
#ifndef _EGE_H_
#error include "sys_edit.h" must after include "ege.h" or "graphics.h"
#endif
#include "egecontrolbase.h"
namespace ege {
class sys_edit : public egeControlBase
{
public:
CTL_PREINIT(sys_edit, egeControlBase) {
// do sth. before sub objects' construct function call
} CTL_PREINITEND;
sys_edit(CTL_DEFPARAM) : CTL_INITBASE(egeControlBase) {
CTL_INIT; // must be the first linef
directdraw(true);
m_hwnd = NULL;
}
~sys_edit() {
destroy();
}
int create(bool multiline = false, int scrollbar = 2) {
if (m_hwnd) {
destroy();
}
msg_createwindow msg = {NULL};
msg.hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
msg.classname = L"EDIT";
msg.id = egeControlBase::allocId();
msg.style = WS_CHILD | WS_BORDER |
ES_LEFT | ES_WANTRETURN;
if (multiline) {
msg.style |= ES_MULTILINE | WS_VSCROLL;
} else {
msg.style |= ES_AUTOHSCROLL;
}
msg.exstyle = WS_EX_CLIENTEDGE;// | WS_EX_STATICEDGE;
msg.param = this;
::PostMessageW(getHWnd(), WM_USER + 1, 1, (LPARAM)&msg);
::WaitForSingleObject(msg.hEvent, INFINITE);
m_hwnd = msg.hwnd;
m_hFont = NULL;
m_hBrush = NULL;
m_color = 0x0;
m_bgcolor = 0xFFFFFF;
::SetWindowLongPtrW(m_hwnd, GWLP_USERDATA, (LONG_PTR)this);
m_callback = ::GetWindowLongPtrW(m_hwnd, GWLP_WNDPROC);
::SetWindowLongPtrW(m_hwnd, GWLP_WNDPROC, (LONG_PTR)getProcfunc());
{
char fontname[] = {'\xcb', '\xce', '\xcc', '\xe5', 0, 0};
setfont(12, 6, fontname);
}
visible(false);
::CloseHandle(msg.hEvent);
return 0;
}
int destroy() {
if (m_hwnd) {
msg_createwindow msg = {NULL};
msg.hwnd = m_hwnd;
msg.hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
::SendMessage(m_hwnd, WM_SETFONT, 0, 0);
::DeleteObject(m_hFont);
::PostMessageW(getHWnd(), WM_USER + 1, 0, (LPARAM)&msg);
::WaitForSingleObject(msg.hEvent, INFINITE);
::CloseHandle(msg.hEvent);
if (m_hBrush) ::DeleteObject(m_hBrush);
m_hwnd = NULL;
return 1;
}
return 0;
}
LRESULT onMessage(UINT message, WPARAM wParam, LPARAM lParam);
void visible(bool bvisible) {
egeControlBase::visible(bvisible);
::ShowWindow(m_hwnd, (int)bvisible);
}
void setfont(int h, int w, LPCSTR fontface) {
{
LOGFONTA lf = {0};
lf.lfHeight = h;
lf.lfWidth = w;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_DONTCARE;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH;
lstrcpyA(lf.lfFaceName, fontface);
HFONT hFont = CreateFontIndirectA(&lf);
if (hFont) {
::SendMessageA(m_hwnd, WM_SETFONT, (WPARAM)hFont, 0);
::DeleteObject(m_hFont);
m_hFont = hFont;
}
}
}
void setfont(int h, int w, LPCWSTR fontface) {
{
LOGFONTW lf = {0};
lf.lfHeight = h;
lf.lfWidth = w;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_DONTCARE;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH;
lstrcpyW(lf.lfFaceName, fontface);
HFONT hFont = CreateFontIndirectW(&lf);
if (hFont) {
::SendMessageW(m_hwnd, WM_SETFONT, (WPARAM)hFont, 0);
::DeleteObject(m_hFont);
m_hFont = hFont;
}
}
}
void move(int x, int y) {
egeControlBase::move(x, y);
::MoveWindow(m_hwnd, m_x, m_y, m_w, m_h, TRUE);
}
void size(int w, int h) {
egeControlBase::size(w, h);
::MoveWindow(m_hwnd, m_x, m_y, m_w, m_h, TRUE);
}
void settext(LPCSTR text) {
::SendMessageA(m_hwnd, WM_SETTEXT, 0, (LPARAM)text);
}
void settext(LPCWSTR text) {
::SendMessageW(m_hwnd, WM_SETTEXT, 0, (LPARAM)text);
}
void gettext(int maxlen, LPSTR text) {
::SendMessageA(m_hwnd, WM_GETTEXT, (WPARAM)maxlen, (LPARAM)text);
}
void gettext(int maxlen, LPWSTR text) {
::SendMessageW(m_hwnd, WM_GETTEXT, (WPARAM)maxlen, (LPARAM)text);
}
void setmaxlen(int maxlen) {
::SendMessageW(m_hwnd, EM_LIMITTEXT, (WPARAM)maxlen, 0);
}
void setcolor(color_t color) {
m_color = color;
::InvalidateRect(m_hwnd, NULL, TRUE);
}
void setbgcolor(color_t bgcolor) {
m_bgcolor = bgcolor;
//::RedrawWindow(m_hwnd, NULL, NULL, RDW_INVALIDATE);
::InvalidateRect(m_hwnd, NULL, TRUE);
}
void setreadonly(bool readonly) {
::SendMessageW(m_hwnd, EM_SETREADONLY, (WPARAM)readonly, 0);
::InvalidateRect(m_hwnd, NULL, TRUE);
}
void setfocus() {
::PostMessageW(getHWnd(), WM_USER + 2, 0, (LPARAM)m_hwnd);
}
protected:
HWND m_hwnd;
HFONT m_hFont;
HBRUSH m_hBrush;
color_t m_color;
color_t m_bgcolor;
LONG_PTR m_callback;
};
} // namespace ege
#endif /*_EGE_SYS_EDIT_H_*/