Picture1.hdc returning different value than GetDC(Picture1.hwnd)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • junkmatred
    New Member
    • Mar 2008
    • 2

    Picture1.hdc returning different value than GetDC(Picture1.hwnd)

    Please help guys,

    Picture1.hdc is returning a different value than GetDC(Picture1. hwnd)

    Look at the source code I've provided. This doesn't make any sense! I need help!

    [CODE=vb]Option Explicit
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

    Private Sub Form_Load()
    Dim lngHDC As Long

    MsgBox "Picture1.h dc value = " & Picture1.hdc

    lngHDC = GetDC(Form1.Pic ture1.hwnd)

    MsgBox "GetDC value = " & lngHDC

    'Get the color
    MsgBox GetPixel(lngHDC , 1, 1)

    End Sub[/CODE]

    I need this to be fixed because I NEED that last line of code to be ran just the way it is, unfortunately. In my program, objects are being created, api's are being used, etc, all of it combined does not allow me to just write GetPixel(pictur e1.hdc, 1, 1).
    Last edited by debasisdas; Mar 11 '08, 08:39 AM. Reason: added code=vb tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What exactly you are trying to do ?

    Comment

    • junkmatred
      New Member
      • Mar 2008
      • 2

      #3
      The exact same thing as this guy. http://www.thescripts. com/forum/thread765261.ht ml . Turns out that in the end, he thought he solved his problem, but it turns out he didn't. All he did was get the program to return the value of the specific pixel of the picturebox color, not the webcam window (which is what he thought his code did), and didn't realize it.

      I'm trying to do this by using the GetPIxel function because I can only reference the webcam window by its hwnd. I'm just using a picturebox so it's nice and easy for people to help me. It should be the same thing as using the webcam api because all that's being referenced to get the window is it's hwnd.

      I figured out that the reason picture1.hdc and getdc(picture1. hwnd) is returning different values because I accidentally put AutoRedraw = true.

      BUT, the main problem with this, is that the GetPixel function is ONLY returning "-1" as it's value. Please help! This should work but it isn't - I've been pulling my hair out on this!

      Comment

      Working...