Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Visual Basic Programming › [Help] Drawing pixels on screen?[Solved]

[Help] Drawing pixels on screen?[Solved]

Posts 1–15 of 15 · Page 1 of 1
MA
master131backup
[Help] Drawing pixels on screen?[Solved]
How would you draw pixels on the screen? I know there is a SetPixel function but I don't know how to get it working..... I tried the following (NONE of it probably makes sense because I just typed anything):

[php]Public Class Form1

Private Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal color As Integer) As Integer
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal wnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal wnd As IntPtr, ByVal dc As IntPtr) As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetPixel(GetDC(IntPtr.Zero), 500, 500, RGB(255, 0, 0))
ReleaseDC(IntPtr.Zero, GetDC(IntPtr.Zero))
End Sub
End Class
[/php]
#1 · 15y ago
master131
[MPGH]master131
Anyone? I edit my code here:
[php]Imports System****ntime.InteropServices
Public Class Form1
<DllImport("gdi32.dll")> Private Shared Function CreateDC(ByVal lpszDriver As String, ByVal lpszDevice As String, ByVal lpszOutput As String, ByVal lpInitData As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll")> Private Shared Function DeleteDC(ByVal hdc As IntPtr) As Boolean
End Function
<DllImport("gdi32.dll")> Private Shared Function SetPixel(ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer, ByVal colour As ColorRef) As Integer
End Function
Private ScreenDC As IntPtr = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
Private red As New ColorRef(255, 0, 0)
Private intX As Integer = Screen.PrimaryScreen.Bounds.Width / 2
Private intY As Integer = Screen.PrimaryScreen.Bounds.Height / 2
Structure ColorRef
Public red, green, blue As Byte
Private unused As Byte
Public Sub New(ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
red = r
green = g
blue = b
unused = 0
End Sub
End Structure

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SetPixel(ScreenDC, intX, intY, red)
DeleteDC(ScreenDC)
End Sub
End Class[/php]
#2 · 15y ago
Jason
Jason
Won't work in game, by the way. Just renders over the top.

Also, DeleteDC should only be on your Form_Closing event, if you delete the device context, it removes all your alterations. Also, you can just do color.ToArgb.
#3 · 15y ago
Kuro Tenshi
Kuro Tenshi

nvm... didnt start...
the graphic command usage
[php]
graphic. *typ of Draw* ( *color*, *pos x*, *pos y*, *Length*, *Width* )
[/php]
#4 · edited 15y ago · 15y ago
master131
[MPGH]master131
Quote Originally Posted by Jason View Post
Won't work in game, by the way. Just renders over the top.

Also, DeleteDC should only be on your Form_Closing event, if you delete the device context, it removes all your alterations. Also, you can just do color.ToArgb.
Still doesn't work though :/
#5 · 15y ago
Jason
Jason
Quote Originally Posted by master131 View Post
Still doesn't work though :/
Did you remove DeleteDC from the timer?
#6 · 15y ago
master131
[MPGH]master131
Quote Originally Posted by Jason View Post


Did you remove DeleteDC from the timer?
I sure did..
#7 · 15y ago
Jason
Jason
Gimme one sec, I'll write a working one and you can go from there.

Edit, the problem might be your declarations, with manual dllimports it worked fine, but with declaring it didn't so just copy the declarations from my "DllImports" region and see if that fixes it first.

[php]
Imports System. Runtime.InteropServices
Public Class Form1
#Region "DllImports"

<DllImport("Gdi32.dll")> _
Public Shared Function GetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function SetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal xColor As Integer) As Integer
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function CreateDC(ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function DeleteDC(ByVal dc As IntPtr) As Boolean
End Function

#End Region

Private ScreenDC As IntPtr
Private midX As Integer = My.Computer.Screen.Bounds.Size.Width / 2
Private midY As Integer = My.Computer.Screen.Bounds.Size.Height / 2

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
DeleteDC(ScreenDC)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ScreenDC = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For x As Integer = midX - 10 To midX + 10
SetPixel(ScreenDC, i, midY, Color.Red.ToArgb)
Next

For y As Integer = midY - 10 To midY + 10
SetPixel(ScreenDC, midX, x, Color.Red.ToArgb)
Next
End Sub

End Class
[/php]
#8 · edited 15y ago · 15y ago
master131
[MPGH]master131
Nothing still appears on my screen though, is it the fact that I need to run VB2010 as admin?
Or is it because I fail at VB? /
#9 · edited 15y ago · 15y ago
Jason
Jason
Quote Originally Posted by master131 View Post
Nothing still appears on my screen though, is it the fact that I need to run VB2010 as admin?
Or is it because I fail at VB? /
Hmm, did you use the exact code I used as a controlled test? (With a button on the form obviously.)
#10 · 15y ago
master131
[MPGH]master131
Quote Originally Posted by Jason View Post


Hmm, did you use the exact code I used as a controlled test? (With a button on the form obviously.)
I sure did! Strange how it didn't work though.

EDIT - Got it working, probably because ScreenDC wasn't declared at the start.
[php]Imports System****ntime.InteropServices
Public Class Form1
#Region "DllImports"

<DllImport("Gdi32.dll")> _
Public Shared Function GetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function SetPixel(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal xColor As Integer) As Integer
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function CreateDC(ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function DeleteDC(ByVal dc As IntPtr) As Boolean
End Function

#End Region
Private ScreenDC As IntPtr = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
Private midX As Integer = My.Computer.Screen.Bounds.Size.Width / 2
Private midY As Integer = My.Computer.Screen.Bounds.Size.Height / 2

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
DeleteDC(ScreenDC)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = midX - 10 To midX + 10
SetPixel(ScreenDC, i, midY, Color.Red.ToArgb)
Next

For x As Integer = midY - 10 To midY + 10
SetPixel(ScreenDC, midX, x, Color.Red.ToArgb)
Next
End Sub

End Class[/php]

The crosshair seems to be in Black and White though.
#11 · edited 15y ago · 15y ago
Jason
Jason
Quote Originally Posted by master131 View Post
I sure did! Strange how it didn't work though.
Last thing I can think of, try this:

[php]
Imports System****ntime.InteropServices
Public Class Form1
#Region "DllImports"

<DllImport("Gdi32.dll")> _
Public Shared Function GetPixel(ByVal hdc As IntPtr, ByVal x As Int32, ByVal y As Int32) As Int32
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function SetPixel(ByVal hdc As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal xColor As Int32) As Int32
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function CreateDC(ByVal driverName As String, ByVal deviceName As String, ByVal output As String, ByVal lpInitData As IntPtr) As IntPtr
End Function

<DllImport("Gdi32.dll")> _
Public Shared Function DeleteDC(ByVal dc As IntPtr) As Boolean
End Function

#End Region

Private ScreenDC As IntPtr
Private midX As Int32 = My.Computer.Screen.Bounds.Size.Width / 2
Private midY As Int32 = My.Computer.Screen.Bounds.Size.Height / 2

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
DeleteDC(ScreenDC)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ScreenDC = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Int32 = midX - 10 To midX + 10
SetPixel(ScreenDC, i, midY, Color.Red.ToArgb)
Next

For x As Int32 = midY - 10 To midY + 10
SetPixel(ScreenDC, midX, x, Color.Red.ToArgb)
Next
End Sub
End Class
[/php]
#12 · edited 15y ago · 15y ago
master131
[MPGH]master131
Don't worry, got it working read above post.
#13 · 15y ago
Jason
Jason
Yeah I didn't play around with colors too much, couldn't be bothered fixing it up

Try this for a different color:

[php]
For i As Int32 = midX - 10 To midX + 10
SetPixel(ScreenDC, i, midY, &Hfe8a01)
Next

For x As Int32 = midY - 10 To midY + 10
SetPixel(ScreenDC, midX, x, &Hfe8a01)
Next
[/php]

Although doesn't seem like the HEX matches as it should.
#14 · edited 15y ago · 15y ago
master131
[MPGH]master131
Ah, never mind I fixed it myself. I used the ColorRef structure shown in the other snippet and it works now.
#15 · 15y ago
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

  • [Help]PopUp Form Center Screen[Solved]By tremaster in Visual Basic Programming
    15Last post 16y ago
  • [HELP] Draw direct to screen.By Jason in Visual Basic Programming
    6Last post 16y ago
  • [Help]Drawing a custom crosshair[Solved]By ♪~ ᕕ(ᐛ)ᕗ in Visual Basic Programming
    22Last post 15y ago
  • [Help] Pressing Print screen?[Solved]By nathanael890 in Visual Basic Programming
    23Last post 15y ago
  • [Help]WarRock Korean Error ScreenBy dor619 in WarRock Korea Hacks
    2Last post 19y ago

Tags for this Thread

None