Reputation: 175
How come when I call the SetPixel function to set a pixel in iTunes, it does shows me the pixel in that specific application (like it should), whilst when calling the same function for Windows Media Player it doesn't show at all. Also, this function doesn't seem to work for fullscreen windows either. Why this great diversity? Any explanation would be greatly appreciated. Thanks in advance.
Upvotes: 0
Views: 2418
Reputation: 61900
As mentioned, it's very easy not to get the result you are expecting because it's not your window, and you ultimately have no control over what it does!
Two things you could do (one obviously being better than the other) are:
Use GetDC (NULL)
to get a handle to the screen device context. Use ClientToScreen
to calculate the position of your pixel on the screen. Call SetPixel
with that handle. This will get cleared fairly quickly, though.
Create your own top-level, popup, transparent (to messages), layered window with an appropriate colour key. Use ClientToScreen
to calculate the position of the screen, and possibly ScreenToClient
to make sure it goes properly onto your window (which should theoretically have the same client dimensions as the screen). Draw the pixel onto your window and you will be in control of when it leaves.
If using the second, your extended window style should be:
WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED
and your normal window style should be:
WS_POPUP | WS_VISIBLE
The dimensions can be found using GetSystemMetrics
with the values SM_CXSCREEN
and SM_CYSCREEN
.
To set the colour key, use SetLayeredWindowAttributes
:
SetLayeredWindowAttributes (hwnd, RGB (red, green, blue), 0, LWA_COLORKEY);
Where red
, green
, and blue
make up the background colour of your window, and should never appear as an actual colour. That way your background will not be drawn, giving an unnoticeable difference to the user, but when anything is drawn, it will show up.
Upvotes: 3
Reputation: 28091
Drawing on a control should be done in the WM_PAINT handler of the control. As it is not your control, you don't have direct access to the message loop. This means, if the control is Invalidated, your pixel will be gone.
Applications that play video or update their content often, will Invalidate the control each frame. Which forces the control to be updated very quick.
I think a transparent overlay window is the only way here. Unless you can hook into the message loop and react to the WM_PAINT handler after the control has processed it...
Upvotes: 1