吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2110|回复: 5
收起左侧

[C&C++ 原创] C++实现拖拽补丁源码

[复制链接]
oxygen1a1 发表于 2022-9-24 17:45
MFC MFC MFC !!实现都封装在成员函数了
一张图怎么用还不够明显吗?
图片
QQ截图20220924163109.png

github:https://github.com/Oxygen1a1/DragPatch
关键代码:

[C++] 纯文本查看 复制代码
void C内存驱动注入过TPDlg::OnTimer(UINT_PTR nIDEvent)
{

	switch (nIDEvent) {
	case DRAGTIMER: {
		POINT point;
		GetCursorPos(&point);
		DWORD32 dwPid;
		char* szFileName = (char*)malloc(0x1000);
		GetCursorProcess(point, &dwPid, szFileName, 0x1000);
		CString csTest;
		csTest.Format("%d %s", dwPid, szFileName);
		m_StaticTest.SetWindowTextA(csTest);
		m_dwPid = dwPid;
		memcpy(m_szFileName, szFileName, strlen(szFileName));
		break;
	}
	}
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CDialogEx::OnTimer(nIDEvent);
}

void C内存驱动注入过TPDlg::GetCursorProcess(POINT point, OUT DWORD32* dwPid, OUT char* szFileName, int size)
{
	HWND hWnd = ::WindowFromPoint(point);
	DWORD _dwPid;
	GetWindowThreadProcessId(hWnd, &_dwPid);
	*dwPid = _dwPid;
	HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, _dwPid);
	::GetProcessImageFileName(hProcess, szFileName, size);

}

void C内存驱动注入过TPDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CRect   rectPic;

	POINT   ptPut = point;


	//获取图像控件对象边框
	GetDlgItem(IDC_BITMAP)->GetWindowRect(rectPic);

	ClientToScreen(&ptPut);//转换成x y 全局屏幕坐标

	if (rectPic.PtInRect(ptPut))//如果在控件围成的矩形中

	{
		SetTimer(DRAGTIMER, 50, 0);
		CBitmap     bitmapTemp, * pOldBitmap;

		//获取DC
		CDC* pDC = GetDlgItem(IDC_BITMAP)->GetDC(),

			* pMemDC = new CDC;

		//创建位图内存   

		bitmapTemp.CreateCompatibleBitmap(pDC, rectPic.Width(), rectPic.Height());

		pMemDC->CreateCompatibleDC(pDC);

		pOldBitmap = pMemDC->SelectObject(&bitmapTemp);

		pMemDC->BitBlt(0, 0, rectPic.Width(), rectPic.Height(), pDC, 0, 0, SRCCOPY);

		pMemDC->SelectObject(pOldBitmap);

		delete  pMemDC;

		ReleaseDC(pDC);

		m_bIsLButtonDown = TRUE;

		m_ptOffset.x = ptPut.x - rectPic.left;

		m_ptOffset.y = ptPut.y - rectPic.top;

		m_imgDrag.DeleteImageList();

		m_imgDrag.Create(rectPic.Width(), rectPic.Height(), ILC_COLOR32 | ILC_MASK, 0, 1);

		m_imgDrag.Add(&bitmapTemp, RGB(0, 0, 0));

		m_imgDrag.BeginDrag(0, m_ptOffset);


		m_imgDrag.DragEnter(NULL, ptPut);

		SetCapture();

	}

	CDialogEx::OnLButtonDown(nFlags, point);
}


void C内存驱动注入过TPDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CRect rect;
	GetClientRect(&rect);

	if (m_bIsLButtonDown)

	{

		CRect   rectPic;

		CWnd* pPic = GetDlgItem(IDC_BITMAP);

		ScreenToClient(&m_ptMove);

		pPic->GetWindowRect(rectPic);

		//pPic->MoveWindow(m_ptMove.x - m_ptOffset.x, m_ptMove.y - m_ptOffset.y, rectPic.Width(), rectPic.Height());

		m_bIsLButtonDown = FALSE;

		CImageList::DragLeave(this);

		CImageList::EndDrag();

		ReleaseCapture();

		pPic->Invalidate();
		
		KillTimer(DRAGTIMER);

		char* szInfo = (char*)malloc(0x1000);
		szInfo[0] = '\0';

		sprintf_s(szInfo,0x1000,"ProcessId:%d\nFileName:%s", m_dwPid, m_szFileName);

		MessageBox(szInfo, "Tips", MB_OK| MB_ICONINFORMATION);
	}


	CDialogEx::OnLButtonUp(nFlags, point);
}


void C内存驱动注入过TPDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	if (m_bIsLButtonDown)

	{

		CRect       rtClient, rtPicture;
		CPoint tempPoint;
		GetClientRect(rtClient);

		m_ptMove = point;

		GetDlgItem(IDC_BITMAP)->GetWindowRect(rtPicture);

		ClientToScreen(&rtClient);

		ClientToScreen(&m_ptMove);


		CImageList::DragMove(m_ptMove);

	}

	CDialogEx::OnMouseMove(nFlags, point);
}

免费评分

参与人数 4吾爱币 +10 热心值 +4 收起 理由
笙若 + 1 + 1 谢谢@Thanks!
5151diy + 1 + 1 我很赞同!
连晋 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

CXC303 发表于 2022-9-25 09:34
感谢分享
roa 发表于 2022-9-25 12:14
aspllh 发表于 2022-9-25 23:25
5151diy 发表于 2022-9-26 21:02
感谢分享,先收藏
piazini 发表于 2023-1-30 11:48
标题带上MFC字样,可能会更受欢迎
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 00:30

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表