首页 > 代码库 > [wxWidgets]_[初级]_[不常见但实用的类wxStandardPaths]

[wxWidgets]_[初级]_[不常见但实用的类wxStandardPaths]


场景:

1.wxStandardPaths   用来获取各种系统路径,可以用于存放app的配置数据。比如文档目录,appData等。


代码:

#include "wx/wxprec.h"

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "wx/cmdline.h"
#include "wx/app.h" 
#include <assert.h>
#include <iostream>
#include <stdio.h>
#include "wx/stdpaths.h"
#include <Windows.h>
#include <shlobj.h>

using namespace std;

void TestStandardPaths()
{
	cout << "TestStandardPaths" << endl;
	wxStandardPaths& sp = wxStandardPaths::Get();
	cout << "GetAppDocumentsDir (): " << sp.GetAppDocumentsDir() << endl;
	cout << "GetDataDir (): " << sp.GetDataDir() << endl;
	cout << "GetDocumentsDir (): " << sp.GetDocumentsDir() << endl;
	cout << "GetExecutablePath  (): " << sp.GetExecutablePath() << endl;
	
	cout << "GetLocalDataDir(): " << sp.GetLocalDataDir() << endl;
	cout << "GetPluginsDir(): " << sp.GetPluginsDir() << endl;
	cout << "GetResourcesDir(): " << sp.GetResourcesDir() << endl;
	cout << "GetTempDir(): " << sp.GetTempDir() << endl;
	cout << "GetUserDataDir(): " << sp.GetUserDataDir() << endl;
	cout << "MSWGetShellDir(): " << sp.MSWGetShellDir(CSIDL_APPDATA) << endl;
}

int main(int argc,char* argv[])
{
	wxInitialize();
	wxEntryStart(argc,argv);
	wxInitAllImageHandlers();

	TestStandardPaths();
	wxEntryCleanup();
	wxUninitialize();
	return 0;
}





输出:

TestStandardPaths
GetAppDocumentsDir (): C:\Users\Admin\Documents
GetDataDir (): E:\workspace\test_project\01.test_project\test_wx\test_wxCmdLineP
arser\msw\Debug\Bin
GetDocumentsDir (): C:\Users\Admin\Documents
GetExecutablePath  (): E:\workspace\test_project\01.test_project\test_wx\test_wx
CmdLineParser\msw\Debug\Bin\test_wxCmdLineParser.exe
GetLocalDataDir(): E:\workspace\test_project\01.test_project\test_wx\test_wxCmdL
ineParser\msw\Debug\Bin
GetPluginsDir(): E:\workspace\test_project\01.test_project\test_wx\test_wxCmdLin
eParser\msw\Debug\Bin
GetResourcesDir(): E:\workspace\test_project\01.test_project\test_wx\test_wxCmdL
ineParser\msw\Debug\Bin
GetTempDir(): C:\Users\Admin\AppData\Local\Temp
GetUserDataDir(): C:\Users\Admin\AppData\Roaming\test_wxCmdLineParser
MSWGetShellDir(): C:\Users\Admin\AppData\Roaming




[wxWidgets]_[初级]_[不常见但实用的类wxStandardPaths]