Results 1 to 9 of 9

Thread: SetPixel Problem...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Angry

    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:

    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
    Code:
    '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!
    Tal Zur!

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Just put this into your timer
    Code:
        Dim DC As Long
        
        'Get the DC
        DC = GetWindowDC(GetDesktopWindow)
        
        SetPixel DC, 100 * Rnd, 100 * Rnd, 255
    (Should always get the DC again )

  3. #3
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Did you set the timer1.interval = a number? It won't work if you don't do this.

  4. #4
    Guest
    Is your Timer Enabled? Did you set a valid Interval for it?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16
    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!
    Tal Zur!

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Wink

    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]
    Tal Zur!

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Kedaman cares

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width