I'm trying to execute an action when a pixel changes in a window by using SetWindowsHookEx
. I can successfully recieve Windows messages, but most messages are called while no screen updates occur, and some messages are called more than once on one pixel.
// WH_GETMESSAGE doesn't call the callback for some reason...
SetWindowsHookEx(WH_CALLWNDPROC, hhookSysMsg, hinstDLL, GetWindowThreadProcessId(hwnd, NULL));
I tried listening for WM_PAINT
, WM_NCPAINT
, and WM_ERASEBKGND
, but for some reason they don't fire every time - for example, in Notepad, it does not fire when the scrollbar colors change (for example when hovering over them with the cursor) or changing the text itself.
switch (msg->message)
{
// doesn't catch all screen updates!
case WM_PAINT:
case WM_NCPAINT:
case WM_ERASEBKGND:
// Bit-blit the screen to a file/process the screen/etc.
...
default:
break;
}
Can someone help me out with this? If there's no concrete event that runs when a pixel is changed within a window, is there a list of events that I can do a switch-case expression on?
CodePudding user response:
There is no message that notifies a client about the change of a pixel's color. This wouldn't really be useful either: Clients are in charge of drawing to the window's (client) area. If they need to know when a pixel changes color, it can monitor the state itself.
If you need to monitor the change of a pixel's color in a foreign process, the system won't help you with that. You'd be left with hooking all API calls that potentially change the color of a pixel, and keep state information around to determine a change in state.