Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw to screen in c++?

How would I draw something on the screen ? not the console window but the entire screen, preferably with the console minimised.

Also, would it show up on a printscreen ? What I want to do is create something like a layer on top of the screen that only me and my aplication are aware of yet still be able to use aplications as usual.

Here's an example: Let's say I want 2 yellow squares 5 by 5 pixels in size appearing in the center of the screen on top of all the other applications, unclickable and invisible to a printscreen.

[Edit]

I forgot to mention that I'm using Visual Studio 2010 on Windows XP.

like image 224
Kesarion Avatar asked Jun 05 '10 18:06

Kesarion


People also ask

How do I draw directly on my screen?

Epic Pen is a free program for the Windows operating system that lets you draw directly on your computer screen. The main purpose of the application is the use during presentations as you can make use of it to annotate, highlight or add to the presentation easily using the program.

How do you draw a graphic pixel?

Syntax : void putpixel(int x, int y, int color); where, (x, y) is the location at which pixel is to be put , and color specifies the color of the pixel. Explanation : A RED color pixel at (50, 40) can be drawn by using putpixel(50, 40, RED).


1 Answers

in windows you can use the GetDC-function. just a minimalistic example:

#include <Windows.h>
#include <iostream>

void drawRect(){
    HDC screenDC = ::GetDC(0);
    ::Rectangle(screenDC, 200, 200, 300, 300);
::ReleaseDC(0, screenDC);
}
int main(void){
    char c;
    std::cin >> c;
    if (c == 'd') drawRect();
    std::cin >> c;
    return 0;
}

but since Windows Vista it is very slow

like image 129
OlimilOops Avatar answered Oct 02 '22 17:10

OlimilOops