Moving skinned Window .. PB vs B+

BlitzPlus Forums/BlitzPlus Programming/Moving skinned Window .. PB vs B+

Tracer(Posted 2004) [#1]
I am trying to get B+ to move the window no matter where one holds the mouse down on the Window... The following PB source works GREAT.. the B+ source.. doesn't do anything.

(These sources do nothing but create a window and wait for the user to move em.. which the PB one does, the B+ one, doesn't)

The PB source example, using SendMessage

[Code]
window = OpenWindow(1,100,100,600,400,#PB_WINDOW_TITLEBAR | #PB_Window_SystemMenu,"MOVE TEST")

Repeat
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(),161,2,0)
EndSelect
Until EventID = #PB_Event_CloseWindow
[/Code]


The B+ example, converted code, using SendMessage
[Code]
window = CreateWindow("MOVE TEST",100,100,600,400)

Repeat
If WaitEvent(1) = $201
SendMessage QueryObject(window,1),161,2,0
EndIf
Until EventID() = $803
[/Code]

The B+ userlib:
[Code]
.lib "user32.dll"

SendMessage%(hwnd,msg,wParam,mPAram) : "SendMessageA"
[/Code]


Any ideas why B+ refuses?

Tracer


Yan(Posted 2004) [#2]
I don't have B+ so I could be way off, but shouldn't you be sending 'SendMessage' the Win32 handle and not the Blitz handle of the window?

Are these the same thing in B+?

[edit]Oh that's what QueryObject() does...DOH![/edit]


YAN


Tracer(Posted 2004) [#3]
SendMessage expects the Win32 handle. I've tried both the QueryObject used above as well as FindWindow from the API both fail.

Tracer


dan_upright(Posted 2004) [#4]
i think you only get the mousedown event when the mouse is over a canvas


Binary_Moon(Posted 2004) [#5]
$201 - Mouse down
Generated when the user presses a mouse button while the mouse is positioned over a canvas gadget. EventData contains the button being pressed: 1 for the left button, 2 for the right button or 3 for the middle button. EventSource contains the canvas gadget handle. Note that you will only get a gadget action event ($401) for buttons, not a mouse down and a mouse up.


From the help file. The important bit to note is the bit that says "while the mouse is positioned over a canvas gadget"

That could be why. BTW I tried adding a canvas and nothing happened.

What's meant to happen exactly? I don't have purebasic to compare.


Yan(Posted 2004) [#6]
After a bit of googling...
User32.decls
-----------------------------------------
.lib "user32.dll"

FindWindow%(class$, Text$) : "FindWindowA"
SendMessage%(hWnd%, Msg%, wParam%, lParam%) : "SendMessageA"
ReleaseCapture%() : "ReleaseCapture"
SetCapture%(hwnd%) : "SetCapture"

AppTitle "test"

hwnd = FindWindow("Blitz Runtime Class", "test")

Repeat
	If MouseDown(1)
		ReleaseCapture()
		SendMessage(hwnd, $A1, 2, 0)
		SetCapture(hwnd)
	EndIf
Until KeyHit(1)

End
The B3D version (obviously).


YAN


Tracer(Posted 2004) [#7]
This crashes on B+ it seems.

Not really crashing.. but it doesn't seem to work.

Tracer


Yan(Posted 2004) [#8]
You didn't run that code 'as was' in B+ did you?
This works in the B+ demo. I had to use 'GetActiveWindow()' cos I don't know the class name of a B+ window. You should be able to use 'QueryObject()'...

User32.decls
-----------------------------------------
.lib "user32.dll"

FindWindow%(class$, Text$) : "FindWindowA"
SendMessage%(hWnd%, Msg%, wParam%, lParam%) : "SendMessageA"
ReleaseCapture%() : "ReleaseCapture"
SetCapture%(hwnd%) : "SetCapture"
GetActiveWindow%() : "GetActiveWindow"


window = CreateWindow("test", 100, 100, 600, 400)

hwnd = GetActiveWindow()

Repeat

	If MouseDown(1)

		ReleaseCapture()

		SendMessage(hwnd, $A1, 2, 0)

		SetCapture(hwnd)

	EndIf

Until KeyHit(1)


End
Yan


Tracer(Posted 2004) [#9]
I tried al sorts. Including the above :) and it didn't work.. must've made a slight booboo in the decls...

Thanks man :)

Tracer


Tracer(Posted 2004) [#10]
Ok..

To be able to use the mouse AFTER the above has been executed at least once, to do other MouseDown() and MouseHit() things in your code..

window = CreateWindow("test", 100, 100, 600, 400)

hwnd = GetActiveWindow()

Repeat
	If MouseDown(1)
		ReleaseCapture()
		SendMessage(hwnd, $A1, 2, 0)
		SetCapture(hwnd)
		ReleaseCapture()
	EndIf
Until KeyHit(1)
End


You gotta do the above.. REALLY fruity.. but without the second ReleaseCapture(), the mouse doesn't work any longer with the MouseHit() and MouseDown() (It basically keeps on dragging the window forever)..

Tracer


Yan(Posted 2004) [#11]
Sorry, I completely misunderstood the way SetCapure() and ReleaseCapture() works.

This should work...

window = CreateWindow("test", 100, 100, 600, 400)

hwnd = GetActiveWindow() ; QueryObject(window, 1)

Repeat
	id = WaitEvent()
	
	Select id
		Case $201
			ReleaseCapture()
			SendMessage(hwnd, $A1, 2, 0)
		Case $803
			End
	End Select
	
Forever
Got there eventually ;o)

Hmmm...I think I'll invest in a copy of B+. I don't really need it for anything but this windows stuff seems like it could be a bit of a wheeze :o)


YAN