Click to See Complete Forum and Search --> : Drawing on screen


hawkagent
December 26th, 2008, 07:56 PM
I'm trying to draw shapes and text on the monitor screen, like on the top level, over all applications. Can anyone tell me where to start?

marceln
December 26th, 2008, 08:02 PM
You could use GetDesktopWindow (http://msdn.microsoft.com/en-us/library/ms633504%28VS.85%29.aspx) to get the Desktop's handle and then get the DC for the handle and paint on it.

TheCPUWizard
December 26th, 2008, 08:04 PM
You could use GetDesktopWindow (http://msdn.microsoft.com/en-us/library/ms633504%28VS.85%29.aspx) to get the Desktop's handle and then get the DC for the handle and paint on it.

Woundn't that draw UNDER all application level windows????

ps: I prefer a grease pencil or dry-erase marker for drawing on the screen, as long as it is a true glass screen...it really sdcrews up a laptop or other flatpanel. :eek::eek::D.

marceln
December 26th, 2008, 08:25 PM
Woundn't that draw UNDER all application level windows????

yes, you're right. I misread the first post :).

hawkagent
December 26th, 2008, 08:31 PM
I tried this

CPaintDC dc1(GetDesktopWindow());
CPoint PtLine[] = { CPoint( 50, 50), CPoint(600, 50) };
dc1.MoveTo(PtLine[0]);
dc1.LineTo(PtLine[1]);


Doesn't work, any help? :)

hawkagent
December 26th, 2008, 10:57 PM
Ok never mind the post above, I managed to do it in C# =)

private void Form1_Deactivate(object sender, EventArgs e)
{
Graphics dc = this.CreateGraphics();
Pen BluePen = new Pen(Color.Blue, 3);
Pen RedPen = new Pen(Color.Red, 2);
int hwn = FindWindow(null, "Calculator");
Graphics G = Graphics.FromHwnd((IntPtr)hwn);
Graphics g = Graphics.FromHdc(GetDC(IntPtr.Zero));
while (true)
{

g.DrawRectangle(BluePen, 0, 0, 50, 50);
G.DrawEllipse(RedPen, 0, 50, 80, 60);
dc.DrawRectangle(BluePen, 0, 0, 50, 50);

dc.DrawEllipse(RedPen, 0, 50, 80, 60);
System.Threading.Thread.Sleep(100);
}
}


Now doing this infinite loop in the deactivate event is not a good choice, because it get stuck when I try to close the window. How can I keep drawing my shapes without my application getting stuck? What event to use? Or anything else?

EDIT: Solved, used timers

codecX
December 31st, 2008, 06:58 AM
I recommend using a modeless dialog:
- Topmost must be" true"
- Style must be "Pop up"

Note: You can hide titlebar or use regions and hide/mask other area of the window except shapes/texts
And use GetForegroundWindow to find current active window.


CMyDialog* pDialog;

void CMyWnd::OnSomeAction()
{
pDialog = new CMyDialog();

if(pDialog != NULL)
{

CWnd hWnd = GetForegroundWindow( );

pDialog->Create(IDD_MYDIALOG, hWnd);

pDialog->ShowWindow(SW_SHOW);

hWnd.SetFocus();
// Or--> hWnd.SetActiveWindow

}
}