Jump to content

[SOLVED] Trying to disable maximize, minimize and resize boxes from window


 Share

Recommended Posts

I am at the point of burn out. I have a little notepad window I am trying to turn off the ability to minimize, maximize or resize. I am missing someting:

$PriorityHandle = WinGetHandle("TestThree.txt - Notepad")

WinActivate($PriorityHandle)

$iStyle = _WinAPI_GetWindowLong($PriorityHandle, $GWL_STYLE)

$iStyle = BitXOR($iStyle, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)

GUISetState($iStyle, $PriorityHandle)

Can anyone clue me in :)

Edited by CountyIT
Link to comment
Share on other sites

Hi,

GUI* functions are used to manipulate GUIs created with your script, not external windows.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Global $hWnd, $iStyles

$hWnd = WinGetHandle("[CLASS:Notepad]")

$iStyles = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)

_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitXOR($iStyles, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))

Edit : Fixed code so the window is not "disabled" after setting the new styles, which is not far from yours : shame !

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Thanks FireFox! I see one obvious blunder on my part. Not using _WinAPI_SetWindowLong to set the style. Is that what you were refering to above in the "Edit : Fixed code so the window is not "disabled" after setting the new styles, which is not far from yours : shame !" or was that a comment to yourself?

I have seen references to the comment you made "GUI* functions are used to manipulate GUIs created with your script, not external windows" many times. I am going to confess. The script I am writing does nothing but manipulate external windows. You think I am going to wind up in big trouble here?

Link to comment
Share on other sites

I like to learn :) What was it that I did in the original script that would have disabled the WIndow? The GUISetState($iStyle, $PriorityHandle)?

This script I am writing runs in the background and manipulates a major commercial package. The instance above is just one small example. You mentioned it and I have seen it mentioned before. That these AutoIt Window manipulation functions were designed to be used with AutoIt Scripts and not external Windows. I am using AutoIt strictly to manipulate external Windows. So far it has been working great but do you think it is just a matter of time until I crash and burn?

Link to comment
Share on other sites

What was it that I did in the original script that would have disabled the WIndow?

No, it was in my code before the edit, I was setting "non complete styles" (something like this) that blocked the window.

This script I am writing runs in the background and manipulates a major commercial package. The instance above is just one small example. You mentioned it and I have seen it mentioned before. That these AutoIt Window manipulation functions were designed to be used with AutoIt Scripts and not external Windows. I am using AutoIt strictly to manipulate external Windows. So far it has been working great but do you think it is just a matter of time until I crash and burn?

It depends on the external applications you want to deal with; if their controls are easy to read then It's not a problem and autoit has been made at first for automating.

You have still the forum and the great helpfile, you won't crash :D

Br, FireFox.

Link to comment
Share on other sites

Keep this MSDN comment on SetWindowLong in mind.

Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.

Edited by KaFu
Link to comment
Share on other sites

#include <Constants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$iPID = Run("notepad.exe")
Global $hWnd, $iTimer = TimerInit()
While Not IsHWnd($hWnd)
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    Sleep(10)
    If TimerDiff($iTimer) > 5000 Then
        MsgBox(0, "", "Notepad Window not found in time...")
        Exit
    EndIf
WEnd

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...