| View previous topic :: View next topic |
| Author |
Message |
Rubes_sw Valued Contributor


Joined: 11 Jun 2001 Posts: 625 Location: Northern Ireland
|
Posted: Wed Jul 30, 2003 3:55 pm Post subject: Pixel ! |
|
|
Can you use an API call or the gdi32.dll to get the pixel color of where the mouse ponter is ?
I know it can be done with one of tommys dll's (but it does not work in vds5)
Nathan |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Jul 30, 2003 4:27 pm Post subject: |
|
|
Yes there is, I'll see if I can get you an example soon. _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Jul 30, 2003 5:44 pm Post subject: |
|
|
Well, I have done this in another language, but in VDS it is only returning -1 as the pixel when it should return the 32bit pixel color.
Maybe someone else can see if I'm doing something wrong.
| Code: |
LOADLIB gdi32.dll
LOADLIB user32.dll
Title GetPixel
DIALOG CREATE,GetPixel,-1,0,240,80,CLASS SSGetPixel
DIALOG ADD,BUTTON,Start,20,40,64,24,Start
DIALOG ADD,BUTTON,Stop,20,132,64,24,Stop
DIALOG ADD,STATUS,STATUS,Click Start to start getting pixel.
DIALOG SHOW
:Evloop
wait event
goto @event()
:StartBUTTON
REPEAT
# Get DC of our Dialog to use with GetPixel.
%%Hwnd = @STRDEL(@WINEXISTS(#SSGetPixel),1,1)
%%DC = @LIB(user32,GetWindowDC,INT,%%Hwnd:INT)
%%Top = @WINPOS(@WINEXISTS(#SSGetPixel),T)
%%Left = @WINPOS(@WINEXISTS(#SSGetPixel),L)
# We need the position of the mouse inside the window it's over.
# So we subtract the Left and Top of the Window from the X and Y of the Mouse.
IF @GREATER(%%Left,-1)
%%GetPixelX = @FSUB(@MOUSEPOS(X),%%Left)
ELSE
%%GetPixelX = @MOUSEPOS(X)
END
IF @GREATER(%%Top,-1)
%%GetPixelY = @FSUB(@MOUSEPOS(Y),%%Top)
ELSE
%%GetPixelY = @MOUSEPOS(Y)
END
%%Pixel = @LIB(gdi32,GetPixel,INT,%%DC:INT,%%GetPixelX:INT,%%GetPixelY:INT)
%%Ret = @LIB(user32,ReleaseDC,INT,%%Hwnd:INT,%%DC:INT)
DIALOG SET,Status,X:%%GetPixelX - Y:%%GetPixelY - Pixel:%%Pixel
%%Event = @event()
WAIT 0.1
UNTIL %%Event
goto %%Event
:StopBUTTON
goto evloop
:Close
FREELIB gdi32.dll
FREELIB user32.dll
exit
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed Jul 30, 2003 6:04 pm Post subject: |
|
|
You swapped the INT: parameter... It should be before the other parameters.
You did:
%%Pixel = @LIB(gdi32,GetPixel,INT,%%DC:INT,%%GetPixelX:INT,%%GetPixelY:INT)
While it should be:
%%Pixel = @LIB(gdi32,GetPixel,INT,INT:%%DC,INT:%%GetPixelX,INT:%%GetPixelY)
If you don't know how to place them, you can always 'forget' them, in most cases VDS will find the right ones itself...
The changed code:
| Code: | LOADLIB gdi32.dll
LOADLIB user32.dll
Title GetPixel
DIALOG CREATE,GetPixel,-1,0,240,80,CLASS SSGetPixel
DIALOG ADD,BUTTON,Start,20,40,64,24,Start
DIALOG ADD,BUTTON,Stop,20,132,64,24,Stop
DIALOG ADD,STATUS,STATUS,Click Start to start getting pixel.
DIALOG SHOW
:Evloop
wait event
goto @event()
:StartBUTTON
REPEAT
# Get DC of our Dialog to use with GetPixel.
%%Hwnd = @STRDEL(@WINEXISTS(#SSGetPixel),1,1)
%%DC = @LIB(user32,GetWindowDC,INT,%%Hwnd:INT)
%%Top = @WINPOS(@WINEXISTS(#SSGetPixel),T)
%%Left = @WINPOS(@WINEXISTS(#SSGetPixel),L)
# We need the position of the mouse inside the window it's over.
# So we subtract the Left and Top of the Window from the X and Y of the Mouse.
IF @GREATER(%%Left,-1)
%%GetPixelX = @FSUB(@MOUSEPOS(X),%%Left)
ELSE
%%GetPixelX = @MOUSEPOS(X)
END
IF @GREATER(%%Top,-1)
%%GetPixelY = @FSUB(@MOUSEPOS(Y),%%Top)
ELSE
%%GetPixelY = @MOUSEPOS(Y)
END
%%Pixel = @LIB(gdi32,GetPixel,INT,INT:%%DC,INT:%%GetPixelX,INT:%%GetPixelY)
%%Ret = @LIB(user32,ReleaseDC,INT,INT:%%Hwnd,INT:%%DC)
DIALOG SET,Status,X:%%GetPixelX - Y:%%GetPixelY - Pixel:%%Pixel
%%Event = @event()
WAIT 0.1
UNTIL %%Event
goto %%Event
:StopBUTTON
goto evloop
:Close
FREELIB gdi32.dll
FREELIB user32.dll
exit |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Jul 30, 2003 6:07 pm Post subject: |
|
|
Doh, thanks Skit, that explains alot..
I usually do just leave them off, guess I should have left it that way  _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Wed Jul 30, 2003 6:27 pm Post subject: |
|
|
Well I had made a similar one planning +/- to add to VDS tray helper Utilty. _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Jul 30, 2003 6:29 pm Post subject: |
|
|
Now to get the RGB values from %%Pixel..does VDS have a logical and equivalent? Like & in other languages..
This is what I need to do:
| Code: |
red = pixel & 0x0000FF
green = (pixel & 0x00FF00) / 256
blue = (pixel & 0xFF0000) / 65536
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Wed Jul 30, 2003 6:36 pm Post subject: |
|
|
I dont know the formula. But if it needs getting loword/hiword you can use the hilo.dll I wrote for calling Wavmix.dll.
Ok it needs and only. Can U write a w32 dll ? If not i will add this function to hilo.dll which already gives hibit/lobit also. _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Jul 30, 2003 7:40 pm Post subject: |
|
|
CodeScript: So far I haven't really messed with making DLL's. I did find a way to do it with Hex though.
Nathan: This should(hopefully ) be the final working version.
| Code: |
#DEFINE FUNCTION,SSBitAnd
#DEFINE FUNCTION,SSDec2Bin
#DEFINE FUNCTION,SSBin2Dec
#DEFINE FUNCTION,SSHex2Dec
LOADLIB gdi32.dll
LOADLIB user32.dll
Title GetPixel
DIALOG CREATE,GetPixel,-1,0,240,80,CLASS SSGetPixel
REM *** Modified by Dialog Designer on 7/30/2003 - 12:30 ***
DIALOG ADD,BUTTON,Start,20,40,64,24,Start
DIALOG ADD,BUTTON,Stop,20,132,64,24,Stop
DIALOG ADD,STATUS,STATUS,Click Start to start getting pixel.
DIALOG SHOW
:Evloop
wait event
goto @event()
:StartBUTTON
REPEAT
# Get DC of our Dialog to use with GetPixel.
%%Hwnd = @STRDEL(@WINATPOINT(@MOUSEPOS(X),@MOUSEPOS(Y)),1,1)
%%DC = @LIB(user32,GetWindowDC,INT,%%Hwnd)
%%Top = @WINPOS(@WINATPOINT(@MOUSEPOS(X),@MOUSEPOS(Y)),T)
%%Left = @WINPOS(@WINATPOINT(@MOUSEPOS(X),@MOUSEPOS(Y)),L)
# We need the position of the mouse inside the window it's over.
# So we subtract the Left and Top of the Window from the X and Y of the Mouse.
IF @GREATER(%%Left,-1)
%%GetPixelX = @FSUB(@MOUSEPOS(X),%%Left)
ELSE
%%GetPixelX = @MOUSEPOS(X)
END
IF @GREATER(%%Top,-1)
%%GetPixelY = @FSUB(@MOUSEPOS(Y),%%Top)
ELSE
%%GetPixelY = @MOUSEPOS(Y)
END
%%Pixel = @LIB(gdi32,GetPixel,INT,INT:%%DC,INT:%%GetPixelX,INT:%%GetPixelY)
%%Ret = @LIB(user32,ReleaseDC,INT,INT:%%Hwnd,INT:%%DC)
%%Red = @SSBitAnd(%%Pixel,@SSHex2Dec(0000FF))
%%Green = @DIV(@SSBitAnd(%%Pixel,@SSHex2Dec(00FF00)),256)
%%Blue = @DIV(@SSBitAnd(%%Pixel,@SSHex2Dec(FF0000)),65536)
DIALOG SET,Status,Red:%%Red - Green:%%Green - Blue:%%Blue
%%Event = @event()
WAIT 0.1
UNTIL %%Event
goto %%Event
:StopBUTTON
goto evloop
:SSBitAnd
%%SSBAresult = ""
%%SSBA1 = @SSDec2Bin(%1)
%%SSBA2 = @SSDec2Bin(%2)
IF @GREATER(@LEN(%%SSBA1),@LEN(%%SSBA2))
%%SSBAStop = @LEN(%%SSBA1)
%%SSBACheck = 1
ELSE
%%SSBAStop = @LEN(%%SSBA2)
%%SSBACheck = 2
END
WHILE @NOT(@EQUAL(@LEN(%%SSBA2),@LEN(%%SSBA1)))
IF @EQUAL(%%SSBACheck,1)
%%SSBA2 = "0"%%SSBA2
ELSE
%%SSBA1 = "0"%%SSBA1
END
WEND
%%SSBAX = 1
REPEAT
IF @BOTH(@EQUAL(@SUBSTR(%%SSBA1,%%SSBAX,%%SSBAX),1),@EQUAL(@SUBSTR(%%SSBA2,%%SSBAX,%%SSBAX),1))
%%SSBAResult = %%SSBAResult"1"
ELSE
%%SSBAResult = %%SSBAResult"0"
END
%%SSBAX = @SUCC(%%SSBAX)
UNTIL @GREATER(%%SSBAX,%%SSBAStop)
%%SSBAresult = @SSBin2Dec(%%SSBAresult)
exit %%SSBAresult
:SSDec2Bin
%%SSD2Bresult = ""
%%SSD2BintValue = %1
While @GREATER(%%SSD2BintValue,0)
%%SSD2Bi = @MOD(%%SSD2BIntValue,2)
%%SSD2Bi = @FADD(%%SSD2Bi,1)
%%SSD2BintValue = @DIV(%%SSD2BintValue,2)
%%SSD2Bresult = @SUBSTR("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",%%SSD2Bi,%%SSD2Bi)%%SSD2Bresult
WEND
exit %%SSD2Bresult
:SSBin2Dec
%%SSB2DResult = 0
%%SSB2DX = 1
%%SSB2DStrValue = %1
REPEAT
%%SSB2DCharValue = @POS(@UPPER(@SUBSTR(%%SSB2DStrValue,%%SSB2DX,%%SSB2DX)),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#return -1 if character is not supported by base
If @GREATER(%%SSB2DCharValue,2)
%%SSB2DResult = -1
%%SSB2DX = @SUCC(@LEN(%%SSB2DStrValue))
END
%%SSB2DResult = @FADD(@FMUL(%%SSB2DResult,2),@FSUB(%%SSB2DcharValue,1))
%%SSB2DX = @SUCC(%%SSB2DX)
UNTIL @GREATER(%%SSB2DX,@LEN(%%SSB2DStrValue))
exit %%SSB2DResult
:SSHex2Dec
%%SSH2DHex = %1
%%SSH2D = 0
%%SSH2DX = 1
repeat
%%SSH2DChar = @UPPER(@SUBSTR(%%SSH2DHex,%%SSH2DX,%%SSH2DX))
%%SSH2DPos = @FSUB(@POS(%%SSH2DChar,"0123456789ABCDEF"),1)
%%SSH2D = @FADD(@FMUL(%%SSH2D,16),%%SSH2DPos)
%%SSH2DX = @SUCC(%%SSH2DX)
until @GREATER(%%SSH2DX,@LEN(%%SSH2DHex))
exit %%SSH2D
:Close
exit
|
UPDATE: Now uses Bitwise AND to get the RGB values from %%Pixel. _________________ -Sheep
My pockets hurt...
Last edited by SnarlingSheep on Fri Aug 01, 2003 9:56 pm; edited 1 time in total |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Thu Jul 31, 2003 2:00 am Post subject: |
|
|
Thanks snarling sheep
OK I thought it must be posible without any dll as already a color converter exists in VDS. I did not know exactly how to do it though. _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Thu Jul 31, 2003 9:38 am Post subject: |
|
|
Well if U want a dll for most of the math functions needed for API here you go:
http://codescript.vdsworld.com/VDS5src/APImathDLL.zip
Also SnarlingSheep i think U need not get the DC of every window Desktop DC would be enough I think - that would make the code simpler/efficient( i think I did this in my code - i have no acces it currently. I will check and let you know.
Enjoy! _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Fri Aug 01, 2003 10:00 pm Post subject: |
|
|
I updated the code above to use Bitwise AND to get the RGB values from %%Pixel..this is more reliable.
| CodeScript wrote: | Also SnarlingSheep i think U need not get the DC of every window Desktop DC would be enough I think - that would make the code simpler/efficient( i think I did this in my code - i have no acces it currently. I will check and let you know.
Enjoy! |
I tried it using GetDesktopWindow and it seems to make the mouse position off..you get pixels that aren't at the cursor position. I guess I'd have to find the position of the Desktop Window and subtract it from the mouse position..too much work for a simple example  _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|