Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing a system-like cursor, top-most, anywhere
    text
    copied!<p>I need to draw a system-like cursor that I simply can control the position of. In other words, I need to draw a transparent image that looks just like the system cursor and I need it to be rendered on top of all other windows. I've tried multiple approaches, but they all seem to have some downside.</p> <p>I've figured out that I can load the cursor image by using LoadImage() and passing the resource OCR_NORMAL and casting it into a HBITMAP.</p> <pre><code>HICON NormalCursor = (HICON)LoadImage(NULL, MAKEINTRESOURCE(OCR_NORMAL), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED); </code></pre> <p>Then getting the "desktop" HDC</p> <pre><code>hDC = GetDC(NULL); </code></pre> <p>Then I can try to draw it using DrawIconEx()</p> <pre><code>DrawIconEx(hDC, (int)x, 0, NormalCursor, 0, 0, NULL, NULL, DI_DEFAULTSIZE | DI_NORMAL); </code></pre> <p>The DI_NORMAL flag is supposed to combine the DI_IMAGE &amp; DI_MASK flags giving me a transparent image/icon/cursor, but this is my result on the desktop:</p> <p><a href="http://i55.tinypic.com/2v3q001.png" rel="nofollow noreferrer">Image</a></p> <p>Not to mention that if it moves it creates trails.</p> <p>By <strong>making a transparent window</strong> using SetLayeredWindowAttributes like this:</p> <pre><code>SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 50, LWA_COLORKEY); </code></pre> <p>And having the background color of my window to be black, I can remove the background from the window. But due to doing alpha based on a color I get ugly black pixels around my cursor icon.</p> <p>Can I make the background of a window transparent in some other way than using a color mask?</p> <p>How do I draw a transparent cursor on top of all windows properly?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload