Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7457 | 0CodErr | 1 | /* Event Constants */ |
2 | #define REDRAW_EVENT 1 |
||
3 | #define KEY_EVENT 2 |
||
4 | #define BUTTON_EVENT 3 |
||
5 | |||
6 | /* Window Style Constants */ |
||
7 | #define WS_SKINNED_FIXED 0x4000000 |
||
8 | #define WS_COORD_CLIENT 0x20000000 |
||
9 | #define WS_CAPTION 0x10000000 |
||
10 | |||
11 | /* Caption Style Constants */ |
||
12 | #define CS_MOVABLE 0 |
||
13 | |||
14 | /* Charset specifiers for DrawText */ |
||
15 | #define DT_CP866_8X16 0x10000000 |
||
16 | |||
17 | /* Fill styles for DrawText */ |
||
18 | #define DT_FILL_OPAQUE 0x40000000 |
||
19 | |||
20 | /* Draw zero terminated string for DrawText */ |
||
21 | #define DT_ZSTRING 0x80000000 |
||
22 | |||
23 | // Button identifiers |
||
24 | #define BUTTON_CLOSE 1 |
||
25 | #define SET_LEFT_BUTTON 1111 |
||
26 | #define SET_TOP_BUTTON 2222 |
||
27 | #define SET_CAPTION_BUTTON 3333 |
||
28 | |||
29 | // Flags = [mouse|screen|parent][number|string] |
||
30 | #define IBF_STRING 0 // в буфер будет записана строка |
||
31 | #define IBF_NUMBER 1 // в буфер будет записано число |
||
32 | #define IBF_MOUSE_REL 0 // относительно положения указателя мыши |
||
33 | #define IBF_SCREEN_REL 8 // относительно экрана |
||
34 | #define IBF_PARENT_REL 16 // относительно родительского окна |
||
35 | |||
36 | // Errors |
||
37 | #define IBE_NO_ERROR 0 // успешно, нет ошибки |
||
38 | #define IBE_NUMBER_OVERFLOW 1 // переполнение при вводе числа |
||
39 | #define IBE_RESULT_TOO_LONG 2 // результат не умещается в буфер |
||
40 | |||
41 | #pragma pack(1) |
||
42 | |||
43 | struct TButtonInput{ |
||
44 | union{ |
||
45 | struct{ |
||
46 | unsigned char MouseButton; |
||
47 | unsigned short ID; |
||
48 | unsigned char HiID; |
||
49 | }; |
||
50 | unsigned long Value; |
||
51 | }; |
||
52 | }; |
||
53 | |||
54 | struct TKeyboardInput{ |
||
55 | union{ |
||
56 | struct{ |
||
57 | unsigned char Flag; |
||
58 | char Code; |
||
59 | union{ |
||
60 | char Scan; |
||
61 | unsigned short Control; |
||
62 | }; |
||
63 | }; |
||
64 | unsigned long Value; |
||
65 | }; |
||
66 | }; |
||
67 | |||
68 | struct TSize{ |
||
69 | union{ |
||
70 | struct{ |
||
71 | unsigned short Height; |
||
72 | unsigned short Width; |
||
73 | }; |
||
74 | unsigned long Value; |
||
75 | }; |
||
76 | }; |
||
77 | |||
78 | struct TBox{ |
||
79 | long Left; |
||
80 | long Top; |
||
81 | unsigned long SizeX; |
||
82 | unsigned long SizeY; |
||
83 | }; |
||
84 | |||
85 | extern struct TButtonInput __stdcall GetButton(void); |
||
86 | extern struct TKeyboardInput __stdcall GetKey(void); |
||
87 | extern struct TSize __stdcall GetScreenSize(void); |
||
88 | extern unsigned long __stdcall WaitEvent(void); |
||
89 | extern void __stdcall BeginDraw(void); |
||
90 | extern void __stdcall EndDraw(void); |
||
91 | extern void __stdcall ThreadTerminate(void); |
||
92 | |||
93 | extern void __stdcall DrawWindow(long Left, |
||
94 | long Top, |
||
95 | unsigned long Width, |
||
96 | unsigned long Height, |
||
97 | char* Caption, |
||
98 | unsigned long BackColor, |
||
99 | unsigned long Style, |
||
100 | unsigned long CapStyle); |
||
101 | |||
102 | extern void __stdcall DrawText(long X, |
||
103 | long Y, |
||
104 | char* Text, |
||
105 | unsigned long ForeColor, |
||
106 | unsigned long BackColor, |
||
107 | unsigned long Flags, |
||
108 | unsigned long Count); |
||
109 | |||
110 | extern void __stdcall DrawButton(long Left, |
||
111 | long Top, |
||
112 | unsigned long Width, |
||
113 | unsigned long Height, |
||
114 | unsigned long BackColor, |
||
115 | unsigned long Style, |
||
116 | unsigned long ID); |
||
117 | |||
118 | extern void __stdcall SetWindowPos(long Left, long Top, unsigned long Width, unsigned long Height); |
||
119 | extern void* __stdcall LoadLibrary(char* Path); |
||
120 | extern void* __stdcall GetProcAddress(void* hLib, char* ProcName); |
||
121 | extern void __stdcall SetWindowCaption(char* Caption); |
||
122 | extern long __stdcall RunFile(char* Path, char* CmdLine); |
||
123 | |||
124 | struct TSize Screen; |
||
125 | struct TBox Window; |
||
126 | |||
127 | unsigned long err; |
||
128 | |||
129 | char Buf[100]; |
||
130 | long NewPos; |
||
131 | |||
132 | void* InputBoxLib; |
||
133 | |||
134 | unsigned long __stdcall (* InputBox)(void* Buffer, char* Caption, char* Prompt, char* Default, |
||
135 | unsigned long Flags, unsigned long BufferSize, void* RedrawProc); |
||
136 | |||
137 | void OnRedraw(void){ |
||
138 | BeginDraw(); |
||
139 | DrawWindow(Window.Left, Window.Top, Window.SizeX, Window.SizeY, "Test InputBox", 0xFFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CS_MOVABLE); |
||
140 | |||
141 | DrawButton(8, 60, 81, 33, 0x0FF0000, 0, SET_LEFT_BUTTON); |
||
142 | DrawButton(104, 60, 81, 33, 0x000FF00, 0, SET_TOP_BUTTON); |
||
143 | DrawButton(200, 60, 93, 33, 0x0FFFF00, 0, SET_CAPTION_BUTTON); |
||
144 | |||
145 | DrawText(28, 72, "Set Left", 0, 0x0FFFFFF, DT_ZSTRING, 0); |
||
146 | DrawText(122, 72, "Set Top", 0, 0x0FFFFFF, DT_ZSTRING, 0); |
||
147 | DrawText(214, 72, "Set Caption", 0, 0x0FFFFFF, DT_ZSTRING, 0); |
||
148 | |||
149 | EndDraw(); |
||
150 | } |
||
151 | /* -------------------------------------------------------- */ |
||
152 | void Main(){ |
||
153 | InputBoxLib = LoadLibrary("/sys/lib/InputBox.obj"); |
||
154 | InputBox = GetProcAddress(InputBoxLib, "InputBox"); |
||
155 | |||
156 | Window.Left = 100; |
||
157 | Window.Top = 70; |
||
158 | Window.SizeX = 315; |
||
159 | Window.SizeY = 200; |
||
160 | |||
161 | while(1){ |
||
162 | switch (WaitEvent()){ |
||
163 | case BUTTON_EVENT: |
||
164 | switch (GetButton().ID){ |
||
165 | case BUTTON_CLOSE: |
||
166 | ThreadTerminate(); |
||
167 | break; |
||
168 | case SET_LEFT_BUTTON: |
||
169 | err = InputBox(&NewPos, "Input", "Enter new left", "100", IBF_NUMBER + IBF_PARENT_REL, sizeof(NewPos), &OnRedraw); |
||
170 | if (err) RunFile("/sys/@notify", "Error"); |
||
171 | SetWindowPos(NewPos, -1, -1, -1); |
||
172 | break; |
||
173 | case SET_TOP_BUTTON: |
||
174 | err = InputBox(&NewPos, "Input", "Enter new top", "70", IBF_NUMBER + IBF_SCREEN_REL, sizeof(NewPos), &OnRedraw); |
||
175 | if (err) RunFile("/sys/@notify", "Error"); |
||
176 | SetWindowPos(-1, NewPos, -1, -1); |
||
177 | break; |
||
178 | case SET_CAPTION_BUTTON: |
||
179 | InputBox(&Buf, "Input", "Enter new caption", "Test InputBox", IBF_STRING + IBF_MOUSE_REL, sizeof(Buf), &OnRedraw); |
||
180 | SetWindowCaption(Buf); |
||
181 | break; |
||
182 | } |
||
183 | break; |
||
184 | case KEY_EVENT: |
||
185 | GetKey(); |
||
186 | break; |
||
187 | case REDRAW_EVENT: |
||
188 | OnRedraw(); |
||
189 | break; |
||
190 | } |
||
191 | } |
||
192 | } |