#include <stdio.h>
#include <stdlib.h>
#include<Windows.h>
int aa(HWND hwd,int msg,int wp,int lp);
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) ;
HWND GetMainWindow();
int ab=0,bb=0;
void main()
{
int (*pFun)();
int WorkAddress=0;
pFun=aa;
WorkAddress=(int)(*pFun);
bb=RegisterWindowMessage("sb");
ab=SetWindowLong(GetMainWindow(),GWL_WNDPROC,(LONG)(*pFun));
SendMessage(GetMainWindow(),888,20,10);
getchar();
return ;
}
int aa(HWND hwd,int msg,int wp,int lp)
{
if(msg==888)
{
printf("sb消息成功");
getchar();
}
return(CallWindowProc((WNDPROC)ab, hwd, msg, wp, lp));
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD dwCurProcessId = *((DWORD*)lParam);
DWORD dwProcessId = 0;
GetWindowThreadProcessId(hwnd, &dwProcessId);
if(dwProcessId == dwCurProcessId && GetParent(hwnd) == NULL)
{
*((HWND *)lParam) = hwnd;
return FALSE;
}
return TRUE;
}
HWND GetMainWindow()
{
DWORD dwCurrentProcessId = GetCurrentProcessId();
if(!EnumWindows(EnumWindowsProc, (LPARAM)&dwCurrentProcessId))
{
return (HWND)dwCurrentProcessId;
}
return NULL;
}
为什么不会printf();
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课