⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wndproc.cpp

📁 使非MFC窗口程序的窗口回调过程成为C++类的成员函数。
💻 CPP
字号:
#include "stdafx.h"
#include "wndproc.h"


static unsigned char g_hook[] =
{
	0x8B, 0x44, 0x24, 0x10,			//	mov         eax,dword ptr [esp+10h]
	0x8B, 0x4C, 0x24, 0x0C,			//	mov         ecx,dword ptr [esp+0Ch]
	0x8B, 0x54, 0x24, 0x08,			//	mov         edx,dword ptr [esp+8]
	0x50,							//	push        eax
	0x8B, 0x44, 0x24, 0x08,			//	mov         eax,dword ptr [esp+8]
	0x51,							//	push        ecx
	0xB9, 0x00, 0x00, 0x00, 0x00,	//	mov         ecx,0 (类的this指针)
	0x52,							//	push        edx
	0x50,							//	push        eax
	0x51,							//	push		ecx
	0xE8, 0x00, 0x00, 0x00, 0x00,	//	call        CWndProc::WndProc
	0xC2, 0x10, 0x00				//	ret         10h
};


CWndProc::CWndProc()
{
	char	*p;
	LRESULT (CALLBACK CWndProc::*pfn)(HWND, UINT, WPARAM, LPARAM);

	CopyMemory(m_hook, g_hook, sizeof(g_hook));
	p = m_hook + 19;
	*((unsigned int *)p) = (unsigned int)this;

	pfn = WndProc;
	p = m_hook + 27;
	__asm
	{
		mov eax, pfn
		sub eax, 4
		mov edi, p
		sub eax, edi
		mov [edi], eax
	}
	m_pfnWndProc = (WNDPROC)&m_hook[0];
}


CWndProc::~CWndProc()
{
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -