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
|
// 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"
class Test : public W32DLib::Dialog
{
public:
Test() : m_static(this,IDSTATIC1)
, m_text(this,IDTEXT)
, m_check(this,IDCHECK)
, m_button(this,IDBUTTON)
, m_quit(this,IDQUIT)
, m_load(this,IDLOADTXT)
, m_loadbut(this,IDLOADBUT)
, m_save(this,IDSAVETXT)
, m_savebut(this,IDSAVEBUT)
{
AddControl(&m_text);
AddControl(&m_check);
AddControl(&m_button);
AddControl(&m_quit);
AddControl(&m_load);
AddControl(&m_loadbut);
AddControl(&m_save);
AddControl(&m_savebut);
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_loadbut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnLoad));
m_savebut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnSave));
}
virtual ~Test()
{
}
int ResourceID()
{
return TESTDLG;
}
virtual void OnInit()
{
std::cout << "OnInit()" << std::endl;
m_text.SetText("Hello");
m_check.SetState(W32DLib::AutoCheck::eChecked);
m_quit.Enable(true);
}
private:
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;
std::string m_loadpath;
std::string m_savepath;
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)
{
std::string txt=m_text.GetText(512);
std::cout << "Called OnButton()" << std::endl;
std::cout << "text=" << txt << std::endl;
std::cout << "check=" << m_check.GetState() << std::endl;
m_static.SetText(txt.c_str());
SetText((txt+" [Title]").c_str());
return TRUE;
}
BOOL OnCheck(UINT msg, WPARAM wp, LPARAM lp)
{
W32DLib::AutoCheck::EState state=m_check.GetState();
std::cout << "Called OnCheck() - state " << state << std::endl;
m_quit.Enable(state==W32DLib::AutoCheck::eChecked);
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.c_str());
}
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.c_str());
}
return TRUE;
}
};
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
Test t;
INT_PTR i;
i=t.ShowModal(hInstance,NULL);
if (i==IDOK)
{
std::cout << "res=IDOK" << std::endl;
}
else
{
std::cout << "res=" << i << std::endl;
}
return 0;
}
|