C++实现拖拽补丁源码
MFC MFC MFC !!实现都封装在成员函数了一张图怎么用还不够明显吗?
图片
github:https://github.com/Oxygen1a1/DragPatch
关键代码:
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);
deletepMemDC;
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';
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);
} 感谢分享 感谢楼主分享,顶贴 支持 虚心学习!!! 感谢分享,先收藏 标题带上MFC字样,可能会更受欢迎
页:
[1]