CUtilFunc.h

来源:互联网 发布:office软件验收 编辑:程序博客网 时间:2024/06/20 02:03

// UtilityFunc.h: interface for the CUtilityFunc class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_UTILFUNC_H__18154823_089F_4064_87D3_104F264FD76C__INCLUDED_)
#define AFX_UTILFUNC_H__18154823_089F_4064_87D3_104F264FD76C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define SAFE_DEL_ARRAY(x) if (x) {delete []x;x = NULL;}
#define SAFE_DEL_POINT(x) if (x) {delete x;x = NULL;}
 
#include <list>
#include <vector>

using namespace std;

struct FILE_VERSION
{
 CHAR szVersion[MAX_PATH];
 CHAR szDescription[MAX_PATH];
 CHAR szCompany[MAX_PATH];
 CHAR    szProcName[MAX_PATH];
};

class AFX_EXT_CLASS CUtilFunc
{
public: 
 CUtilFunc();
  ~CUtilFunc();
public:
 static BOOL GetHostInfo(char * outIP, char * outName);

 //static int ExportDllSys(HMODULE hModule,UINT resID,LPCTSTR typeName,LPCTSTR dllName);
 static int SetFileHidden(CString sFilePath);

 static BOOL CheckExistFile(const char *sFile);

 static int    ExecuteExe(char *sCmdline);
 static int    ExecuteIEWin7(char *sCmdline);
 static string ExecuteApp(char *sCmdline);
 static BOOL   ExecuteAsAdmin(CHAR * pFile, CHAR *pParameters,  int nShow = SW_SHOWNORMAL,int bParam = 0);

 static void SetFileAttributes(char *sPath,DWORD dwAttrs);
  
 static BOOL CheckUrl(const char *url);
 
 static void GetMainPath(char *sFolderName,int from =1);//1:从应用程序获取,2:从注册表获取
 static void GetMainAppName(char *sMainAppName);

 static DWORD EraseString(vector<string> &vec_str,string str);
 
 static DWORD UniqueCopyString(vector<string> &vecFrom,vector<string> &vecTo);

 static HWND GetWindowHWND(char *sCaption);

 static BOOL CheckExistProc(DWORD dwPid);
 static BOOL CheckExistProc(const char *szName);

 static BOOL GetFileVersions(char * pFilePath, FILE_VERSION * pVerInfo);
 static BOOL GetFileVersions2(char *pFileName, FILE_VERSION * pVerInfo);
 static BOOL GetFileVersions2(DWORD dwId, FILE_VERSION * pVerInfo);

 static BOOL CheckExistBuf(char *str,char *subStr);
 static BOOL CheckExitList(list<string> &list_char,string buf);
 static BOOL CheckExitList2(list<string> &list_char,string buf);
 static void GetHostIp(char *svrIp);
 static DWORD GetNowTimeStamp();
 static DWORD GetPIDFromName(const char *szName); 
 static DWORD GetPIDFromName2(const char *szName,DWORD notID); //不是notID的进程号

 static DWORD GetFileCheckSum(string sPath);
 static string GetProcessAccount(DWORD dwPid);
 static CString GetFullPathFromPID(DWORD dwPid);
 static CString GetFileNameFromPID(DWORD dwPid);
 static CString GetSysTimeStr();
 static string GetSysTimeFormatStr(int format = 0);
 static CString GetFormatTimeStr(CTime &tt,int format = 0);
 static CString GetFormatDateStr(int idx,int format = 0);
 static CString GetFormatTimeStr(int y,int m,int d,int h,int mi,int s);
 static CString GetFormatTimeStrBeg(CTime &tt );
 static CString GetFormatTimeStrEnd(CTime &tt);
 static DWORD   LoadProcList(vector<string> &vecProc);
 static DWORD   LoadProcList(vector<DWORD> &vecPid,vector<string> &vecProc);

 static void ClearList(list<string> &list_char);
 static void LoadBuf2List(list<string> &list_char,char *inBuf,char ch='*'); //ch 为分割标志
 //static void AddRule2List(list<RULE_CLIENT_CHAR*> &list_rule,UINT nCmd, char *sContent);
 //static void AddRule2List(list<RULE_CLIENT_INT*> &list_rule,UINT nCmd, int iContent);
 static BOOL StartProcess(char *szPath,int mode = SW_SHOW);
 static BOOL KillProcess(const char *szName,DWORD dwProcessID = 0);

 static BOOL GetSelectedListItem(CListCtrl &lst,int iSubItem = -1,char *sItemText= NULL);
 static int  Split( char * line, char delimiter, char * items[] );

 static void LogFile(const char *slog,...);

 static string GetRuleText(UINT nID);

 static int ParseVer(char* ver,int &major,int &minor,int &revi);//解析版本
 static int CompareVer(char *ver1,char *ver2); //比较版本

 static int ConvertUtf8ToANSI(char *sReadData,char *outData);
 static int SaveUtf8ToFile(char *sReadData,char *xmlFile);

 static BOOL GetProcInfo(IN CString procPath,OUT CString &name,OUT CString &proc,OUT CString &author);

 static BOOL GetProcInfo(IN CString proc,OUT CString &name,OUT CString &author);

 static void  SetTransparent(CWnd *pWnd);

 static void SetCaptionBK(CWnd *pWndParent,UINT uID,CString sCaption);

 static int ExportDllSys(HMODULE hModule,UINT resID,LPCTSTR typeName,LPCTSTR dllName);

 //以子进程形式
 static int CreateProcessEx(char *cmd);

 //删除非空文件夹
 static bool DeleteDirectory(char* sDirName);

 //枚举文件夹中文件
 static int ListFileInDirectory(char *sDirName,vector<CString> &vecFile,int dep = 1);

 static int GetShareMem(char *param,char *value);
 static int SetShareMem(char *param,char * value);
 static int SetShareMem(char *param,int value);

 static void   ShowTrayIcon(char szIcon[],BOOL hide);

 static int   CheckHasChinese(const char *str);
public:
 static CString GetTmpFolder(void);
 static CString GetAppDataFolder();
};


#endif // !defined(AFX_UTILFUNC_H__18154823_089F_4064_87D3_104F264FD76C__INCLUDED_)

原创粉丝点击