mouseX(DesktopBuffer()) fails!

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

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.

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


I had mouse issues too, until I tried sswift's Improved Mouse Functions:

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

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)
;windows constants
Const GWL_STYLE        = -16
Const WS_MINIMIZE      = $00020000
Const WS_SYSMENU       = $00080000
Const SWP_NOSIZE       = $0001
Const SWP_NOMOVE       = $0002
Const SWP_FRAMECHANGED = $0020
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3

	Const FULLNAME$ = "TEST"
	AppTitle FULLNAME ;do before graphics is called

	IniWindowedMode = 1
	Local flag = 0
	If IniWindowedMode Then
		flag = 2
		GAME_WIDTH = 768
		GAME_HEIGHT = 540
	Else
		GAME_WIDTH = 800
		GAME_HEIGHT = 600
	EndIf

	;set commoncode vars
	ScreenWidth = GAME_WIDTH
	ScreenHeight = GAME_HEIGHT
			
	If Ini16BitGraphics Then
		Graphics GAME_WIDTH, GAME_HEIGHT, 16, flag
	Else
		Graphics GAME_WIDTH, GAME_HEIGHT, 32, flag
	EndIf
	
	If IniWindowedMode Then
		; add minimize button 
		TheWindow = User32_FindWindowA("",FULLNAME)				
		Wlong = User32_GetWindowLong(TheWindow, GWL_STYLE)
		Wlong = Wlong Or WS_MINIMIZE Or WS_SYSMENU		
		User32_SetWindowLong(TheWindow, GWL_STYLE, Wlong)				
		User32_ShowWindow(TheWindow,0) : User32_ShowWindow(TheWindow,1)	
	Else
		TheWindow = User32_FindWindowA("",FULLNAME)		
		AutoSuspend False ;needed in full screen mode to detect minimize to pause music
	EndIf	
	;always set the icon, as in full-screen mode they might alt+tab
	icon=Shell32_ExtractIconA(TheWindow,"fruitola.ico",0)
	User32_SetClassLongA(TheWindow,-14,icon)

While KeyDown(1) = 0 ;press escape to quit
 Cls
 dmx = MouseX()
 dmy = MouseY()
Text 0,0,dmx+ " " + dmy
Text 0,20,"press <Escape> to exit>
Flip
Wend


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

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.