Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > GetPixel


Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2003, 08:38 AM
Crovax Crovax is offline
Newcomer
 
Join Date: Mar 2003
Location: Swe
Posts: 3
Default GetPixel


Im trying to make a program that runs in the back and when i hit a key it use GetPixel to get the RGB value from a pixel on the screen.

It lookings like this:

Dim hDCDesk As Long
Dim ReturnCol As Long

hDCDesk = GetDC(0)
ReturnCol = GetPixel(hDCDesk, x, y)

then i use

Debug.Print ReturnCol

so I can see the RBG value. This works fine.

The problem is when i start the program i look at a pixel and get its RGB value, later i look at the same pixel and i know that the RGB value have changed but when i look at the value its the same as the first one. I dont know what im doning wrong so i hope someone can help me with this or point me in some direction where i can get some info about this.

PS. Hope u can read and understand my bad english DS.
Reply With Quote
  #2  
Old 03-19-2003, 03:28 PM
Legend Legend is offline
Contributor
 
Join Date: Dec 2002
Posts: 542
Default

There is nothing wrong with your english!!

I think what you actually need to do is use an API call to get the handle to the window under the mousepointer (WindowFromPoint????). You then proceed as you have written.

I think that all your code is doing is getting the RGB for the point on the desktop - not from any window on top of the desktop.
Reply With Quote
  #3  
Old 03-20-2003, 12:13 AM
Crovax Crovax is offline
Newcomer
 
Join Date: Mar 2003
Location: Swe
Posts: 3
Default

Im try to spell as good as i can


Ah, So GetDC(0) dont get the dc to the screen? only the
desktop?

So all i have been doing is looking at the same pixel thats
in my desktoppic

Thx for the help i will look into the WindowFromPoint????? API
Reply With Quote
  #4  
Old 03-23-2003, 01:31 PM
Legend Legend is offline
Contributor
 
Join Date: Dec 2002
Posts: 542
Default

Crovax,

The function: GetCursorPos

Code:
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Can be used to convert the mouse position to the screen position.

You can then use WindowFromPoint to get the handle to the window under the mouse:

Code:
Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Reply With Quote
  #5  
Old 03-24-2003, 08:01 AM
Crovax Crovax is offline
Newcomer
 
Join Date: Mar 2003
Location: Swe
Posts: 3
Default

k, i will take a look at it and see how it works out

thx again for the help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
D3DXSprite or CopyRect / Getpixel / Setpixel etc etc piggybank1974 DirectX 29 11-23-2002 10:43 AM
GetPixel Prob! rowanjl General 3 07-06-2002 12:18 PM
GetPixel Error Epo General 18 03-26-2002 03:33 PM
GetPixel Returns What? Aviator General 7 02-24-2002 07:57 PM
how can i get the GetPixel color values to be shown in RGB? bratok General 4 02-17-2002 02:21 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->