// 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 #include #include #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) , m_combo(this,IDCOMBO) { m_button.OnPress (this,static_cast(&Test::OnButton)); m_quit.OnPress (this,static_cast(&Test::OnQuit)); m_check.OnPress (this,static_cast(&Test::OnCheck)); m_text.OnTextChanged (this,static_cast(&Test::OnText)); m_loadbut.OnPress (this,static_cast(&Test::OnLoad)); m_savebut.OnPress (this,static_cast(&Test::OnSave)); m_combo.OnSelection (this,static_cast(&Test::OnComboSel)); m_combo.OnDoubleClick (this,static_cast(&Test::OnComboDbl)); m_combo.OnTextChanged (this,static_cast(&Test::OnComboTxt)); } 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); 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; m_combo.SelectedIndex(2); } 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; W32DLib::ComboBox m_combo; 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(); std::cout << "Called OnButton()" << std::endl; std::cout << "text=" << txt << std::endl; std::cout << "check=" << m_check.GetState() << std::endl; m_static.SetText(txt); SetText(txt+" [Title]"); m_combo.AddString(m_combo.GetText()); m_text.AppendText(m_combo.GetText()+"\n"); return TRUE; } BOOL OnCheck(UINT msg, WPARAM wp, LPARAM lp) { bool checked=m_check.GetState(); std::cout << "Called OnCheck() - state " << checked << 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 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) { int sel=m_combo.SelectedIndex(); 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 << ":GetText=" << m_text.GetText() << std::endl; 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; }