Draw a line on screen

Hey guys, I was wondering if it is possible to draw a line on screeen.
I want to make a c++ program that would draw a line on my screen.
Nothing with graphics though.

Last edited on
If you're using Windows, you could use SetPixel.
https://msdn.microsoft.com/en-us/library/dd145078(v=vs.85).aspx
Can I use this function to draw an another screen ?
Like if I wanted to draw something on a game window that I haven't created.
Last edited on
Nothing with graphics though.

What are you looking for? Do you mean by using native C++ without external libraries?
http://stackoverflow.com/questions/35954645/how-to-draw-graphics-on-screen-without-using-any-framework-or-library -- sorry.
Last edited on
I'm playing a game and I want to draw lines for better aiming in the game.

It's been about 4 years since I dealt with WinApi, and I wish all the luck to you if you undertake that as a project.
WinApi Tutorials: ( http://www.winprog.org/tutorial/start.html )


I don't know if you have any experience yet in that direction, but here's several ways that you would draw to the root screen;

http://stackoverflow.com/questions/29091028/windows-api-write-to-screen-as-on-screen-display

http://stackoverflow.com/questions/1137155/why-does-windows-let-you-draw-on-the-whole-screen/1137194 - https://msdn.microsoft.com/en-us/library/windows/desktop/dd183490(v=vs.85).aspx

You might also simulate a line by http://www.codeguru.com/cpp/g-m/gdi/capturingimages/article.php/c11231/Capturing-Windows-Regardless-of-Their-ZOrder.htm . Just capture that image, blit to your window, then draw the line on your own window over that image. I'm pretty sure that after the second mouse-click you could specify that events should be passed to the next window down in the z-order, though I'm at my limit with skimming articles on google, so I'll leave looking that up to you ( https://www.google.com/search?q=pass+event+down+zorder+winapi ).

Good luck.
Last edited on
It appears that the option of drawing a tranparent window can be done in Qt. It's not really a common action, so there might be some issues with it being cross-platform and changes between versions of Qt (but that's also a caution with WinApi). Qt is much easier to learn than WinApi.

http://stackoverflow.com/questions/20000481/how-to-draw-over-everything-on-the-screen-using-qt

http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
Last edited on
I found a window using the FindWindowA() function.
Now is it possible to draw in that window using the SetPixel() function ?
Thanks.
I thought you just needed to draw a line above that window. Mouse-click A to Mouse-Click B. The window below the line isn't moving, right?

Yes you can get to the point where the line is a part of the lower window, but that's an advanced topic for WinApi called Hooks and/or Pipes. (Basically a method of injecting your own code into pre-existing code, carefull, I think a lot of antivirus programs look for this kind of behavior). I never got that deep into the API. I'm not even sure that it's possible if you don't have access to the game's inner workings (such as through their dll's)... but I think you should look into Hooks as they pertain to the API.

Hook Example:
https://www.unknowncheats.me/wiki/C%2B%2B:Make_Your_Own_DLL_Hack_-_2_-_WINAPI_Hooking

You might want to move this to the Windows forum to get more specific answers. [ At the top hit "edit topic" and then hit the drop-down menu in the forum section. Select "Windows Programming" and hit submit at the bottom of the page ]
Last edited on
Topic archived. No new replies allowed.