From a6c8b4498363db99d0de8f15e7bc8a9cfc1a7f81 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 11 Apr 2005 20:25:39 +0000 Subject: Added Common::DirSelect(). Also added '--archive' switch to w32dlib-config. --- src/common.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/install.sh | 4 +++- src/test/dialog.rc | 13 ++++++++----- src/test/w32dtst.cpp | 20 ++++++++++++++++++++ src/w32dlib/common.h | 15 +++++++++++++++ 5 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 383a773..9f5296c 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -19,6 +19,7 @@ // ------------------------------------------------------------------------- // #include +#include #include "w32dlib/common.h" namespace W32DLib @@ -157,6 +158,51 @@ bool Common::SaveFile(HWND parent, } +// ------------------------------------------------------------ +// +bool Common::SelectDir(HWND parent, const char *title, std::string& path) +{ + char name[1024]; + LPITEMIDLIST sel=NULL; + BROWSEINFO bi={0}; + + strcpy(name,path.c_str()); + + bi.hwndOwner=parent; + bi.pidlRoot=NULL; + bi.pszDisplayName=name; + bi.lpszTitle=title; + bi.ulFlags=0; + bi.lpfn=BrowseCallback; + bi.lParam=(LPARAM)name; + + sel=SHBrowseForFolder(&bi); + + if (SHGetPathFromIDList(sel,name)) + { + path=name; + return true; + } + else + { + return false; + } +} + + +// ------------------------------------------------------------ +// +int CALLBACK Common::BrowseCallback(HWND w, UINT u, LPARAM p1, LPARAM p2) +{ + if (u==BFFM_INITIALIZED) + { + PostMessage(w,BFFM_SETSELECTION,TRUE,p2); + } + + return 0; +} + + // ------------------------------------------------------------ // std::string Common::GetOSError() diff --git a/src/install.sh b/src/install.sh index e3274ae..54afb53 100644 --- a/src/install.sh +++ b/src/install.sh @@ -34,8 +34,10 @@ if [ "\$1" == "--libs" ] ; then echo -L$libdir -mwindows -lw32dlib elif [ "\$1" == "--cflags" ] ; then echo -I$incbase +elif [ "\$1" == "--archive" ] ; then + echo $libdir/libw32dlib.a else - echo usage: \$0 [--libs\|--cflags] + echo usage: \$0 [--libs\|--cflags\|-archive] fi EOF diff --git a/src/test/dialog.rc b/src/test/dialog.rc index 8207c9f..233389c 100644 --- a/src/test/dialog.rc +++ b/src/test/dialog.rc @@ -1,7 +1,7 @@ #include #include "dialog.h" -TESTDLG DIALOG 10, 10, 500, 300 +TESTDLG DIALOG 10, 10, 500, 340 STYLE WS_POPUP | WS_BORDER CAPTION "Test Dialog" FONT 8,"MS Shell Dlg" @@ -17,11 +17,14 @@ TESTDLG DIALOG 10, 10, 500, 300 EDITTEXT IDSAVETXT, 10, 140, 200, 12, ES_READONLY PUSHBUTTON "Save ...",IDSAVEBUT, 10, 155, 100, 18 - COMBOBOX IDCOMBO, 10, 180, 100, 100, CBS_SIMPLE | CBS_SORT | WS_VSCROLL | WS_TABSTOP + EDITTEXT IDDIRTXT, 10, 180, 200, 12, ES_READONLY + PUSHBUTTON "Dir ...",IDDIRBUT, 10, 195, 100, 18 - AUTORADIOBUTTON "Radio 1", IDRADIO1, 120, 180, 100, 18 - AUTORADIOBUTTON "Radio 2", IDRADIO2, 120, 200, 100, 18 - AUTORADIOBUTTON "Radio 3", IDRADIO3, 120, 220, 100, 18 + COMBOBOX IDCOMBO, 10, 220, 100, 100, CBS_SIMPLE | CBS_SORT | WS_VSCROLL | WS_TABSTOP + + AUTORADIOBUTTON "Radio 1", IDRADIO1, 120, 220, 100, 18 + AUTORADIOBUTTON "Radio 2", IDRADIO2, 120, 240, 100, 18 + AUTORADIOBUTTON "Radio 3", IDRADIO3, 120, 260, 100, 18 LTEXT "Text:", IDSTATIC1, 210, 10, 35, 12 EDITTEXT IDTEXT, 250, 10, 100, 100, ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN diff --git a/src/test/w32dtst.cpp b/src/test/w32dtst.cpp index e3a55cf..94245ba 100644 --- a/src/test/w32dtst.cpp +++ b/src/test/w32dtst.cpp @@ -44,6 +44,8 @@ public: , 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) @@ -63,6 +65,8 @@ public: (this,static_cast(&Test::OnLoad)); m_savebut.OnPress (this,static_cast(&Test::OnSave)); + m_dirbut.OnPress + (this,static_cast(&Test::OnDir)); m_combo.OnSelection (this,static_cast(&Test::OnComboSel)); @@ -137,6 +141,9 @@ private: W32DLib::Text m_save; W32DLib::Button m_savebut; + W32DLib::Text m_dir; + W32DLib::Button m_dirbut; + W32DLib::ComboBox m_combo; W32DLib::RadioButton m_radio1; @@ -145,6 +152,7 @@ private: std::string m_loadpath; std::string m_savepath; + std::string m_dirpath; BOOL OnQuit(UINT msg, WPARAM wp, LPARAM lp) { @@ -231,6 +239,18 @@ private: 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(); diff --git a/src/w32dlib/common.h b/src/w32dlib/common.h index 51995b8..8fd4b14 100644 --- a/src/w32dlib/common.h +++ b/src/w32dlib/common.h @@ -115,6 +115,19 @@ namespace W32DLib const char *filter); + /// \brief Selects a directory. + /// + /// \param parent The parent window. + /// \param title Title for the selector. + /// \param path The current path. This will hold the selected path + /// on return if a directory is selected. + /// \return True if a directory was selected and path updated. + /// + static bool SelectDir(HWND parent, + const char *title, + std::string& path); + + /// \brief Returns the last error as a readable string. /// /// \return The error message @@ -132,6 +145,8 @@ namespace W32DLib private: Common(); + static CALLBACK int BrowseCallback(HWND w,UINT u,LPARAM p1,LPARAM p2); + }; // class Common }; // namespace w32dlib -- cgit v1.2.3