Adding controls when DLL hooking
I've DLL hooked calc.exe, and I'm trying to created a new button, but it's not working. CreateWindowEx() returns a handle, but I can't see anything. When I check Spy++, I can't find the button window anywhere. Does anyone know what's going on?
Code:
BOOL WINAPI DllMain(HANDLE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
if (fdwReason==DLL_PROCESS_ATTACH)
{
HWND hFind=NULL;
DWORD thisProcessId=GetCurrentProcessId();
DWORD wndProcessId;
do
{
hFind=FindWindowEx(NULL, hFind,NULL, "Calculator");
GetWindowThreadProcessId(hFind, &wndProcessId);
} while (thisProcessId!=wndProcessId);
lpCalculator=(WNDPROC)SetWindowLong(hFind, GWL_WNDPROC, (LONG)WndProc);
RECT rc;
GetWindowRect(hFind,&rc);
MoveWindow(hFind,rc.left,rc.top,(rc.right-rc.left)+500, rc.bottom-rc.top,TRUE);
hButton=CreateWindowEx(WS_EX_CLIENTEDGE,"BUTTON","YO",
WS_CHILD| WS_VISIBLE|BS_DEFPUSHBUTTON,
500,5,100,100,hFind,(HMENU)1020,
(HINSTANCE)GetWindowLong(hFind, GWL_HINSTANCE),NULL);
if (!hButton)
{
MessageBox(NULL,"couldn't create button","yo", MB_OK);
}
else
{
MessageBox(NULL,"created button","yo", MB_OK);
ShowWindow(hButton,TRUE);
}
bButtonVisible=TRUE;
}
return TRUE;
}
It is very fustrating!