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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
// w32dlib - Win32 Control Helpers
//
// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// -------------------------------------------------------------------------
//
#include <w32dlib/w32dlib.h>
#include <iostream>
#include <string>
#include "dialog.h"
#define DATAX_TEST
class Test : public W32DLib::Dialog
{
public:
Test() : m_check_data(true)
, m_combo_data(2)
, m_text_data("Hello")
, m_radio1_data(true)
, m_radio2_data(false)
, m_radio3_data(false)
, m_static(this,IDSTATIC1,0)
, m_text(this,IDTEXT,&m_text_data)
, m_check(this,IDCHECK,&m_check_data)
, m_button(this,IDBUTTON,0)
, m_quit(this,IDQUIT,0)
, m_load(this,IDLOADTXT,0)
, m_loadbut(this,IDLOADBUT,0)
, m_save(this,IDSAVETXT,0)
, m_savebut(this,IDSAVEBUT,0)
, m_dir(this,IDDIRTXT,0)
, m_dirbut(this,IDDIRBUT,0)
, m_combo(this,IDCOMBO,&m_combo_data)
, m_radio1(this,IDRADIO1,IDRADIO1,IDRADIO3,&m_radio1_data)
, m_radio2(this,IDRADIO2,IDRADIO1,IDRADIO3,&m_radio2_data)
, m_radio3(this,IDRADIO3,IDRADIO1,IDRADIO3,&m_radio3_data)
{
m_button.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnButton));
m_quit.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnQuit));
m_check.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnCheck));
m_text.OnTextChanged
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnText));
m_loadbut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnLoad));
m_savebut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnSave));
m_dirbut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnDir));
m_combo.OnSelection
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnComboSel));
m_combo.OnDoubleClick
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnComboDbl));
m_combo.OnTextChanged
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnComboTxt));
m_radio1.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnRadio));
m_radio2.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnRadio));
m_radio3.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnRadio));
SetMenuProc
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnMenu));
}
virtual ~Test()
{
}
int ResourceID()
{
return TESTDLG;
}
virtual void OnInit()
{
std::cout << "OnInit()" << std::endl;
std::cout << "Can be used from a thread:"
<< (HasMutex() ? "Yes":"No") << std::endl;
m_quit.Enable(true);
m_combo.Reset();
std::cout << "addstring=" << m_combo.AddString(std::string("Entry 1")) << std::endl;
std::cout << "addstring=" << m_combo.AddString("Entry 2") << std::endl;
std::cout << "addstring=" << m_combo.AddString("Entry 3") << std::endl;
std::cout << "count=" << m_combo.Count() << std::endl;
std::cout << "HWND=" << m_combo.GetHWND() << std::endl;
#ifdef DATAX_TEST
SetData();
#else
m_text.SetText("Hello");
m_check.SetState(W32DLib::AutoCheck::eChecked);
m_combo.SelectedIndex(2);
m_radio1.SetState();
#endif
}
private:
W32DLib::DataX m_check_data;
W32DLib::DataX m_combo_data;
W32DLib::DataX m_text_data;
W32DLib::DataX m_radio1_data;
W32DLib::DataX m_radio2_data;
W32DLib::DataX m_radio3_data;
W32DLib::StaticText m_static;
W32DLib::Text m_text;
W32DLib::AutoCheck m_check;
W32DLib::Button m_button;
W32DLib::Button m_quit;
W32DLib::Text m_load;
W32DLib::Button m_loadbut;
W32DLib::Text m_save;
W32DLib::Button m_savebut;
W32DLib::Text m_dir;
W32DLib::Button m_dirbut;
W32DLib::ComboBox m_combo;
W32DLib::RadioButton m_radio1;
W32DLib::RadioButton m_radio2;
W32DLib::RadioButton m_radio3;
std::string m_loadpath;
std::string m_savepath;
std::string m_dirpath;
BOOL OnQuit(UINT msg, WPARAM wp, LPARAM lp)
{
std::cout << "Called OnQuit()" << std::endl;
Dialog::Close(IDOK);
return TRUE;
}
BOOL OnButton(UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef DATAX_TEST
GetData();
bool check=m_check_data.Bool();
std::string txt=m_text_data.Str();
#else
bool check=m_check.GetState();
std::string txt=m_text.GetText();
#endif
std::cout << "Called OnButton()" << std::endl;
std::cout << "text=" << txt << std::endl;
std::cout << "check=" << check << std::endl;
m_static.SetText(txt);
SetText(txt+" [Title]");
m_combo.AddString(m_combo.GetText());
m_text.AppendText(m_combo.GetText()+"\r\n");
#ifdef DATAX_TEST
GetData();
m_radio1_data.Set(false);
m_radio2_data.Set(true);
m_radio3_data.Set(false);
SetData();
#else
m_radio2.SetState();
#endif
return TRUE;
}
BOOL OnCheck(UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef DATAX_TEST
GetData();
bool checked=m_check_data.Bool();
#else
bool checked=m_check.GetState();
#endif
std::cout << "Called OnCheck() - state " << checked << std::endl;
std::cout << "move="<< m_quit.MoveBase(this,10+(checked ? 50:0),50,150,18) << std::endl;
m_quit.Enable(checked);
m_load.ReadOnly(checked);
m_save.Enable(!checked);
return TRUE;
}
BOOL OnLoad(UINT msg, WPARAM wp, LPARAM lp)
{
if (W32DLib::Common::OpenFile(this->GetHWND(),
"Select file to open",
m_loadpath,
"CPP Files\0*.cpp\0Any File\0*.*\0"))
{
m_load.SetText(m_loadpath);
}
return TRUE;
}
BOOL OnSave(UINT msg, WPARAM wp, LPARAM lp)
{
if (W32DLib::Common::SaveFile(this->GetHWND(),
"Select file to save",
m_savepath,
NULL))
{
m_save.SetText(m_savepath);
}
return TRUE;
}
BOOL OnDir(UINT msg, WPARAM wp, LPARAM lp)
{
if (W32DLib::Common::SelectDir(this->GetHWND(),
"Select a directory",
m_dirpath))
{
m_dir.SetText(m_dirpath);
}
return TRUE;
}
BOOL OnComboSel(UINT msg, WPARAM wp, LPARAM lp)
{
int sel=m_combo.SelectedIndex();
std::string str=m_combo.GetString(sel);
std::cout << "Called OnComboSel()" << std::endl;
std::cout << "Sel:selection=" << sel << " (" << str << ")" << std::endl;
std::cout << "Sel:Window::GetText=" << m_combo.GetText() << std::endl;
return TRUE;
}
BOOL OnComboDbl(UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef DATAX_TEST
GetData();
int sel=m_combo_data.Int();
#else
int sel=m_combo.SelectedIndex();
#endif
std::string str=m_combo.GetString(sel);
std::cout << "Called OnComboDbl()" << std::endl;
std::cout << "Dbl:selection=" << sel << " (" << str << ")" << std::endl;
std::cout << "Dbl:Window::GetText=" << m_combo.GetText() << std::endl;
return TRUE;
}
BOOL OnComboTxt(UINT msg, WPARAM wp, LPARAM lp)
{
std::cout << "Called OnComboSel()" << std::endl;
std::cout << "Txt:Window::GetText=" << m_combo.GetText() << std::endl;
return TRUE;
}
BOOL OnText(UINT msg, WPARAM wp, LPARAM lp)
{
std::cout << "Called OnText()" << std::endl;
std::cout << "OnText::GetText=" << m_text.GetText() << std::endl;
return TRUE;
}
BOOL OnMenu(UINT msg, WPARAM wp, LPARAM lp)
{
int cmd=LOWORD(wp);
std::cout << "Menu command " << cmd << std::endl;
switch(cmd)
{
case IDMENUDIALOG:
{
Test t;
t.ShowModal(W32DLib::Common::GetInstance(),m_wnd);
break;
}
case IDMENUQUIT:
Dialog::Close(IDCANCEL);
break;
default:
break;
}
return TRUE;
}
BOOL OnRadio(UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef DATAX_TEST
GetData();
bool radio1=m_radio1_data.Bool();
bool radio2=m_radio2_data.Bool();
bool radio3=m_radio3_data.Bool();
#else
bool radio1=m_radio1.GetState();
bool radio2=m_radio2.GetState();
bool radio3=m_radio3.GetState();
#endif
std::cout << "OnRadio" << std::endl;
std::cout << "radio1=" << radio1 << std::endl;
std::cout << "radio2=" << radio2 << std::endl;
std::cout << "radio3=" << radio3 << std::endl;
return TRUE;
}
};
static void ReadInt(const char *mode, W32DLib::Registry& r, const char *name)
{
unsigned i=0;
bool res=r.Read(name,i);
std::cout << "ReadInt(mode=" << mode
<< ") res=" << res << " val=" << i << std::endl;
}
static void ReadStr(const char *mode, W32DLib::Registry& r, const char *name)
{
std::string i;
bool res=r.Read(name,i);
std::cout << "ReadStr(mode=" << mode
<< ") res=" << res << " val=" << i << std::endl;
}
static void WriteInt(const char *mode, W32DLib::Registry& r, const char *name)
{
unsigned i=666;
bool res=r.Write(name,i);
std::cout << "WriteInt(mode=" << mode << ") res=" << res << std::endl;
}
static void WriteStr(const char *mode, W32DLib::Registry& r, const char *name)
{
std::string i("Hello World");
bool res=r.Write(name,i);
std::cout << "WriteInt(mode=" << mode << ") res=" << res << std::endl;
}
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
Test t;
INT_PTR i;
W32DLib::Common::Initialise();
#ifdef DATAX_TEST
std::cout << "DATAX_TEST enabled" << std::endl;
#endif
W32DLib::Registry rw(HKEY_CURRENT_USER,"Software\\Noddybox\\w32dlibtest",false);
W32DLib::Registry rd(HKEY_CURRENT_USER,"Software\\Noddybox\\w32dlibtest");
ReadInt("rw",rw,"int");
ReadStr("rw",rw,"str");
ReadInt("ro",rd,"int");
ReadStr("ro",rd,"str");
ReadStr("rw",rw,"int");
ReadInt("rw",rw,"str");
WriteInt("rw",rw,"int");
WriteStr("rw",rw,"str");
WriteInt("ro",rd,"int");
WriteStr("ro",rd,"str");
if (hInstance==W32DLib::Common::GetInstance())
{
std::cout << "Common::GetInstance() OK" << std::endl;
}
else
{
std::cout << "Common::GetInstance() FAILED" << std::endl;
}
i=t.ShowModal(hInstance,NULL);
if (i==IDOK)
{
std::cout << "res=IDOK" << std::endl;
}
else if (i==IDCANCEL)
{
std::cout << "res=IDCANCEL" << std::endl;
}
else
{
std::cout << "res=" << i << std::endl;
}
return 0;
}
|