I want to control other running programs directly by CallWindowProc
instead of SendMessage
, there is my code:
#define UNICODE
#include <Windows.h>
#include <stdio.h>
int main(){
HWND hwnd;
scanf("%d", &hwnd);
WNDPROC l = (WNDPROC)GetWindowLongPtr(hwnd, GWL_WNDPROC);
CallWindowProc(l, hwnd, WM_PAINT, NULL, NULL);
return GetLastError();
}
It is very simple but after I entered the obtained HWND of any other running window by spy++, it failed with return value 5. Which means Permission Denied
by GetLastError()
. I am confused. So I'll appreciate if someone can help me.
I'm using Visual studio 2010 express(C++) and I open the IDE in administrator mode. I'm also using Windows 7 and I have closed my UAC.
Thanks in advance.