Prevent window from moving

Hello,

Does anybody know how to get the below windows API working in Xojo;

Declare Sub SetWindowPos Lib “User32” ( hwnd as Integer, after as Integer, x as Integer, y as Integer, _
width as Integer, height as Integer, flags as Integer )
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_NOTOPMOST = -2
SetWindowPos( self.handle, HWND_NOTOPMOST , 0, 0, me.Width , me.Height , SWP_NOMOVE )

Thanks.

[quote=111253:@A Himmit]Hello,

Does anybody know how to get the below windows API working in Xojo;

Declare Sub SetWindowPos Lib “User32” ( hwnd as Integer, after as Integer, x as Integer, y as Integer, _
width as Integer, height as Integer, flags as Integer )
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_NOTOPMOST = -2
SetWindowPos( self.handle, HWND_NOTOPMOST , 0, 0, me.Width , me.Height , SWP_NOMOVE )
[/quote]

This looks conformant to msdn http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

Have you tried it in the window Open event ?

Hi Michel,

Yes I’m executing this code from the window open event. Before this method I have another method that hides the application icon from taskbar, tha’s all.

Thanks.

Looks like this declare works, but it is telling the window “set the height to the height and the width to the width…”
Notice, if you change the me.width to me.width+100, the window resizes.

To create a window that can’t be moved, try changing the frame to “Plain Box”. There will be no titlebar, but I can’t think of any other way to prevent moving that won’t cause all sorts of flashing/flickering…

According to msdn, this function returns a boolean, and you had set it up with no return value. I tested it, and it works fine to position the window. Not really necessary as you can do that in Xojo, but this does work :

Declare Function SetWindowPos Lib "User32" ( hwnd as Integer, after as Integer, x as Integer, y as Integer, _ width as Integer, height as Integer, flags as Integer ) as boolean Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const HWND_NOTOPMOST = -2 Const HWND_TOP = 0 dim nothing as boolean = SetWindowPos( self.handle, HWND_TOP , 0, 0, me.Width , me.Height , SWP_NOSIZE )

I just did a bit of research in preventing a window from being moved, and found this method in C :
http://stackoverflow.com/questions/2400819/wpf-disable-window-moving

It involves placing a hook on the window messaging system and blocking the move messages. It should be possible to adapt it to Xojo declares, but it will be much more difficult than changing the window type.

Modal dialog seems better than plain box, as it keeps the menu, and you can always add a small red closing box in the upper right hand side.

Hooking the winproc isn’t hard. You just can’t use an instance method. It has to be a shared method or in a module.

Well ; I just do not know how to do it … Your insight will be appreciated.

I was just playing with a custom shape window and the idea came about : create a custom shape window with the picture of a normal window. Since the standard control bar is invisible, it becomes impossible to move such a window.

Here is the result : a non moving window.

NoMove.zip

Hi Michel,

Thanks for the afford, I’ll use the solution from your zip file. At least that works without a doubt.

Try this. Grab WFS, which has some support for hooking into WndProc. Add WFS to a new project and insert a new Window (NonMovableWindow) specifying this interface for it: WndProcSubclassWFS

This adds the WndProc method to the window.

In the Open event handler of the Window, add this code:

 WndProcHelpersWFS.Subclass( Self, self )

In the WndProc method (added when you selected the interface) add this code (translated from the StackOverflow link above):

[code]
// Part of the WndProcSubclassWFS interface.

Const WM_SYSCOMMAND = &h0112
Const SC_MOVE = &hF010

If msg = WM_SYSCOMMAND Then
Dim command As Integer = wParam And &hfff0
If command = SC_MOVE Then
Return True
End If
End If

Return False

#pragma unused hWnd[/code]

Set the default window on App to NonMovableWindow and run the project. The window appears and cannot be moved.

Paul I suspected the solution might be in WFS but the documentation for it is so terse I usually go for msdn instead.

It took me a while to locate WndProcHelpersWFS.rbbas in
WFS-master\Windows Functionality Suite\UI Extras\Modules
and WndProcSubclassWFS.rbbas in
WFS-master\Windows Functionality Suite\UI Extras\Interfaces

Then I applied your advice and it works great. Thank you.