From bf252f63d520be07a938076518aa17c25b11f8be Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 25 Mar 2005 02:25:10 +0000 Subject: Implemented OpenFile and SaveFile. Removed SelectDirectory as it depends on IE controls and COM --- src/common.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 12 deletions(-) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index ced7779..2c9d01f 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -18,6 +18,7 @@ // // ------------------------------------------------------------------------- // +#include #include "w32dlib/common.h" namespace W32DLib @@ -49,25 +50,85 @@ bool Common::Query(HWND parent, const char *msg) // ------------------------------------------------------------ // -std::string OpenFile(const char *filter) +bool Common::OpenFile(HWND parent, + const char *title, + std::string& path, + const char *filter) { - return std::string(); + char buff[1024]; + OPENFILENAME ofn={sizeof(OPENFILENAME),0}; + + if (path.length()) + { + std::strcpy(buff,path.c_str()); + } + else + { + buff[0]=0; + } + + ofn.hwndOwner=parent; + ofn.lpstrFilter=filter; + ofn.lpstrCustomFilter=NULL; + ofn.nFilterIndex=1; + ofn.lpstrFile=buff; + ofn.nMaxFile=sizeof buff; + ofn.lpstrFileTitle=NULL; + ofn.lpstrInitialDir=NULL; + ofn.lpstrTitle=title; + ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY; + + if (GetOpenFileName(&ofn)) + { + path=buff; + return true; + } + else + { + return false; + } } // ------------------------------------------------------------ // -std::string SaveFile(const char *filter) +bool Common::SaveFile(HWND parent, + const char *title, + std::string& path, + const char *filter) { - return std::string(); -} - - -// ------------------------------------------------------------ -// -std::string SelectDirectory() -{ - return std::string(); + char buff[1024]; + OPENFILENAME ofn={sizeof(OPENFILENAME),0}; + + if (path.length()) + { + std::strcpy(buff,path.c_str()); + } + else + { + buff[0]=0; + } + + ofn.hwndOwner=parent; + ofn.lpstrFilter=filter; + ofn.lpstrCustomFilter=NULL; + ofn.nFilterIndex=1; + ofn.lpstrFile=buff; + ofn.nMaxFile=sizeof buff; + ofn.lpstrFileTitle=NULL; + ofn.lpstrInitialDir=NULL; + ofn.lpstrTitle=title; + ofn.Flags=0; + + if (GetSaveFileName(&ofn)) + { + path=buff; + return true; + } + else + { + return false; + } } -- cgit v1.2.3