Hi ,

Is there a way that I can draw lines or circles etcc..(graphics) onto windows screen?

Please let me know.Sample code would greatly help.

you can't draw directly onto the desktop. You first have to create a windows gui program and draw on its canvas.

#include <iostream>
#include <windows.h>

using namespace std;

int main(int argc, char* argv[]) 
HWND p = FindWindow("ProgMan", NULL);
HWND s = FindWindowEx(p, NULL, "SHELLDLL_DefView", NULL);
HWND dtw = FindWindowEx(s, NULL, "SysListView32", NULL);
HDC hdc = GetDC(dtw);
if(hdc != NULL) 
TextOut(hdc, 10, 10, "hello world", 12);

return 0;

RECT r = {0, 0, 300, 300};
ReleaseDC(dtw, hdc);
return 0;

The code above prints text in the deskdop background (beneath the icons).Could you please help me in modifying the code to draw shapes onto the fore-ground like animations.

HDC hdct;

hdct = CreateDC("DISPLAY", NULL, NULL, NULL);

for(int i=0;i<100;i++)

TextOut(hdct, 200+i*2, 600, "hello world", 12);

this code puts the text in the foreground but when I have kept in the loop the previous draws are there they don't get erased.It does not appear that the object is moving but badly drawn.Any suggestion on how to erase previous draws and how to draw shapes?(Someone say something!)

But one question still remains how to erase the previous draws.What I observed is when a new window is dragged onto the drawn area it acts as a refreshing thing and it gets erased.Any function in GDI which can erase the previous draws?

This article has been dead for over six months. Start a new discussion instead.