Solved

GDI Drawing to desktop

Posted on 2006-06-22
4
3,731 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to become programmer? 12 42
eclipse error 7 105
error when compiling my project in eclipse luna 30 448
installing and using WTP plugin eclipse MARS 3 124
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

829 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