mouseX(DesktopBuffer()) fails!

BlitzPlus Forums/BlitzPlus Programming/mouseX(DesktopBuffer()) fails!

Grey Alien(Posted 2005) [#1]
Why does MouseX(DesktopBuffer()) say "Invalid Canvas Gadget Handle?"

All I want to do is get the mouse coords relative to the desktop instead of my app. I also tried this:

SetBuffer DesktopBuffer()
dmx = MouseX()
dmy = MouseY()				
SetBuffer BackBuffer()

This just returns the coords relative to the Backbuffer.

Can you help Prof as you suggested this technique forme to see if a mouse cursor is outside the current window?

Thanks in advance.


Beaker(Posted 2005) [#2]
MouseX() and MouseY() work here.

MouseX(DeskTopBuffer()) doesn't work because the desktopbuffer isn't a canvas.

This seems to work:
window=CreateWindow( "Size me to ZOOM!",ClientWidth(Desktop())/2-96,ClientHeight(Desktop())/2-96,192,192 )

width=ClientWidth(window)
height=ClientHeight(window)

canvas=CreateCanvas( 0,0,width,height,window )
SetGadgetLayout canvas,1,1,1,1
SetBuffer CanvasBuffer(canvas)

While WaitEvent(10)<>$803

	mx=MouseX()-width/2
	my=MouseY()-height/2
	
	Cls
	
	CopyRect mx,my,width,height,0,0,DesktopBuffer()
	
	dmx = MouseX()
	dmy = MouseY()
	DebugLog dmx+" "+dmy
	FlipCanvas canvas
Wend

End



norki(Posted 2005) [#3]
I had mouse issues too, until I tried sswift's Improved Mouse Functions:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1290


Grey Alien(Posted 2005) [#4]
That's a pretty whacky app Beaker, reminds me of stuff I used to do on the Amiga to get an infinite mirror effect.

Unfortunately it won't work for me in my game which is setup like this (code extract, that I have made run)


you also need this user32.decls
.lib "user32.dll"
User32_SetWindowLong% (hwnd%, nIndex%, dwNewLong%) : "SetWindowLongA"
User32_GetWindowLong%(hwnd%, nIndex%): "GetWindowLongA" 
User32_GetActiveWindow%(): "GetActiveWindow"
User32_FindWindowA%(NullString,WindowText$):"FindWindowA"
User32_SetWindowPos%(hWnd%,hAfter%,x%,y%,cx%,cy%,flags%):"SetWindowPos" 
User32_keybd_event%(bVk%, bScan%, dwFlags%, dwExtraInfo%) : "keybd_event" 
User32_updatewindow%(hwnd%): "UpdateWindow"
User32_ShowWindow% (hwnd%, nCmdShow%): "ShowWindow" 
User32_SetClassLongA%(hWnd%,nIndex%,Value%):"SetClassLongA"
User32_GetWindowPlacement%(hwnd%, pwpl*):"GetWindowPlacement" 
User32_GetWindowRect%(hwnd%, prect*):"GetWindowRect" 


Basically I'm not using the Blitz gadgets because my windowed mode actually uses the Graphics command and various windows API calls to set it up. So mouseX and MouseY return the coords inside the window only. I can't get the coords relative to the desktop and I really want them! Any ideas?

thanks


Grey Alien(Posted 2005) [#5]
Woo norki! You posted that just 4 seconds before my last post. All I needed was GetCursorPos%(lpPoint*):"GetCursorPos".

Thanks to you and of course sswift for finding it, I shoulda just checked User32.dll, but I thought there might be an easy blitz way.

Thanks too Beaker.