March 28, 2024, 05:25:17 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Alias a built in command

Started by SnarlingSheep, September 09, 2007, 08:46:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SnarlingSheep

I can't remember, can you Alias GetPixel from GDI32 and use it?

DECLARE "gdi32.dll",_GetPixel alias GetPixel(hdc:INT, x:INT, y:INT),INT
Gives me a wrong variable type error when I try to send it a window DC, since it seems to just alias the built in GetPixel.


Kind of on this note, is there any way that the 'Wrong Variable Type' error could tell you which variable it ran into?
It took me a while to figure out why it was complaining about this situation.

GWS

Hi Sheep,

I don't think you can use an underscore in a variable name, it has to begin with a letter.

I've never tried it in an API call though .. of which I'm no expert ..  ::)

Why not just use the built-in 'GetPixel' statement .. ?  :)

Graham
Tomorrow may be too late ..

SnarlingSheep

The built in GetPixel doesn't seem to work with external(Non-CBasic) windows.
Unless I missed something.. I went round and round with trying different things late last night.

pistol350

September 10, 2007, 05:59:46 AM #3 Last Edit: September 10, 2007, 06:01:52 AM by pistol350
Hi SnarlingSheep!

this declaration works for me :DECLARE "gdi32.dll",_GetPixel(hdc:INT, x:INT, y:INT),INT

see the example below:


DECLARE "gdi32.dll",_GetPixel(hdc:INT, x:INT, y:INT),INT

DEF myWindow:WINDOW
DEF loopcount, left, width : INT
left=150width=300
WINDOW myWindow,0,0,300,260,@SIZE|@MINBOX|@MAXBOX,0,"Get Pixel",main
CONTROL myWindow,"B,Close Window,0,0,200,20,0,1"
ELLIPSE myWindow,30,30,100,150,RGB(150,150,150),RGB(0,255,255)
MOVE myWindow, 0, 200
PRINT myWindow, "The color of pixel 200,0 is :", ,_GetPixel(myWindow,200,0)
MOVE myWindow, 0, 215
PRINT myWindow, "The color of pixel 65,105 is :", ,_GetPixel(myWindow,65,105)
run = 1
WAITUNTIL run = 0
CLOSEWINDOW myWindow
END   

SUB main
SELECT @CLASS
CASE @IDCONTROL   
SELECT @CONTROLID         
CASE 1           
run = 0   
endselect   
CASE @IDCLOSEWINDOW       
run = 0   
ENDSELECT
RETURN

Regards,

Peter B.

SnarlingSheep

pistol: In your example, somehow, _GetPixel still uses the built in GetPixel command.
It complains when trying to pass it an HDC instead of a WINDOW variable.

The GetPixel API wants an HDC of a window, the CBasic GetPixel wants a WINDOW variable(handle).

It seems like the built in GetPixel should work with any window.. why does this crash:
DECLARE "user32.dll",WindowFromPoint(xPoint:INT, yPoint:INT),INT
DEF pixel:INT
DEF cursorwnd:WINDOW
cursorwnd = WindowFromPoint(10,10)
pixel = GetPixel(cursorwnd,20,20)
messagebox 0,STR$(pixel),"Pixel value"

Ionic Wind Support Team

A WINDOW variable isn't a handle, it is an internal structure and it is only of use to the built in commands, not the Windows API. 

Use two underscores or a different name.

DECLARE "gdi32.dll",GDIGetPixel alias GetPixel(hdc:INT, x:INT, y:INT),INT

Paul.
Ionic Wind Support Team

SnarlingSheep

Ah, there we go, thank you Paul.
I believe I tried that, but sometimes, apparently if I hit save and then run too quick, the IDE crashes. I thought it crashed because of what I tried.