I have this beloved old VB6 program that has been converted to a sleek new vb2005 program. It's name is "Color"
Color is a utility. It will sample pixels color anywhere on the desktop. It also gives me the x-y coordinates for a given location. It gives me the RGB color value in hex and decimal.
I find that I used Color to measure dimensions a lot. and that I'm always having to(x1-x1) and (y1-y2) and awful lot. It's natural that I'd like to use Color to measure anywhere on the desktop or more accurrately what I'm seeing in the moment. So tonight I've been playing with GDI+. It's no problem to:
dim g as graphics
g=me.creategraphics relates graphics to the creating form. I draw lines and that's not a problem except... it's clear I don't want the form instance for creating the graphics. I want something else. I actually want to be able to drawing measuring line anyplace on the screen.
What object doI use here or what approach do I take

GDI+ Questions
K-ERoL-K
Can you email me what you are trying to do Maybe i can re-write my code a bit to be more specific to what you are doing.
I am still getting all my emails to you rejected by your I.S.P. :(
SiJP
Stezza Stereotype
I don't think this method is ready for prime time at all. Events aren't firing on it and without events there little I can do.
Thomas Kionka
Dustin,
I'll write you via another vendor......
Also do you have MSN Messnger I do not think this is the approach to take.
I believe GDi+ is the way to go.
I think the design needs to be...
A transparent bit map over the entire screen. Use movetoEX and lineto in conjunction with that graphics screen.
I will write.
Tom Rizzo - MSFT
I got your new email. I replied to it... and still got this back.
Doesn't seem i'm able to email you.
I'm thinking that you won't be able to display a bitmap, without using a form to contain the bitmap. So it's kinda the same thing
Dustin.
Kieran Snyder
This is Great and I will have some nice improvements soon.
Don't mark this as closed yet.
m_tejas777
I will write to you. at an alternate address....
At any rate... I am on the way to a solution. It begins in this manner...
Dim p As New Pen(Color.Crimson, 2) Declare Function GetDesktopWindow Lib "user32.dll" () As IntPtr Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As IntPtr) As IntPtr Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As Integer Dim g As Graphics ' FromHdcInternal(is looking for an hdc As System.IntPtr) ' GetDesktopWindow() returns an HWND of the desktopg = Graphics.FromHdcInternal(GetWindowDC(GetDesktopWindow()))
g.DrawLine(p, 0, 100, 200, 400)
g.Dispose()
The beginning is working beautifully and it certainly does write on the desktop.
My only complaint is the resolution appears to be about 96 dpi and lines with aggressive angles of attack are not to smooth ....
But it's not all that critical.
I am not to sure about the proper disposal of resources either.
Renee
Nihad
I don't know who marked this closed. I don't want it closed.
OK. This is sort of neat but it also has some real problems. I don't know that they are circumventable.
I've had problems and solved several of them. With this approach, intially there is a screen flash as the screen fills with the transparency color and then becomes transparent. I've dealt with this by adding screenheight to me.top and letting things initalize and then retrning Me.top to zero.
***Sigh*** so that's the only good news.
The bad news is that some event seem to work and some do not.
This is now actually a second form and
I'm calling this as a second form and events do not seem to fire at all. Predictably.
I am subclassing the form to get WM_MOUSEMOVE. A trouble is I can't set a break point on many of the events. I know the event is occurring but I can't trap it to single step through it. The subclassing works for a few seconds and then there is a sate change and it stops.
(There is no config mgr shown on the menu to show whether is's release or debug mode. Why is there no config mgr displayed on the menu )
djnilm
Thanks dustin. I've missed the heck out of you.
Please write to me. Important News !!!!!!!!
No this doesn't work ......yet. As a matter of fact it has many problems. I'm going to get to work on it.
"A call to PInvoke function 'GDI!Test1.Form1::GetDC' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."
I'll get to work on it.
elianaca
Well, i had to make a new snippet for this...
basically, this creates a form the size of the entire screen, and makes it always on top. it sets up a transparency key to rgb(1,0,1), and sets the background to that color. so avoid drawing with the transparency key color if possible.
The effect is the same as drawing directly to the desktop.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.FormBorderStyle = Windows.Forms.FormBorderStyle.None
.ForeColor = Color.Transparent
.Top = 0
.Left = 0
.Height = My.Computer.Screen.Bounds.Height
.Width = My.Computer.Screen.Bounds.Width
.BackColor = Color.FromArgb(1, 0, 1)
.TransparencyKey = Color.FromArgb(1, 0, 1)
.BringToFront()
.TopMost = True
End With
End Sub
Public Sub Draw(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.FillEllipse(Brushes.BlanchedAlmond, 300, 800, 200, 300)
End Sub
End Class
kelton
More information.
I continued attempting to work with this technique. I created a class which produced a form which was given the attributes in dustin's example and the form with the class was instantiated as a friend with events. I see the same behaviors.
The transparent masking seems to work but I'm not able to use any events.
David Hernandez Diez
Hey Renee, It's been a while.
I have a code snippet i use for that. I'm at work, so i can't verify it right now. Let me know if it works though. I'll check it tonight when i'm home.
Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Sub main()
Dim gfx As Graphics
gfx = Graphics.FromHdcInternal(GetDC(GetDesktopWindow()))
Do Until My.Computer.Keyboard.CtrlKeyDown = True
gfx.Clear(Color.White)
gfx.FillEllipse(Brushes.Brown, New Rectangle(0, 0, 300, 300))
Loop
End Sub