Jump to content

_WinAPI_SetWindowPos() $SWP_NOSENDCHANGING not working as expected.


D3fr0s7
 Share

Recommended Posts

I'm trying to make it so that any given window is unable to be resized or moved. I'm using the function _WinAPI_SetWindowLong() and _WinAPI_SetWindowPos(). I also added $SWP_NOSENDCHANGING so as to disable the window's call to move when dragged with the mouse, and removed $SWP_FRAMECHANGED, as I didn't need it in my case, Win11, apparently the sizing box went away without having to send the framechanged parameter. However, it didn't disable that window-moving function, it seems as though $SWP_NOSENDCHANGING does nothing in this instance. Here is the code I'm working with:

#include <WinAPISysWin.au3>

$hWnd = WinGetHandle( "[CLASS:CabinetWClass]")
If @error Then
    MsgBox( 0, "", "FileExplorer window not found.")
    Exit
EndIf

$iStyle = _WinAPI_GetWindowLong( $hWnd, $GWL_STYLE)
$iStyle = BitXOR( $iStyle, $WS_SIZEBOX)
_WinAPI_SetWindowLong( $hWnd, $GWL_STYLE, $iStyle)
_WinAPI_SetWindowPos( $hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR( $SWP_NOSENDCHANGING, $SWP_NOMOVE, $SWP_NOSIZE))

I also tried it with $SWP_FRAMECHANGED in the SetWindowPos() flags just in case, but it didn't help. If anything, $SWP_FRAMECHANGED just adds an ugly thicker border around the window, I don't need it to update the window after removing the sizing box, to reiterate, it is changed without having to do so. Am I using $SWP_NOSENDCHANGING wrong?

I am trying to disable the size box AND prevent the window from being able to be moved. Any help would be appreciated!

I'm using a file explorer window for the test, so make sure it is open before running the code, and if it doesn't remove the sizing box for you, maybe you do need $SWP_FRAMECHANGED.

Here is the MSDN reference if needed: 
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanging

Edited by D3fr0s7
corrected code
Link to comment
Share on other sites

You cannot do anything you want to another process window.  For security reasons. Your example uses Window Explorer -- but what is the real application you are trying to force it like that ?  And most importantly why ?

Edited by Nine
Link to comment
Share on other sites

@Nine It is in fact Windows Explorer I'd like to force like that.

Why is the WinAPI function flag available if it doesn't specifically affect Windows programs? That doesn't make sense to me, but maybe I'm mistaken... It's in the MSDN reference files, it makes me think that it is able to be applied to windows programs. Every other flag works properly except for that one. Does it only work for script-created GUIs? And at that point, why do other flags work such as disabling the resize function, or the minimize and maximize funtions.

Is there a way I can work around this limitation you say exists? I appreciate the help, but telling me I'm at a dead end when I know that I cannot go forward isn't really help per se...

Edited by D3fr0s7
Link to comment
Share on other sites

@Nine You helped me in another thread that I started:

where I was looking for another way to do what I am trying to do in this thread. I was thinking I could get the title bar and disable mouse dragging my letting go of the mouse and changing the active window to drop the window being dragged, but for that to work I would've needed the size of the title bar, which is variable per window. I can totally make a script that does that, drop the mouse click and hold, but I still want to be able to affect the items in folders, and this made registering double clicks in Windows Explorer unreliable. I still also want to be able to affect the menu items, and using a script that disables mouse input would have to be restricted to the clicks made within the title bar area.

I stumbled upon the $SWP_NOSENDCHANGING flag in _WinAPI_SetWindowPos() function. I figured if I can disable the function of clicking and dragging a window, then that's perfect and what I needed. So do you have a solution? I know I can't do it this way, I can see that. I was just wondering if the flag was even working properly, as I looked it up and couldn't find any forum posts about its usage.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...