Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need a quick help on getting the RGB of a pixel.
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HazySmoke)345




PostPosted: Sat Nov 19, 2005 7:47 pm   Post subject: Need a quick help on getting the RGB of a pixel.

I'm trying to get the color of a pixel on the top left corner of the screen, so I typed

code:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Sub Command1_Click()
    Print GetPixel(Me.hdc, 0, 0)
End Sub


But the outcome is 13554646 always. Now, I'm not that clear about what I'm doing here... does "Me.hdc" confine the program to find the color of the pixel inside the form? If it does... how do I make it find the top left corner of the whole screen?
Sponsor
Sponsor
Sponsor
sponsor
Brightguy




PostPosted: Sat Nov 19, 2005 10:31 pm   Post subject: Re: Need a quick help on getting the RGB of a pixel.

Yes, Me.hdc will only return the device context handle to the form.

I'm sure there are lots of ways to do this (e.g. CreateDC) but GetWindowDC seems to work fine:
VisualBASIC:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Form_Click()
    Me.BackColor = GetPixel(GetWindowDC(0), 0, 0)
End Sub
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: