赞
踩
内容参考于:易道云信息技术研究院VIP课
上一个内容:窗口化助手显示与大小调整
码云地址(游戏窗口化助手 分支):https://gitee.com/dye_your_fingers/sro_-ex.git
码云版本号:e85c0fc8b85895c8c2d3417ec3c75bcad8e7c41d
代码下载地址,在 SRO_EX 目录下,文件名为:SRO_Ex-窗口化助手与游戏窗口同步移动.zip
链接:https://pan.baidu.com/s/1W-JpUcGOWbSJmMdmtMzYZg
提取码:q9n5
--来自百度网盘超级会员V4的分享
HOOK引擎,文件名为:黑兔sdk.zip
链接:https://pan.baidu.com/s/1IB-Zs6hi3yU8LC2f-8hIEw
提取码:78h8
--来自百度网盘超级会员V4的分享
以 窗口化助手显示与大小调整 它的代码为基础进行修改
效果窗口化助手可以跟游戏窗口的移动而移动,实现这个东西在没有游戏源代码的情况下,实现起来比较好的方式是做个钩子,在钩子里面去做这个事情
CHelper.h文件的修改:新加 HideGame函数、hookGameWnd变量
- #pragma once
- #include "afxdialogex.h"
- #include "resource.h"
-
- // CHelperUI 对话框
-
- class CHelperUI : public CDialogEx
- {
- DECLARE_DYNAMIC(CHelperUI)
-
- public:
- CHelperUI(CWnd* pParent = nullptr); // 标准构造函数
- virtual ~CHelperUI();
-
- // 对话框数据
- #ifdef AFX_DESIGN_TIME
- enum { IDD = IDD_HELPER };
- #endif
-
- protected:
- virtual BOOL OnInitDialog();
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
-
- DECLARE_MESSAGE_MAP()
- public:
- afx_msg void OnBnClickedOk();
- // 血量条
- CProgressCtrl HPBar;
- // 魔法条
- CProgressCtrl MPBar;
- // 怒气条
- CProgressCtrl RageBar;
- // 升级经验值条
- CProgressCtrl ExBar;
-
- HHOOK hookGameWnd;
- bool GameShow = true;
- // 游戏句柄
- HWND hwndGame{};
- int helper_Width;
- void Init();
- void MoveHelper();
- void ShowData();
- void Show();
- afx_msg void OnBnClickedOk2();
- afx_msg void OnClose();
- void HideGame();
- };
CHelper.cpp文件的修改:新加 HideGame函数、CallWndProc函数,修改了 Init函数
- // CHelperUI.cpp: 实现文件
- //
-
- #include "pch.h"
- #include "CHelperUI.h"
- #include "afxdialogex.h"
- #include "extern_all.h"
-
- LRESULT _stdcall CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
- if (nCode == 0) {
- // 这里接收到的不只有游戏窗口的消息,还有我们的窗口消息
- // 所以要排除掉我们的窗口
- PCWPSTRUCT tmp = (PCWPSTRUCT)lParam;
- // 判断当前触发消息的窗口句柄是不是我们的游戏窗口句柄
- if (tmp->hwnd == _ui_helper->hwndGame) {
- // 拦截移动窗口消息
- if (tmp->message == WM_MOVE) {
- // 移动我们的窗口
- _ui_helper->MoveHelper();
- }
- if (tmp->message == WM_CLOSE) {
- // 游戏窗口右上角的X关闭按钮屏蔽掉了,这里我们给它处理一下
- // 让它点击之后可以隐藏游戏窗口并且显示我们的窗口
- /**
- _ui_helper->HideGame(); 里执行的代码如下面的两行
- this->ShowWindow(TRUE);
- ::ShowWindow(hwndGame, GameShow = false);
- */
- _ui_helper->HideGame();
- }
-
- }
- }
- return CallNextHookEx(_ui_helper->hookGameWnd, nCode, wParam, lParam);
- }
-
- void _stdcall TimeProcHelper(HWND, UINT, UINT_PTR, DWORD) {
- if (_ui_helper)_ui_helper->ShowData();
- }
-
- //获取程序当前所在显示器的分辨率大小,可以动态的获取程序所在显示器的分辨率
- SIZE GetScreenResolution(HWND hWnd) {
- SIZE size{};
- if (!hWnd)
- return size;
-
- //MONITOR_DEFAULTTONEAREST 返回值是最接近该点的屏幕句柄
- //MONITOR_DEFAULTTOPRIMARY 返回值是主屏幕的句柄
- //如果其中一个屏幕包含该点,则返回值是该屏幕的HMONITOR句柄。如果没有一个屏幕包含该点,则返回值取决于dwFlags的值
- HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
- MONITORINFOEX miex;
- miex.cbSize = sizeof(miex);
- if (!GetMonitorInfo(hMonitor, &miex))
- return size;
-
- DEVMODE dm;
- dm.dmSize = sizeof(dm);
- dm.dmDriverExtra = 0;
-
- //ENUM_CURRENT_SETTINGS 检索显示设备的当前设置
- //ENUM_REGISTRY_SETTINGS 检索当前存储在注册表中的显示设备的设置
- if (!EnumDisplaySettings(miex.szDevice, ENUM_CURRENT_SETTINGS, &dm))
- return size;
-
- size.cx = dm.dmPelsWidth;
- size.cy = dm.dmPelsHeight;
- return size;
- }
-
- IMPLEMENT_DYNAMIC(CHelperUI, CDialogEx)
-
- CHelperUI::CHelperUI(CWnd* pParent /*=nullptr*/)
- : CDialogEx(IDD_HELPER, pParent)
- {
-
- }
-
- CHelperUI::~CHelperUI()
- {
- }
-
- BOOL CHelperUI::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- this->SetBackgroundColor(RGB(255, 255, 255));
- HPBar.SetBkColor(RGB(0 ,0, 0));
- MPBar.SetBkColor(RGB(0 ,0, 0));
- RageBar.SetBkColor(RGB(0 ,0, 0));
- ExBar.SetBkColor(RGB(0 ,0, 0));
-
-
- HPBar.SetBarColor(RGB(255 ,0, 0));
- MPBar.SetBarColor(RGB(0x0, 0x0, 0x99));
- RageBar.SetBarColor(RGB(0x66, 0x0, 0x66));
- ExBar.SetBarColor(RGB(0x00, 0xFF, 0xCC));
-
- HPBar.SetRange(0, 999);
- MPBar.SetRange(0, 1000);
- RageBar.SetRange(0, 5);
- ExBar.SetRange(0, 1000);
-
- //HPBar.SetPos(50);
- //MPBar.SetPos(50);
- //RageBar.SetPos(50);
- //ExBar.SetPos(50);
-
- ::SetTimer(this->m_hWnd, 0x100002, 100, TimeProcHelper);
-
- return TRUE;
- }
-
- void CHelperUI::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_PRO_HP, HPBar);
- DDX_Control(pDX, IDC_PRO_MP, MPBar);
- DDX_Control(pDX, IDC_PRO_RAGE, RageBar);
- DDX_Control(pDX, IDC_PRO_RAGE2, ExBar);
- }
-
-
- BEGIN_MESSAGE_MAP(CHelperUI, CDialogEx)
- ON_BN_CLICKED(IDOK, &CHelperUI::OnBnClickedOk)
- ON_BN_CLICKED(IDOK2, &CHelperUI::OnBnClickedOk2)
- ON_WM_CLOSE()
- END_MESSAGE_MAP()
-
-
- // CHelperUI 消息处理程序
-
-
- void CHelperUI::OnBnClickedOk()
- {
- // TODO: 在此添加控件通知处理程序代码
- // CDialogEx::OnOK();
- //CString tmp;
- //tmp.Format(L"%d", _pgamebase->SRO_Player->MapId);
- //AfxMessageBox(tmp);
- //
- //CString city;
- //city.Format(L"%s", _pgamebase->SRO_Res->ReadTitle(tmp.GetBuffer())->wcstr());
- //AfxMessageBox(city);
- _ui->UIShow();
- }
-
- void CHelperUI::Init()
- {
- if (hwndGame) return;
- wchar_t buff[0xFF]{};
- // 获取主窗口句柄
- HWND _hwnd = ::GetActiveWindow();
- // 获取窗口标题
- ::GetWindowText(_hwnd, buff, 0xFF);
- CString _title = buff;
- if (_title == L"SRO_CLIENT") {
- hwndGame = _hwnd;
- CRect rect_me;
- // 获取当前窗口句柄
- GetWindowRect(&rect_me);
- helper_Width = rect_me.Width();
- SetWindowsHook(WH_CALLWNDPROC, CallWndProc);
- }
- }
-
- void CHelperUI::MoveHelper()
- {
- if (hwndGame) {
- CRect rect;
- // 获取游戏窗口(主窗口)样式
- ::GetWindowRect(hwndGame, &rect);
- int helper_left = rect.left + rect.Width();
- SIZE windowSize = GetScreenResolution(this->m_hWnd);
- if ((helper_left + helper_Width) > windowSize.cx) {
- helper_left -= helper_Width;
- }
- // 设置窗口大小
- ::MoveWindow(this->m_hWnd, helper_left, rect.top, helper_Width, rect.Height(), TRUE);
- }
- }
-
- void CHelperUI::ShowData()
- {
- CString tmp;
- CString city;
-
- auto _player = _pgamebase->SRO_Player;
- if (_player) {
- tmp.Format(L"%s Lv %d", _player->Name.wcstrByName(), _player->Lv);
- this->SetWindowText(tmp);
- float hpStep = _player->HP * 1000;
- hpStep = hpStep / _player->MaxHP;
- HPBar.SetPos(hpStep);
-
- float mpStep = _player->MP * 1000;
- mpStep = mpStep / _player->MaxMP;
- MPBar.SetPos(mpStep);
- RageBar.SetPos(_player->Rage);
-
- unsigned max_exp = _pgamebase->SRO_Core->GetLvMaxExp(_player->Lv)->Exp;
- float expSetp = _player->Exp * 1000;
- expSetp = expSetp / max_exp;
- ExBar.SetPos(expSetp);
-
- tmp.Format(L"%.1f %.1f %.1f", _player->x, _player->h, _player->y);
- GetDlgItem(IDC_STATIC_CORD)->SetWindowText(tmp);
-
- tmp.Format(L"%d", _pgamebase->SRO_Player->MapId);
- city.Format(L"%s", _pgamebase->SRO_Res->ReadTitle(tmp.GetBuffer())->wcstr());
- GetDlgItem(IDC_STATIC_MAP)->SetWindowText(city);
-
- }
- }
-
- void CHelperUI::Show()
- {
- MoveHelper();
- this->ShowWindow(TRUE);
- }
-
-
- void CHelperUI::OnBnClickedOk2()
- {
- if (hwndGame) {
- ::ShowWindow(hwndGame, GameShow = !GameShow);
- }
- }
-
-
- void CHelperUI::OnClose()
- {
- if (hwndGame) {
- ::ShowWindow(hwndGame, GameShow = true);
- this->ShowWindow(FALSE);
- }
- }
-
- void CHelperUI::HideGame()
- {
- this->ShowWindow(TRUE);
- ::ShowWindow(hwndGame, GameShow = false);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。