Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GDI Drawing to desktop

Posted on 2006-06-22
4
Medium Priority
?
3,737 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 2000 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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

610 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