gdi and drawing a dot (setPixel ?)

bunze

Well-known member
Joined
Aug 4, 2005
Messages
52
Location
Adirolf
Programming Experience
1-3
All I want to do is draw a dot in the very middle of my screen, visible over all windows. I assume I use SetPixel and the msdn says use gdi32. I have no idea how to do this. Can someone just tell me exactly how? I swear ive been googling and testing code for well over 4 hours.

If no one knows how to do that, can someone tell me how to take C:\omg.bmp and use code to "draw" it to the screen over all widnows?

Thanks.
 
You can use GetDC and Graphics.FromHDC. Here is a code sample:

VB.NET:
Declare Function GetDC Lib "user32.dll" ( _
  ByVal hwnd As Int32) As Int32
 
Declare Function ReleaseDC Lib "user32.dll" ( _
  ByVal hwnd As Int32, _
  ByVal hdc As Int32) As Int32
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
  Dim img As Image = Image.FromFile("C:\omg.bmp")
  Dim hdc As Int32 = GetDC(0)
  Dim g As Graphics = Graphics.FromHdc(New IntPtr(hdc))
  g.DrawImage(img, 10, 10)
  ReleaseDC(0, hdc)
  g.Dispose()
[SIZE=2]  img.Dispose()
[/SIZE]End Sub

Article on DC 1 http://www.codeproject.com/gdi/paint_beginner.asp
Article on DC 2 http://www.codeproject.com/gdi/updatergn.asp
 
Hey thanks alot. That code is awesome.

I figured out:

SetPixel(GetDC(FindWindow(0, "Window")), 100, 100, Color.Red.ToArgb)

but the dot is black not red :(
 

Latest posts

Back
Top