#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();
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!