LIBURANIA
GUI library (a wrapper of Win32 API) in C++
読み取り中…
検索中…
一致する文字列を見つけられません
cmndlg.h
[詳解]
1/*
2 * Copyright 2002-2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
41#ifndef INCLUDE_GUARD_URANIA_COMMONDLG_H
42#define INCLUDE_GUARD_URANIA_COMMONDLG_H
43
44#include <memory>
45#include <cwchar>
46#include "wbase.h"
47
53class urania::CommonDialogBase : eunomia::Noncopyable<urania::CommonDialogBase>
54{
55protected:
56 CommonDialogBase() = default;
57
58public:
59 virtual ~CommonDialogBase() = default;
60};
61
62
69{
70private:
71 OPENFILENAME ofn_;
72 wchar_t name_[MAX_PATH];
73 wchar_t initDir_[MAX_PATH];
74 std::wstring filter_;
75 std::wstring defExt_;
76
77protected:
78 FileDialog(const std::wstring& flt, const std::wstring& ext);
79
80public:
81 bool doModalOpenFile(const urania::WndBase* win);
82 bool doModalSaveFile(const urania::WndBase* win);
83
84 std::wstring getFilePath() const { return name_; }
85 std::wstring getFileName() const { return name_ + ofn_.nFileOffset; }
86
87 std::wstring getFileDir() const
88 {
89 wchar_t tmp[MAX_PATH];
90 std::wcsncpy(tmp, name_, ofn_.nFileOffset);
91 tmp[ofn_.nFileOffset] = L'\0';
92 return tmp;
93 }
94
95 std::wstring getFileExt() const
96 {
97 if (!ofn_.nFileExtension)
98 return L"";
99 else
100 return name_ + ofn_.nFileExtension;
101 }
102
103 void clearFilePath() { name_[0] = L'\0'; }
104
105 void setFilePath(const std::wstring& path)
106 {
107 std::wcsncpy(name_, path.c_str(), MAX_PATH);
108 name_[MAX_PATH - 1] = L'\0';
109 }
110
111 void setInitDir(const std::wstring& path)
112 {
113 wcsncpy(initDir_, path.c_str(), MAX_PATH);
114 initDir_[MAX_PATH - 1] = L'\0';
115 }
116
117 static
118 std::unique_ptr<FileDialog>
119 create(const std::wstring& flt, const std::wstring& ext =L"")
120 { return std::unique_ptr<FileDialog>(new FileDialog(flt, ext)); }
121};
122
123
124
125
126#endif // INCLUDE_GUARD_URANIA_COMMONDLG_H
コモンダイアログ基底クラス
Definition cmndlg.h:54
virtual ~CommonDialogBase()=default
ファイルダイアログ
Definition cmndlg.h:69
bool doModalOpenFile(const urania::WndBase *win)
Definition cmndlg.cpp:65
std::wstring getFileExt() const
Definition cmndlg.h:95
void clearFilePath()
Definition cmndlg.h:103
void setFilePath(const std::wstring &path)
Definition cmndlg.h:105
FileDialog(const std::wstring &flt, const std::wstring &ext)
Definition cmndlg.cpp:46
std::wstring getFileName() const
Definition cmndlg.h:85
static std::unique_ptr< FileDialog > create(const std::wstring &flt, const std::wstring &ext=L"")
Definition cmndlg.h:119
void setInitDir(const std::wstring &path)
Definition cmndlg.h:111
bool doModalSaveFile(const urania::WndBase *win)
Definition cmndlg.cpp:91
std::wstring getFilePath() const
Definition cmndlg.h:84
std::wstring getFileDir() const
Definition cmndlg.h:87
HWND管理用基底クラス
Definition wbase.h:55
HWND管理基底クラス