IonicWind Software

Creative Basic => General Questions => Topic started by: SnarlingSheep on September 09, 2007, 08:46:42 AM

Title: Alias a built in command
Post by: SnarlingSheep on September 09, 2007, 08:46:42 AM
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.
Title: Re: Alias a built in command
Post by: GWS on September 09, 2007, 10:23:48 AM
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
Title: Re: Alias a built in command
Post by: SnarlingSheep on September 09, 2007, 03:55:07 PM
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.
Title: Re: Alias a built in command
Post by: pistol350 on September 10, 2007, 05:59:46 AM
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

Title: Re: Alias a built in command
Post by: SnarlingSheep on September 10, 2007, 05:44:13 PM
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"
Title: Re: Alias a built in command
Post by: Ionic Wind Support Team on September 10, 2007, 05:49:25 PM
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.
Title: Re: Alias a built in command
Post by: SnarlingSheep on September 10, 2007, 05:56:37 PM
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.