1: // cexer
2: #include "../../cexer/include/GUI/panel.h"
3: #include "../../cexer/include/GUI/window.h"
4: #include "../../cexer/include/GUI/button.h"
5: #include "../../cexer/include/GUI/checkbox.h"
6: #include "../../cexer/include/GUI/radiobox.h"
7: #include "../../cexer/include/GUI/GUI.h"
8:
9: using namespace cexer;
10: using namespace cexer::gui;
11: using namespace cexer::gdi;
12:
13: // c++ std
14: #include <iostream>
15: using namespace std;
16:
17:
18: class TestWindow:public Window
19: {
20:
21: public:
22:
23: TestWindow( ):Window( NULL,_T("test window") )
24: {
25: onCreated( this,&TestWindow::windowCreated );
26: onClosing( this,&TestWindow::windowClosing );
27: onDestroy( this,&TestWindow::windowDestroy );
28: onResized( this,&TestWindow::windowResized );
29: onErasing( this,&TestWindow::windowErasing );
30:
31: onMouseClicked( this,&TestWindow::mouseClicked );
32: onMouseEntered( this,&TestWindow::mouseEntered );
33: onMouseExited( this,&TestWindow::mouseExited );
34: onMousePressed( this,&TestWindow::mousePressed );
35: onMouseReleased( this,&TestWindow::mouseReleased );
36: }
37:
38: public:
39:
40: LRESULT windowCreated( Widget*,CREATESTRUCT& )
41: {
42: wcout<<L"创建成功!"<<endl;
43:
44: Panel* panel = new Panel( this,_T("panel") );
45: panel->create( _T(""),10,10 );
46: panel->onResized( this,&TestWindow::windowResized );
47:
48: Button* button = new Button( panel,_T("button") );
49: button->create( _T("测试按钮"),10,10 );
50: button->onClicked( this,&TestWindow::buttonClicked );
51:
52: Checkbox* checkbox = new Checkbox( panel,_T("checkbox") );
53: checkbox->create( _T("测试多选框"),10,40 );
54: checkbox->onClicked( this,&TestWindow::buttonClicked );
55:
56:
57: Radiobox* radiobox = new Radiobox( panel,_T("radiobox") );
58: radiobox->create( _T("测试单选框"),10,70 );
59: radiobox->onClicked( this,&TestWindow::buttonClicked );
60:
61: return 0;
62: }
63:
64: LRESULT windowDestroy( Widget* )
65: {
66: wcout<<L"销毁成功!"<<endl;
67: ::PostQuitMessage(0);
68:
69: return 0;
70: }
71:
72: LRESULT windowClosing( Widget* )
73: {
74: if ( IDNO == confirmBox(_T("确定关闭窗口?")) )
75: {
76: return 0;
77: }
78:
79: destroy();
80:
81: return 0;
82: }
83:
84: LRESULT windowErasing( Widget*,Canvas& canvas )
85: {
86: canvas.fillRect( clientBounds() );
87: canvas.drawText( 100,100,_T("测试窗口") );
88:
89: return 0;
90: }
91:
92: LRESULT windowResized( Widget* source,UINT,SIZE size )
93: {
94: if ( source->name() == m_name )
95: {
96: long panelWidth = ( size.cx-20 );
97: long panelHeight = ( size.cy-20 );
98:
99: resizeChild( _T("panel"),panelWidth,panelHeight );
100: }
101: else if ( source->name() == _T("panel") )
102: {
103: long childWidth = ( size.cx-20 );
104: long childHeight = 20;
105:
106: resizeChild( _T("button") ,childWidth,childHeight );
107: resizeChild( _T("checkbox"),childWidth,childHeight );
108: resizeChild( _T("radiobox"),childWidth,childHeight );
109: }
110:
111: return 0;
112: }
113:
114: LRESULT buttonClicked( Button* button )
115: {
116: messageBox( button->text() + _T("被点击了!") );
117: return 0;
118: }
119:
120:
121: LRESULT mouseClicked( Widget*,UINT,POINT cursor)
122: {
123: wcout<<L"鼠标点击\t"<<L"位置";
124: wcout<<L"("<<cursor.x<<L","<<cursor.y<<L")"<<endl;
125: return 0;
126: }
127:
128: LRESULT mouseEntered( Widget*,UINT,POINT cursor )
129: {
130: wcout<<L"鼠标进入\t"<<L"位置";
131: wcout<<L"("<<cursor.x<<L","<<cursor.y<<L")"<<endl;
132: return 0;
133: }
134:
135: LRESULT mouseExited( Widget*,UINT,POINT cursor )
136: {
137: wcout<<L"鼠标离开\t"<<L"位置";
138: wcout<<L"("<<cursor.x<<L","<<cursor.y<<L")"<<endl;
139: return 0;
140: }
141:
142: LRESULT mousePressed( Widget*,UINT,POINT cursor )
143: {
144: wcout<<L"鼠标按下\t"<<L"位置";
145: wcout<<L"("<<cursor.x<<L","<<cursor.y<<L")"<<endl;
146: return 0;
147: }
148:
149: LRESULT mouseReleased( Widget*,UINT,POINT cursor )
150: {
151: wcout<<L"鼠标释放\t"<<L"位置";
152: wcout<<L"("<<cursor.x<<L","<<cursor.y<<L")"<<endl;
153: return 0;
154: }
155:
156: };
157:
158:
159:
160: int _tmain( int argc,TCHAR** argv )
161: {
162: CEXER_GUI_THREAD();
163:
164: wcout.imbue( std::locale("") );
165:
166: TestWindow* window = new TestWindow();
167: window->create();
168:
169: return runGUIthread();
170: }