Solved

GDI Drawing to desktop

Posted on 2006-06-22
4
3,733 Views
Last Modified: 2013-11-17
Hi,
Im new to GDI and I just want to draw a rectagle on the Windows Desktop to get started.  The code I have so far to do this when the user click a button is:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    HPEN hpen, hpenOld;
    HBRUSH hbrush, hbrushOld;

    HDC hdc = GetDesktopWindow();

    hpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
    hbrush = CreateSolidBrush(RGB(0, 0, 255));

    // Select the new pen and brush then draw a rectangle.
    hpenOld = SelectObject(hdc, hpen);
    hbrushOld = SelectObject(hdc, hbrush);
    Rectangle(hdc, 0,0, 700,700);

    SelectObject(hdc, hpenOld);
    DeleteObject(hpen);
    SelectObject(hdc, hbrushOld);
    DeleteObject(hbrush);
}


This doesnt work, and I assume it's because I'm not getting the windows desktop DC when I call:
HDC hdc = GetDesktopWindow();

can someone tell me how I should be doing this?
thanks!
0
Comment
Question by:blackfrancis75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
Jase-Coder earned 500 total points
ID: 16958903
Hi it is working, but the desktop window keeps repainting itself so your rectangle gets deleted. If you put your code in a timer with a interval of 10 you will see that you are painting on the desktop.

I think you must create a hook to the desktop and modify the WM_PAINT message handler
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16958934
you can also get a handle to the desktop by doing:

hdc = CreateDC(NULL,NULL,NULL,NULL);
GetClientRect (GetDesktopWindow(), &rect) ;
DrawText (hdc, szStartMsg, -1, &rect,DT_SINGLELINE |   DT_CENTER | DT_VCENTER) ;
DeleteDC (hdc);
return 0 ;

you code is fine just remember you must call your function once the desktop repaints itself
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 16960346
thanks! I have a basic understanding of Windows message handling; do you know any good sites that deal with this?
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16961922
the best site to use is the mircosoft msdn
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question