• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[C#] OSD function. I need some assistance.

Question

Vorenus    0

using System.Runtime.InteropServices; // since we are using COM..

...

[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);

...

IntPtr hdc = GetDCEx(GetDesktopWindow(), IntPtr.Zero, 1027);
using (Graphics g = Graphics.FromHdc(hdc))
{
	  g.FillEllipse(Brushes.Red, 0, 0, 400, 400);
}

With this code it succesfully draw an OSD (on screen display) in a red circle. However, when another window appears over it it erases the pixels.

Is there a better way to draw OSD's? If not, how would I go about fixing this?

Thanks.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
neowin_hipster    0
However, when another window appears over it it erases the pixels.

Aah, yet another programmer has discovered the stupidity in windows. Not only are you, the coder, responsible for drawing what you want to draw, you are responsible for all paint events. Normally the .net controls handle this for you.

I can't remember exactly what to do at this moment, but you want to make sure that you trap the WM_PAINT messages or create an appropriate delegate.

You may wish to use .net's gdi+ functions for drawRectangle, but be warned they are not hardware accelerated.

There is no clean solution and everything is a hack. Luckily this will change with vista's new graphic framework (which is being backported to XP afaik) bringing windows into the present along with every other operating system.

Share this post


Link to post
Share on other sites
  • 0
Mordkanin    225

Well, I hated using the unmanaged crap and came up with a way to do it with a form once.

Make a form with a background of a specific color, for example, red. Make a 1px by 1px label that is red, and have it follow your mouse around the form. Use one of the events on the form that monitors the mouse moving over it. Hover? Move? Whatever.

Make the transparency key red. put it on top, disable task bar, border, etc.

Make another label, but set the first one to the highest z-order. This new label will hold the text you want to display. (Or you can override OnPaint and draw on the new form that way. It doesn't matter.)

There we go. You have an OSD, and you can still click through the text, thanks to the 1x1 transparent label.

You can add a timer, position it how you want, autosize, whatever.

Share this post


Link to post
Share on other sites
  • 0
Vorenus    0

Well, I hated using the unmanaged crap and came up with a way to do it with a form once.

Make a form with a background of a specific color, for example, red. Make a 1px by 1px label that is red, and have it follow your mouse around the form. Use one of the events on the form that monitors the mouse moving over it. Hover? Move? Whatever.

Make the transparency key red. put it on top, disable task bar, border, etc.

Make another label, but set the first one to the highest z-order. This new label will hold the text you want to display. (Or you can override OnPaint and draw on the new form that way. It doesn't matter.)

There we go. You have an OSD, and you can still click through the text, thanks to the 1x1 transparent label.

You can add a timer, position it how you want, autosize, whatever.

Thanks this seems to work. I'll be using this until I find a more elegant way of doing things.

Thanks,

VB Guy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.