文章目录
在应用程序编程中,有时需要选择桌面文件夹的路径,这时可以通过win32提供的api来获取,源代码如下所示:
1.获取桌面
- 1.获取桌面
- 2.jsoncpp
#include
#include
#pragma comment(lib, "shell32.lib")
std::string GetDesktopFolder()
{
char path[255];
SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, 0);
std::string rlt=path;
return rlt;
}
2.jsoncpp
在C++编码中,需要根据参数进行数据处理时,经常遇到的一个问题就是需要将关键的内存类属性数据转为文件保存,方便下次加载使用。使用jsoncpp开源库,下文展示一个范例代码,源代码如下所示:
#include
#include
#include
#include
#include
//加载文档
void ACustomDocumentInfo::LoadDocumentParaInfo(std::string filename)
{
// 打开文件
std::ifstream ifs(filename, std::ios::binary);
if (!ifs.good())
{
return;
}
//读取信息
Json::Value root;
Json::Reader reader;
if (!reader.parse(ifs, root)) {
return;
}
//转换信息
int sz = root.size();
for (int i = 0; i SetContentByJson(property.toStyledString());
m_ANormalLabelSizeMap[layer_name]=pANormalLabelSize;
}
}
}
void ACustomDocumentInfo::SaveDocumentParaInfo(std::string filename)
{
//打开文件
std::ofstream ofs(filename, std::ios::binary | std::ios_base::out | std::ios_base::trunc);
if (!ofs.good())
{
return;
}
//将map信息转为json
Json::Value root;
std::map::iterator it=m_ANormalLabelSizeMap.begin();
for (;it!=m_ANormalLabelSizeMap.end();it++)
{
//保存图层名
Json::Value jObject;
jObject["layer_name"]=it->first;
std::string json_str=it->second->GetContentByJson();
//常规尺寸标注
jObject["layer_type"]="normal_label_size";
//保存正常尺寸数据
Json::Reader reader;
Json::Value value;
if (reader.parse(json_str, value))
{
jObject["obj_property"]=value;
}
root.append(jObject);
}
ofssecond;
}
return jObject.toStyledString();
}
static std::string itoa_self(int i)
{
std::stringstream ss;
ss
关注
打赏
热门博文
- Adobe illustrator插件开发-SPInterfaceSuite-插件A向插件B传递消息-插件通信-AI插件开发
- javascript-ztree-树形控件-初始化-加载节点数据-节点数据获取
- Adobe illustrator插件开发-坐标系统-AIHardSoftSuite-画板坐标-页面坐标-AI插件开发
- Adobe illustrator插件开发-AIUIDUtilsSuite-AIUIDPoolSuite-AIUIDSuite-AIUIDREFSuite-Art唯一标识符与索引-AI插件开发
- C++-逆向分析-类的成员函数地址与对象地址动态绑定-this指针-成员函数和成员虚函数反汇编解析
- C++-逆向分析-结构体和类-内存布局-this指针-静态数据成员-对象作为参数和返回值
- Adobe illustrator插件开发-命令名称-AddCommand -AI插件开发
- Adobe illustrator插件开发-事件-PlugPlugAddEventListener-向系统注册事件-AI插件开发
- Adobe illustrator插件开发-ole拖拽粘贴交换数据格式-RegisterClipboardFormat函数-AI插件开发
- Adobe illustrator插件开发-所有模块列表-内部存在大量非公开的Suite-AI插件开发