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
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
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
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.
I got it 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.
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.
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 )
[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 )
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.
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 )
[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.