473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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!

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  4.  
  5. Private Sub Form_Load()
  6. Dim lngHDC As Long
  7.  
  8. MsgBox "Picture1.hdc value = " & Picture1.hdc
  9.  
  10. lngHDC = GetDC(Form1.Picture1.hwnd)
  11.  
  12. MsgBox "GetDC value = " & lngHDC
  13.  
  14. 'Get the color
  15. MsgBox GetPixel(lngHDC, 1, 1)
  16.  
  17. End Sub
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(picture1.hdc, 1, 1).
Mar 11 '08 #1
2 3834
debasisdas
8,127 Expert 4TB
What exactly you are trying to do ?
Mar 11 '08 #2
The exact same thing as this guy. http://www.thescripts.com/forum/thread765261.html . 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!
Mar 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sandra Setz | last post by:
Hi, Is it possible to assign the Picture property of a picturebox to the Picture property of an image control? I use an invisble picturebox to make some changes to a picture, but I want to...
0
by: adrian maull | last post by:
I'm using the GetWindowRect in my screen capture utility: private static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle); My Rect Struct: public struct Rect {
17
by: Bonj | last post by:
Is PostQuitMessage(?) different to PostMessage(hWnd, WM_QUIT, ... ) ? I've got a window in a DLL (the same one experiencing the issue below, "return value of WM_QUIT") in which PostMessage(hWnd,...
4
by: mark | last post by:
I need to use GetDC but I don't know how to find a parameter to pas to the function. This is the GetDc from MSVC help: ********** GetDC The GetDC function retrieves a handle to a display...
8
by: MyAlias | last post by:
Can't solve this CallBack returning structures Error message: An unhandled exception of type 'System.NullReferenceException' occurred in MyTest.exe Additional information: Object reference not...
1
by: MultiMarine | last post by:
Hello I have just started using .NET and C# from a c++ background using win32. Now i want to do something that i used to do, without using the win32 API. I use Spy++ to get a HWND from...
5
by: Paul Aspinall | last post by:
Hi I am trying to find the application from a hWnd handle. ie. if the hWnd is to Internet explorer, I want to try to return iexplore.exe (as per processes in Task Manager), or some other...
6
by: NvrBst | last post by:
Hello. I can pInvoke "GetDC" with NULL or "IntPtr.Zero" and get the hDC for the entire screen. I can use the hDC for stuff like "GetPixel" and it works fine. When I try to do the... ...
1
FishVal
by: FishVal | last post by:
Hi. Does anybody know the name of DLL to declare GetDC(hwnd) alias in VBA.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.