PDA

Click to See Complete Forum and Search --> : SetPixel Problem...


TalZ
Jun 26th, 2000, 01:54 AM
Hi...
Look, i try to do a little prog that just print a random pixels on the desktop and i have a little problem...

this is the code:


'Module

Public Declare Function SetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long


'This the Code...

Private Sub Command1_Click()
Dim DC As Long

'Get the DC
DC = GetWindowDC(GetDesktopWindow)

Randomize Timer
Timer1.Enabled = True
SetPixel DC, 100, 100, 200 'This is work just fine...
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
SetPixel DC, 100, 100, 200 'This, the same line!
SetPixel DC, Rnd * 100,Rnd * 100, 200 '& This !!!Dont Work!!!
End Sub



This is the problem, the function don't work in the timer sub...

WHY ???

if you can help me... THANKS!

Fox
Jun 26th, 2000, 02:10 AM
Just put this into your timer
Dim DC As Long

'Get the DC
DC = GetWindowDC(GetDesktopWindow)

SetPixel DC, 100 * Rnd, 100 * Rnd, 255


(Should always get the DC again ;))

joey o.
Jun 26th, 2000, 02:10 AM
Did you set the timer1.interval = a number? It won't work if you don't do this.

Jun 26th, 2000, 02:11 AM
Is your Timer Enabled? Did you set a valid Interval for it?

TalZ
Jun 26th, 2000, 02:34 AM
Thanks Fox !!!

but there is another way, easy one...

just dim the dc in the start of code and then it public and no private.

i didn't see it before!

thanks again!

kedaman
Jun 26th, 2000, 05:44 AM
Sorry to disappoint you but the pixels wont stay there, if you put another window over it it will erase them. If anyone knows how to make them persistent, i would be glad to know

Fox
Jun 26th, 2000, 11:33 AM
The only way it prolly to store them in your own DC and copy it to the desktop every time... and backup the pixels behind... Yeah, I know the problem :(

TalZ
Jun 26th, 2000, 03:21 PM
it's ok i get what i want...
it's dont bother me that you can delete them...

;) ;) ;) ;) ;) ;)

[Edited by TalZ on 06-27-2000 at 04:24 AM]

Fox
Jun 27th, 2000, 12:53 AM
Kedaman cares ;)