C++常用操作函数Word格式文档下载.docx

上传人:b****6 文档编号:20709770 上传时间:2023-01-25 格式:DOCX 页数:27 大小:22.78KB
下载 相关 举报
C++常用操作函数Word格式文档下载.docx_第1页
第1页 / 共27页
C++常用操作函数Word格式文档下载.docx_第2页
第2页 / 共27页
C++常用操作函数Word格式文档下载.docx_第3页
第3页 / 共27页
C++常用操作函数Word格式文档下载.docx_第4页
第4页 / 共27页
C++常用操作函数Word格式文档下载.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

C++常用操作函数Word格式文档下载.docx

《C++常用操作函数Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C++常用操作函数Word格式文档下载.docx(27页珍藏版)》请在冰豆网上搜索。

C++常用操作函数Word格式文档下载.docx

std:

:

vector<

string>

split(std:

stringstr,std:

stringpattern)

{

std:

string:

size_typepos;

result;

str+=pattern;

//扩?

展1字?

符?

串?

以?

方?

便?

操ù

作痢?

intsize=str.size();

for(inti=0;

i<

size;

i++)

{

pos=str.find(pattern,i);

if(pos<

size)

{

std:

strings=str.substr(i,pos-i);

result.push_back(s);

i=pos+pattern.size()-1;

}

}returnresult;

UTF8转GBK

voidUTF8ToGBK(std:

string&

s)

charszOut[256];

memset(szOut,0,256);

strcpy(szOut,s.c_str());

unsignedshort*wszGbk=NULL;

char*szGbk=NULL;

//长度

intlen=MultiByteToWideChar(CP_UTF8,0,(LPCSTR)szOut,-1,NULL,0);

wszGbk=newunsignedshort[len+1];

memset(wszGbk,0,len*2+2);

MultiByteToWideChar(CP_UTF8,0,(LPCSTR)szOut,-1,(LPWSTR)wszGbk,len);

len=WideCharToMultiByte(CP_ACP,0,(LPWSTR)wszGbk,-1,NULL,0,NULL,NULL);

szGbk=newchar[len+1];

memset(szGbk,0,len+1);

WideCharToMultiByte(CP_ACP,0,(LPWSTR)wszGbk,-1,szGbk,len,NULL,NULL);

//szOut=szGbk;

//这样得到的szOut不正确,因为此句意义是将szGbk的首地址赋给szOut,

//当delete[]szGbk执行后szGbk的内存空间将被释放,此时将得不到szOut的内容

memset(szOut,'

\0'

strlen(szGbk)+1);

//改将szGbk的内容赋给szOut,这样即使szGbk被释放也能得到正确的值

memcpy(szOut,szGbk,strlen(szGbk));

s=szOut;

delete[]szGbk;

delete[]wszGbk;

删除文件

intDeleteFileFunc(stringv_SourceFile)

intl_Result=0;

/*_access(char*,int)判断文件是否存在

存在返回0;

不存在返回-1.

_access(constchar*path,intmode)

mode的值:

00是否存在

02写权限

04读权限

06读写权限

*/

charl_SourceFile[256]={0};

strcpy(l_SourceFile,v_SourceFile.c_str());

if(!

_access(l_SourceFile,0))//如果文件存在:

文件为只读无法删除

//去掉文件只读属性

SetFileAttributes(l_SourceFile,0);

if(DeleteFile(l_SourceFile))//删除成功

{

l_Result=0;

}

else//无法删除:

文件只读或无权限执行删除

//cout<

<

source<

无法删除:

文件为只读属性或无删除权限."

endl;

l_Result=1;

returnl_Result;

重命名文件

intRenameFileFunc(stringv_SourceFile,stringv_NewFileName)

charl_NewFileName[256]={0};

strcpy(l_NewFileName,v_NewFileName.c_str());

_access(l_SourceFile,0))//如果文件存在:

if(!

rename(l_SourceFile,l_NewFileName))//删除成功

else//无法重命名:

文件打开或无权限执行重命名

文件无法重命名(可能原因如下):

\t"

1."

newname<

已存在"

endl

//<

2."

正在使用,未关闭."

3."

你没有权限重命名此文件."

else//文件不存在

l_Result=1;

设置系统语言

intSetLanguageThrd()

BOOLbXPLaterOS=FALSE;

//是否为xp以后版本的os

OSVERSIONINFOovs;

ovs.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);

if(:

GetVersionEx(&

ovs))

bXPLaterOS=(ovs.dwPlatformId==VER_PLATFORM_WIN32_NT

&

&

ovs.dwMajorVersion>

=6

ovs.dwMinorVersion>

=0);

//vistaorlater

}

else

returnFALSE;

intlang=0;

//charl_Language[10]={0};

char*l_Language=ReadXmlFile("

System"

Language"

if(stricmp(l_Language,"

en"

)==0)

lang=1;

if(lang==1)

if(bXPLaterOS)

SetThreadUILanguage(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US));

else

SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT));

elseif(lang==0)

SetThreadUILanguage(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED));

SetThreadLocale(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_DEFAULT));

returnTRUE;

读写xml文件

char*ReadXmlFile(char*v_FatherNodeName,char*v_NodeName,char*v_Default)

charl_ComName[20]={0};

charl_TempStr[20]={0};

charl_XmlPath[256]={0};

charl_ExePath[256]={0};

GetModuleFileName(NULL,l_ExePath,256);

intl_ExePathLen=strlen(l_ExePath);

for(inti=l_ExePathLen-1;

i>

=0;

i--)

if(l_ExePath[i]=='

\\'

memcpy(l_XmlPath,l_ExePath,i);

strcat(l_XmlPath,g_XmlFileName);

CTinyXMLLibl_TinyXml;

strcpy(l_TinyXml.m_XmlPath,l_XmlPath);

intl_Result=l_TinyXml.LoadXml();

if(l_Result==0)

l_TinyXml.ReadXmlNode(v_FatherNodeName,v_NodeName,v_Default,l_TempStr);

strcpy(l_TempStr,v_Default);

returnl_TempStr;

char*ReadXmlFile(char*v_XmlFileName,char*v_FatherNodeName,char*v_NodeName,char*v_Default)

strcat(l_XmlPath,"

\\"

strcat(l_XmlPath,v_XmlFileName);

intWriteXmlFile(char*v_XmlFileName,char*v_FatherNodeName,char*v_NodeName,char*v_Value)

l_TinyXml.LoadXml();

l_TinyXml.WriteXmlNode(v_FatherNodeName,v_NodeName,v_Value);

return0;

读ini文件

intCCommServerDlg:

ReadIniFile()

charl_TempStr[2048]={0};

charl_CurrentDir[256]={0};

l_TempStr,2048,g_config_name);

GetCurrentDirectory(256,l_CurrentDir);

strcat(l_CurrentDir,"

\\Download"

CheckFolderExist(l_CurrentDir);

GetPrivateProfileString("

Application"

LocalFileList"

l_FileListPath,l_TempStr,2048,g_config_name);

LocalFileDir"

l_LocalFileDir,l_TempStr,2048,g_config_name);

读文件

voidRead(char*v_Path,char*v_Buffer,constintv_BufferLen)

HANDLEhFile=:

CreateFile(v_Path,GENERIC_READ,0,NULL,OPEN_EXISTING,NULL,NULL);

if(hFile!

=INVALID_HANDLE_VALUE)

//SetFilePointer(hFile,-1,NULL,FILE_END);

SetFilePointer(hFile,81920,NULL,FILE_BEGIN);

charl_Buffer[5]={0};

DWORDnNumberOfBytesRead;

BOOLbRet=:

ReadFile(hFile,l_Buffer,v_BufferLen,&

nNumberOfBytesRead,NULL);

memcpy(v_Buffer,l_Buffer,v_BufferLen);

//TODO...

CloseHandle(hFile);

写文件

voidWrite(char*v_Path,char*v_Content,constintv_ContentSize)

CreateFile(v_Path,GENERIC_WRITE,0,NULL,OPEN_EXISTING,NULL,NULL);

DWORDnNumberOfBytesWritten;

:

WriteFile(hFile,v_Content,v_ContentSize,&

nNumberOfBytesWritten,NULL);

查找进程

BOOLFindProcess()

inti=0;

PROCESSENTRY32pe32;

pe32.dwSize=sizeof(pe32);

HANDLEhProcessSnap=:

CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

if(hProcessSnap==INVALID_HANDLE_VALUE)

i+=0;

BOOLbMore=:

Process32First(hProcessSnap,&

pe32);

while(bMore)

//printf("

进程名称:

%s\n"

pe32.szExeFile);

if(stricmp("

RWPEPROC.exe"

pe32.szExeFile)==0)

//printf("

进程运行中"

i+=1;

bMore=:

Process32Next(hProcessSnap,&

if(i>

1){//大于1,排除自身

returntrue;

}else{

路径操作

charl_ExePath[256]={0};

charl_MainExePath[256]={0};

//GetCurrentDirectory(256,l_ExePath);

GetModuleFileName(NULL,l_ExePath,256);

intl_ExePathLen=strlen(l_ExePath);

for(inti=l_ExePathLen-1;

if(l_ExePath[i]=='

memcpy(l_MainExePath,l_ExePath,i);

strcat(l_MainExePath,"

\\RWPEPROC.exe"

BOOLAPIENTRYDllMain(HMODULEhModule,

DWORDul_reason_for_call,

LPVOIDlpReserved

switch(ul_reason_for_call)

caseDLL_PROCESS_ATTACH:

char*l_Buffer;

l_Buffer=_getcwd(NULL,0);

_getcwd(DllPath,MAXPATH);

HMODULEmodule=GetModuleHandle(0);

charszBuff[MAX_PATH]={0};

GetModuleFileName(module,szBuff,sizeof(szBuff));

intl_Pause=0;

caseDLL_THREAD_ATTACH:

caseDLL_THREAD_DETACH:

caseDLL_PROCESS_DETACH:

break;

查找指定进程

///判断指定进程是否存在

intIsProcExist(charFileName[50],boolIsDelete)

charNameBuff[MAX_PATH];

char*pFileName;

//pFileName转化为大写后的字符串指针

char*pNameBuff;

//NameBuff转化为大写后的字符串指针

BOOLbRes;

//返回结果

HINSTANCEhInstance;

//动态库句柄

HANDLEhHandle;

//进程句柄

inti,j;

//循环变量

intlen;

funEnumPorcessEnumProcesses;

funGetModuleFileNameExGetModuleFileNameEx;

DWORD*buffer,maxNum,factNum;

maxNum=MAXPROCESS;

factNum=MAXPROCESS;

buffer=(DWORD*)malloc(maxNum);

hInstance=LoadLibrary("

psapi.dll"

//装载psapi.dll

if(hInstance)

EnumProcesses=(funEnumPorcess)GetProcAddress(hInstance,"

EnumProcesses"

if(EnumProcesses)

bRes=EnumProcesses(buffer,maxNum,&

factNum);

//枚举进程,得到进程名称和实际进程总大小

if(bRes)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1