Dlg4.cpp
资源名称:WarH_2.10.rar [点击查看]
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:10k
源码类别:
外挂编程
开发平台:
Visual C++
- // Dlg4.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "WarH.h"
- #include "Register.h"
- #include "Dlg4.h"
- #include "YZFindFile.h"
- HRESULT CreateLink(LPCWSTR lpszPathObj, LPWSTR lpszPathLink, LPWSTR lpszDesc);
- HRESULT GetDesktop(LPWSTR lpPath, DWORD* lpSize);
- // CDlg4 对话框
- IMPLEMENT_DYNAMIC(CDlg4, CDialog)
- CDlg4::CDlg4(CWnd* pParent /*=NULL*/)
- : CDialog(CDlg4::IDD, pParent)
- , m_strPath(_T(""))
- , m_strParam(_T(""))
- , m_bWindows(FALSE)
- , m_bOpenGL(FALSE)
- , m_bLink(FALSE)
- , m_bAutoRun(FALSE)
- {
- }
- CDlg4::~CDlg4()
- {
- }
- void CDlg4::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Text(pDX, IDC_PATH, m_strPath);
- DDX_Text(pDX, IDC_COMLINE, m_strParam);
- DDX_Check(pDX, IDC_WINDOW, m_bWindows);
- DDX_Check(pDX, IDC_OPENGL, m_bOpenGL);
- DDX_Check(pDX, IDC_CHECK4, m_bLink);
- DDX_Check(pDX, IDC_AUTORUN, m_bAutoRun);
- }
- BEGIN_MESSAGE_MAP(CDlg4, CDialog)
- ON_WM_CTLCOLOR()
- ON_WM_SHOWWINDOW()
- ON_BN_CLICKED(IDC_SEARCH, &CDlg4::OnBnClickedSearch)
- ON_BN_CLICKED(IDC_RUN, &CDlg4::OnBnClickedRun)
- ON_BN_CLICKED(IDC_WINDOW, &CDlg4::OnBnClickedWindow)
- ON_BN_CLICKED(IDC_OPENGL, &CDlg4::OnBnClickedOpengl)
- ON_BN_CLICKED(IDC_SAVE, &CDlg4::OnBnClickedSave)
- ON_BN_CLICKED(IDC_READ, &CDlg4::OnBnClickedRead)
- ON_BN_CLICKED(IDC_CHECK4, &CDlg4::OnBnClickedCheck4)
- ON_BN_CLICKED(IDC_LastReplay, &CDlg4::OnBnClickedLastreplay)
- ON_BN_CLICKED(IDC_AUTORUN, &CDlg4::OnBnClickedAutorun)
- ON_BN_CLICKED(IDC_SEARCHFILE, &CDlg4::OnBnClickedSearchfile)
- END_MESSAGE_MAP()
- // CDlg4 消息处理程序
- HBRUSH CDlg4::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: 在此更改 DC 的任何属性
- int nID = pWnd->GetDlgCtrlID();
- switch (nID)
- {
- case IDC_STATIC:
- case IDC_PATH:
- case IDC_COMLINE:
- pDC->SetTextColor(RGB(255, 0, 0));
- break;
- case IDC_STATICB:
- pDC->SetTextColor(RGB(0, 0, 255));
- break;
- }
- // TODO: 如果默认的不是所需画笔,则返回另一个画笔
- return hbr;
- }
- void CDlg4::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CDialog::OnShowWindow(bShow, nStatus);
- // TODO: 在此处添加消息处理程序代码
- OnBnClickedRead();
- }
- void CDlg4::OnBnClickedSearch()
- {
- // TODO: 在此添加控件通知处理程序代码
- CFileDialog fileDlg(true, _T(""), _T("War3.exe"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- _T("魔兽可执行文件(War3.exe)|War3.exe||"));
- if (fileDlg.DoModal() == IDOK)
- {
- m_strPath = fileDlg.GetPathName();
- UpdateData(false);
- }
- }
- void CDlg4::OnBnClickedRun()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData();
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- CString strCommandline;
- strCommandline = m_strPath + ' ' + m_strParam;
- // Start the child process.
- if( !CreateProcess( NULL, // No module name (use command line).
- strCommandline.GetBuffer(), // Command line.
- NULL, // Process handle not inheritable.
- NULL, // Thread handle not inheritable.
- FALSE, // Set handle inheritance to FALSE.
- 0, // No creation flags.
- NULL, // Use parent's environment block.
- NULL, // Use parent's starting directory.
- &si, // Pointer to STARTUPINFO structure.
- &pi ) // Pointer to PROCESS_INFORMATION structure.
- )
- {
- MessageBox(_T("路征不对吧!"));
- return;
- }
- }
- void CDlg4::OnBnClickedWindow()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(1);
- if (m_bWindows)
- {
- if (m_strParam.Find(_T("-windows")) == -1)
- {
- m_strParam += "-windows ";
- }
- }
- else
- {
- int index = m_strParam.Find(_T("-windows"));
- if (index != -1)
- {
- m_strParam.Delete(index, 9);
- }
- }
- UpdateData(0);
- }
- void CDlg4::OnBnClickedOpengl()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(1);
- if (m_bOpenGL)
- {
- if (m_strParam.Find(_T("-opengl")) == -1)
- {
- m_strParam += "-opengl ";
- }
- }
- else
- {
- int index = m_strParam.Find(_T("-opengl"));
- if (index != -1)
- {
- m_strParam.Delete(index, 8);
- }
- }
- UpdateData(0);
- }
- void CDlg4::OnBnClickedLastreplay()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(1);
- CString str;
- str =_T("-loadfile "") + str + m_strPath;
- str.Replace(_T("War3.exe"), _T("replay\LastReplay.w3g" "));
- if (::IsDlgButtonChecked(m_hWnd, IDC_LastReplay))
- {
- if (m_strParam.Find(str) == -1)
- {
- m_strParam = str + m_strParam;
- }
- }
- else
- {
- int index = m_strParam.Find(str);
- if (index != -1)
- {
- m_strParam.Delete(index, str.GetLength());
- }
- }
- UpdateData(0);
- }
- void CDlg4::OnBnClickedSave()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(1);
- BOOL bResult = TRUE;
- CRegister reg;
- bResult = bResult && reg.CreateKeyW(HKEY_CURRENT_USER, _T("Software\Blizzard Entertainment\Warcraft III\WarH"));
- bResult = bResult && reg.SetValueExExW(_T("War3Path"), REG_SZ, (LPBYTE)m_strPath.GetBuffer(), wcslen(m_strPath.GetBuffer()) * sizeof(TCHAR));
- bResult = bResult && reg.SetValueExExW(_T("Param"), REG_SZ, (LPBYTE)m_strParam.GetBuffer(), wcslen(m_strParam.GetBuffer()) * sizeof(TCHAR));
- bResult = bResult && reg.SetValueExExA("bWindows", REG_BINARY, (LPBYTE)&m_bWindows, sizeof(BYTE));
- bResult = bResult && reg.SetValueExExA("bOpenGL", REG_BINARY, (LPBYTE)&m_bOpenGL, sizeof(BYTE));
- bResult = bResult && reg.SetValueExExA("bAutoRun", REG_BINARY, (LPBYTE)&m_bAutoRun, sizeof(BYTE));
- if (bResult)
- {
- MessageBox(_T("保存成功!"), _T("消息:)"), MB_OK);
- }
- }
- void CDlg4::OnBnClickedRead()
- {
- // TODO: 在此添加控件通知处理程序代码
- static BYTE szPath[MAX_PATH];
- static BYTE szParam[MAX_PATH];
- memset(szPath, 0, MAX_PATH);
- memset(szParam, 0, MAX_PATH);
- CRegister reg;
- reg.OpenKeyEx(HKEY_CURRENT_USER, _T("Software\Blizzard Entertainment\Warcraft III\WarH"));
- reg.QueryValueExW(_T("War3Path"), szPath, MAX_PATH);
- reg.QueryValueExW(_T("Param"), szParam, MAX_PATH);
- reg.QueryValueExA("bWindows", (LPBYTE)&m_bWindows, 4);
- reg.QueryValueExA("bOpenGL", (LPBYTE)&m_bOpenGL, 4);
- reg.QueryValueExA("bAutoRun", (LPBYTE)&m_bAutoRun, 4);
- m_strPath.Format((LPWSTR)szPath);
- m_strParam.Format((LPWSTR)szParam);
- UpdateData(0);
- }
- void CDlg4::OnBnClickedCheck4()
- {
- // TODO: 在此添加控件通知处理程序代码
- wchar_t chDir[512];
- DWORD size;
- UpdateData();
- GetDesktop(chDir, &size);
- wcscat(chDir, _T("\Frozen Throne.lnk"));
- if (m_bLink)
- {
- CString str = m_strPath;
- str.Replace(_T("War3"), _T("Frozen Throne"));
- CreateLink(str.GetBuffer(), chDir, _T("魔兽快捷方式"));
- }
- else
- {
- SHFILEOPSTRUCT fileOp;
- ZeroMemory(&fileOp, sizeof(fileOp)) ;
- fileOp.hwnd = HWND_DESKTOP;
- fileOp.wFunc = FO_DELETE;
- fileOp.pFrom = chDir;
- fileOp.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS ; // 删除文件到回收站
- SHFileOperation(&fileOp);
- }
- }
- HRESULT GetDesktop(LPWSTR lpPath, DWORD* lpSize)
- {
- long result;
- HKEY hKey;
- DWORD dwType;
- result = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"),
- NULL, KEY_QUERY_VALUE,&hKey);
- if(result == ERROR_SUCCESS)
- {
- // 查询Desktop的键值并把查询到的结果保存在字符串“chDir”中(因为Windows并不一定安装在c盘中,所以要查询注册表)
- result = RegQueryValueEx(hKey,_T("Desktop"),0,&dwType,(LPBYTE)lpPath,lpSize);
- result = RegCloseKey(hKey);
- }
- return result;
- }
- HRESULT CreateLink(LPCWSTR lpszPathObj, LPWSTR lpszPathLink, LPWSTR lpszDesc)
- {
- HRESULT hres;
- IShellLink* psl;
- CoInitialize(NULL);
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL,
- CLSCTX_INPROC_SERVER,
- IID_IShellLink,
- (void**)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
- // Set the path to the shortcut target and add the
- // description.
- psl->SetPath(lpszPathObj);
- psl->SetDescription(lpszDesc);
- // Query IShellLink for the IPersistFile interface for saving the
- // shortcut in persistent storage.
- hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
- if (SUCCEEDED(hres))
- {
- wchar_t wsz[MAX_PATH]; // Ensure that the string is ANSI.
- //MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
- // Save the link by calling IPersistFile::Save.
- hres = ppf->Save(lpszPathLink, TRUE);
- ppf->Release();
- }
- psl->Release();
- }
- return hres;
- }
- void CDlg4::OnBnClickedAutorun()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData();
- HKEY hKey;
- DWORD dwType;
- LONG result;
- TCHAR wsBuf[MAX_PATH];
- memset(wsBuf, 0, MAX_PATH * 2);
- result = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\Microsoft\Windows\CurrentVersion\Run"),
- NULL, KEY_ALL_ACCESS, &hKey);
- if (result == ERROR_SUCCESS)
- {
- if (m_bAutoRun)
- {
- ::GetCurrentDirectoryW(MAX_PATH, wsBuf);
- wsprintf(wsBuf, _T("%s%s"), wsBuf, _T("\WarH.exe"));
- RegSetValueExW(hKey, _T("WarH V1.12"), NULL, REG_SZ, (LPBYTE)wsBuf, wcslen(wsBuf) * sizeof(TCHAR));
- }
- else
- {
- ::RegDeleteKeyW(hKey, _T("WarH V1.12"));
- }
- }
- }
- void CALLBACK ShowPath(LPTSTR lpStr)
- {
- HWND hWnd = ::AfxGetApp()->m_pMainWnd->GetSafeHwnd();
- ::SetWindowText(hWnd, lpStr);
- }
- void CDlg4::OnBnClickedSearchfile()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(TRUE);
- BROWSEINFO bi;
- TCHAR szDispName[MAX_PATH + 1];
- memset(&bi, 0, sizeof(BROWSEINFO));
- bi.hwndOwner = m_hWnd;
- bi.pszDisplayName = szDispName;
- bi.ulFlags = BIF_BROWSEINCLUDEFILES + BIF_EDITBOX;
- bi.lpszTitle = _T("Please select the folder u want to search:");
- if(ITEMIDLIST *iil = SHBrowseForFolder(&bi))
- {
- SHGetPathFromIDList(iil, szDispName);
- if (!SearchFile(_T("War3.exe"), szDispName, m_strPath.GetBuffer(MAX_PATH), ShowPath))
- {
- m_strPath = _T("");
- MessageBox(_T("no find"));
- }
- UpdateData(FALSE);
- }
- }