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.

Recommended Answers

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

Jump to Post

No functions -- to erase just redraw with same colors as the background.

Jump to Post

All 9 Replies

Here is one source

Hi

Thanks for the resource.But that is not what I am looking for.I want to draw directly onto the desktop.

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

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);
}
else
 {
cout<<"error"<<endl;

return 0;
}

RECT r = {0, 0, 300, 300};
RedrawWindow(dtw, &r, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW );
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?

No functions -- to erase just redraw with same colors as the background.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.