Declare for Locking Window in place

Hi,

Does anyone have code or a link to a Windows Declare that will lock a window in place? Here is an equivalent MacOS Cocoa Declare.

I know I can do this in Xojo code, but I am venturing out into the land of OS Framework :slight_smile:

Thanks in advance!

  #if TargetMacOS Then
    soft declare sub setMovable lib "Cocoa" selector "setMovable:" (windowRef as integer, yesNo as integer)
    setMovable(self.handle, 0)
  #endif

Wrong snippet :slight_smile: Still looking :slight_smile:

You got all the Windows API calls described here : http://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx

I browsed through it but could not find the equivalent of SetMovable.

The Windows plain box window is not that far from a regular window, though. With some design elements, it would very much look like a regular window that cannot move…

I am adding a “Lock Window” option on my menu bar which setMovable works perfectly on MacOS so thats why I am looking for the Win32 equivalent :wink:

I also was not successful with any Xojo equivelent code that may be cross platform to acheive this for a window. Any additional ideas or thoughts would be very helpful.

Thanks Michel!

I tried several ways of locking a regular window in Xojo and it does not work, because grabbing a window by its top always moves.

Another approach would be to start with a borderless window which does not move by default, and allow it to move with the code at
https://forum.xojo.com/9458-move-a-borderless-window

A quick try showed that it does work as long as the mouse is not in the top bar of the window, where a window could normally be dragged.

Unless there is a declare to get the MouseDown all over a window including the top bar, I do not see how you can emulate the Mac routine :confused:

Maybe you have to reserve the “Lock window” option for Mac users…

I got it :slight_smile: Here is how to do it in Windows, I think :

Create two different windows which have the same size and bear the same controls and code :

  • One regular window
  • One borderless window

Activating the “Lock window” renders invisible the regular window and reveals the borderless at the same place. Unactivating “Lock window” comes back to the regular window and makes invisible the borderless.

All depends on the complexity of your window UI for the actual coding, but it can work.

Michel thank you :slight_smile: I will try this!

I use a window with the type set in the IDE to Plain Box and set the width, Min. Width and Max. Width to the same value just as i do with the Height, Min. Height and Max. Height.
If you don’t want a menubar in the window set the Menu Bar to None. Because then there is no way to close the window you have to implement an event for closing e.g. Mousedown or put a close button on the window.

Andre do you lose the title bar when you use the Plain Box frame type in windows? I am loading a win 7 VM now to test :slight_smile:

Hmm I wonder if this would work if we forced the x/y coordinates to simulate a lock?

Windows API SetWindowPos

Windows API MoveWindow

Yes, the titlebar is the object that controls the move possibility of a window in Windows. It’s easy to fake a titlebar however by a canvas with a text as title.

Not tested (am on my MacBook), but in theory this should work…

[code] // This code lives in the Open event
Declare Sub SetWindowPos Lib “User32” ( hwnd as Ptr, after as Integer, x as Integer, y as Integer, width as Integer, height as Integer, flags as Integer )

Const SWP_NOMOVE = &h2
SetWindowPos( me.handle, 0, 0, 0, Me.Width, Me.Height, SWP_NOZORDER )[/code]

[quote=68474:@shao sean]Not tested (am on my MacBook), but in theory this should work…

[code] // This code lives in the Open event
Declare Sub SetWindowPos Lib “User32” ( hwnd as Ptr, after as Integer, x as Integer, y as Integer, width as Integer, height as Integer, flags as Integer )

Const SWP_NOMOVE = &h2
SetWindowPos( me.handle, 0, 0, 0, Me.Width, Me.Height, SWP_NOZORDER )[/code][/quote]

Tried to implement but

  • SWP_NOZORDER is not defined
  • If I assign SWP_NOZORDER = &h2 and try to run, I get “Parameters not compatible with that function” :frowning:

Shouldn’t SWP_NOZORDER = &h4 ?

Probably, but that still would not explain the Parameters not compatible with that function. Reading the definition and what is passed, it should work, though.

This code in the Moved event of the window prevents its movement and it’s cross platform.

[code]static top, left as integer

if top = 0 then top = self.top
if left = 0 then left = self.left

self.top = top
self.left = left[/code]

The first ( hwnd ) parameter is the problem, it accepts it as integer, rather than ptr…

[code]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_NOMOVE = &h2

SetWindowPos( me.handle, 0, 0, 0, Me.Width, Me.Height, SWP_NOMOVE )

[/code]

…but Ramon’s solution worked OK.

BTW: Forgot to mention, the SetWindowPos call did get accepted, but ti did not prevent the window movment here !

[quote=68517:@Ramon SASTRE]This code in the Moved event of the window prevents its movement and it’s cross platform.

[/quote]

I tried that too. The issue is that it actually lets the user drag the window, then put it back where it was. It is not as if the window did not move at all.

[quote=68542:@Chris Carter]forgot to mention, the SetWindowPos call did get accepted, but ti did not prevent the window movment here !
[/quote]

Then we are back to square one, or not exactly : substituting a plain box window to a regular window of the same dimensions does work.

[quote=68517:@Ramon SASTRE]This code in the Moved event of the window prevents its movement and it’s cross platform.

[code]static top, left as integer

if top = 0 then top = self.top
if left = 0 then left = self.left

self.top = top
self.left = left[/code][/quote]

Ramon,
This works fine, only i would also disable resizeable, minimize and maximize button in the IDE.
Especially the minimize button can cause problems when restoring the window and leading to a crash of the program, as i discoverd while trying your solution.