#ifndef __GLOBAL_WECHAT__
#define __GLOBAL_WECHAT__

#include <tlhelp32.h>
#include <vector>
#include <string>
using namespace std;

#ifdef UNICODE
typedef wstring TString;
#else
typedef string TString;
#endif

#define WECHAT _T("WeChat.exe")
#define OGC_TOOL _T("Demo.exe")


typedef struct __PROCINFO__
{
    DWORD   dwProId;        // 进程id;
    TString strProName;     // 进程名称;
    TString strProFile;     // 进程路径;
}ProInfo, *pProInfo;

typedef struct __WNDINFO__
{
    HWND    hWnd;
	DWORD	dwCtrlId;
    TCHAR   szClassName[MAX_PATH];
    TCHAR   szWndTitle[MAX_PATH];
    __WNDINFO__()
    {
		dwCtrlId = 0;
        memset(szClassName, 0, sizeof(TCHAR)*MAX_PATH);
        memset(szWndTitle, 0, sizeof(TCHAR)*MAX_PATH);
    }

	__WNDINFO__ &operator=(const __WNDINFO__ &that)
	{
		if ( this == &that )
			return *this;

		hWnd = that.hWnd;
		dwCtrlId = that.dwCtrlId;
		_stprintf(szWndTitle, _T("%s"), that.szWndTitle);
		_stprintf(szClassName, _T("%s"), that.szClassName);

		return *this;
	}

}WNDINFO, *LPWNDINFO;

typedef struct __WNDDATA__
{
    DWORD   dwPid;
    std::vector<WNDINFO> vtWndInfo;

	void AddWnd(WNDINFO &data)
	{
		if (!IsExistWnd(data.hWnd))
			vtWndInfo.push_back(data);
	}

	bool IsExistWnd(HWND hWnd)
	{
		bool bExist = false;
		for (std::vector<WNDINFO>::iterator it = vtWndInfo.begin(); it != vtWndInfo.end(); it++ )
		{
			if ( it->hWnd == hWnd )
			{
				bExist = true;
				break;
			}
		}

		return bExist;
	}
}WNDDATA,*LPWNDDATA;

// 全局变量;
extern TCHAR g_szModulePath[MAX_PATH];			// 软件目录;
extern TCHAR g_szModuleFileName[MAX_PATH];		// 软件名称;
extern TCHAR g_szIniFile[MAX_PATH];

// 配置文件信息;
extern TCHAR g_szServAddress[MAX_PATH];		
extern DWORD g_dwServPort;					
extern TCHAR g_szAccount[MAX_PATH];			
extern TCHAR g_szPassword[MAX_PATH];		
extern TCHAR g_szWeChatPath[MAX_PATH];		
extern TCHAR g_szCacheDir[MAX_PATH];	
extern TCHAR g_szDynamicLibraryPath[MAX_PATH];


// 控制台输出;
extern BOOL g_bStdOut;

extern int GetIniInfo(LPCTSTR lpIniDir = NULL, LPCTSTR lpIniName = NULL);
extern DWORD FindProcess(LPCTSTR lpProName);
extern vector<DWORD> FindAllProcess(LPCTSTR lpProName);
extern void FindAllProcess(std::vector<ProInfo> &vtProInfo);
extern HANDLE FindModule(LPCTSTR lpModuleName, DWORD dwPID);
extern HANDLE FindModuleEx(LPCTSTR lpModuleName, DWORD dwPid);
extern BOOL GetDebugPriv();

extern BOOL GetFileVersion( IN HMODULE hModule, IN DWORD (&dwArray)[4]);
extern BOOL GetFileVersionEx( IN LPCTSTR lpFileName, IN DWORD (&dwArray)[4] );
extern BOOL GetProductVersion( IN HMODULE hModule, IN DWORD (&dwArray)[4]);
extern BOOL GetProductVersionEx( IN LPCTSTR lpFileName, IN DWORD (&dwArray)[4] );

extern BOOL GetOSDisplayString(LPTSTR pszOS);
extern void WriteTextLog(const TCHAR *format, ...);
extern BOOL CopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists=TRUE);
extern void tSplitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
extern void tSplitpath(const char *path, char *drive, char *dir, const int &nTimes);
extern BOOL IsDirectoryLegitimate(const CString &strDirectory);
extern void ShowSystemErrorInfo(CString strDescription, const DWORD &dwError);
extern BOOL MySystemShutdown(LPTSTR lpMsg);
extern BOOL PreventSystemShutdown();
extern BOOL MySystemShutdown();

// 根据进程pid获取进程对应程序的窗口句柄;
HWND GetProcessMainWnd(const DWORD& dwTagetProcessId, LPCTSTR lpTagetWndName);
// 获取指定进程名的进程主窗口;
HWND GetProcessMainWnd(LPCTSTR lpProcessName, LPCTSTR lpTagetWndName);
BOOL EnumProcessAllWnd(LPWNDDATA lpWndData);
//////////////////////////////////////////////////////////////////////////
extern BOOL GetWeChatPath();
extern BOOL OpenWeChat();

#endif