Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
3751fb7a
Commit
3751fb7a
authored
Sep 14, 2017
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加获取系统特殊文件夹功能;另存为可设置默认文件夹、默认文件名
parent
afce9bf3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
file_op.h
win32/file_op.h
+28
-2
path_op.h
win32/path_op.h
+22
-0
No files found.
win32/file_op.h
View file @
3751fb7a
#pragma once
#include <Windows.h>
#include <string>
namespace
jlib
{
inline
bool
get_file_open_dialog_result
(
std
::
wstring
&
path
,
HWND
hWnd
=
nullptr
,
const
std
::
wstring
&
default_folder
=
L""
,
const
std
::
wstring
&
ext
=
L""
,
UINT
cFileTypes
=
0
,
const
COMDLG_FILTERSPEC
*
rgFilterSpec
=
nullptr
)
{
...
...
@@ -20,8 +23,17 @@ inline bool get_file_open_dialog_result(std::wstring& path,
IID_IFileOpenDialog
,
reinterpret_cast
<
void
**>
(
&
pFileOpen
));
if
(
SUCCEEDED
(
hr
))
{
if
(
!
default_folder
.
empty
())
{
IShellItem
*
psiFolder
;
LPCWSTR
szFilePath
=
SysAllocStringLen
(
default_folder
.
data
(),
default_folder
.
size
());
hr
=
SHCreateItemFromParsingName
(
szFilePath
,
NULL
,
IID_PPV_ARGS
(
&
psiFolder
));
if
(
SUCCEEDED
(
hr
))
hr
=
pFileOpen
->
SetDefaultFolder
(
psiFolder
);
}
if
(
!
ext
.
empty
())
{
pFileOpen
->
SetDefaultExtension
(
ext
.
c_str
());
pFileOpen
->
SetDefaultExtension
(
ext
.
data
());
}
if
(
cFileTypes
!=
0
&&
rgFilterSpec
)
{
...
...
@@ -63,6 +75,8 @@ inline bool get_file_open_dialog_result(std::wstring& path,
inline
bool
get_save_as_dialog_path
(
std
::
wstring
&
path
,
HWND
hWnd
=
nullptr
,
const
std
::
wstring
&
default_folder
=
L""
,
const
std
::
wstring
&
default_name
=
L""
,
const
std
::
wstring
&
ext
=
L""
,
UINT
cFileTypes
=
0
,
const
COMDLG_FILTERSPEC
*
rgFilterSpec
=
nullptr
)
{
...
...
@@ -81,8 +95,20 @@ inline bool get_save_as_dialog_path(std::wstring& path,
if
(
SUCCEEDED
(
hr
))
{
if
(
!
default_folder
.
empty
())
{
IShellItem
*
psiFolder
;
LPCWSTR
szFilePath
=
SysAllocStringLen
(
default_folder
.
data
(),
default_folder
.
size
());
hr
=
SHCreateItemFromParsingName
(
szFilePath
,
NULL
,
IID_PPV_ARGS
(
&
psiFolder
));
if
(
SUCCEEDED
(
hr
))
hr
=
pFileSave
->
SetDefaultFolder
(
psiFolder
);
}
if
(
!
default_name
.
empty
())
{
pFileSave
->
SetFileName
(
default_name
.
data
());
}
if
(
!
ext
.
empty
())
{
pFileSave
->
SetDefaultExtension
(
ext
.
c_str
());
pFileSave
->
SetDefaultExtension
(
ext
.
data
());
}
if
(
cFileTypes
!=
0
&&
rgFilterSpec
)
{
...
...
win32/path_op.h
View file @
3751fb7a
#
pragma
once
#include <string>
#include <algorithm>
#include <Windows.h>
#include <ShlObj.h>
#pragma comment(lib, "Shell32.lib")
namespace
jlib
{
...
...
@@ -38,6 +42,24 @@ inline std::string integrate_path(const std::string& path, char replace_by = '_'
return
ret
;
}
inline
std
::
wstring
get_special_folder
(
int
csidl
)
{
wchar_t
path
[
MAX_PATH
]
=
{
0
};
if
(
SHGetSpecialFolderPathW
(
nullptr
,
path
,
csidl
,
false
))
{
return
std
::
wstring
(
path
);
}
return
std
::
wstring
();
}
inline
std
::
string
get_special_folder_a
(
int
csidl
)
{
char
path
[
MAX_PATH
]
=
{
0
};
if
(
SHGetSpecialFolderPathA
(
nullptr
,
path
,
csidl
,
false
))
{
return
std
::
string
(
path
);
}
return
std
::
string
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment