SetWindowsHookEx 测试

2018-7-5 流沙 C/C++


LRESULT CALLBACK GameProc(          
	int code,
    WPARAM wParam,
    LPARAM lParam
)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	
	if((wParam == VK_HOME)&&(lParam&(1<<31)))
	{
		//AfxMessageBox("www.gyarmy.com");
		//展示对话框
		if(m_dialog == NULL)
		{
			m_dialog = new  CWGDialog();
			m_dialog->Create(IDD_DLG_MAIN);
		}
		m_dialog->ShowWindow(SW_SHOW);
		
		//解决销毁的bug
	}

	return CallNextHookEx(0,code,wParam,lParam);
}




#define GameCaption "test2018070301"

//钩子函数
void SetHook()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	HWND gameh = FindWindow(NULL,GameCaption);
	if(gameh==0)
	{
		AfxMessageBox("没有找到游戏");
	}

	DWORD tid = GetWindowThreadProcessId(gameh,NULL);

	//安装钩子
	::SetWindowsHookEx(WH_KEYBOARD,&GameProc,GetModuleHandle("GameDll.dll"),tid);
}


发表评论:

Powered by 流沙团