Jump to content
Sign in to follow this  
CountyIT

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

Recommended Posts

CountyIT

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

Share this post


Link to post
Share on other sites
FireFox

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
CountyIT

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?

Share this post


Link to post
Share on other sites
FireFox

or was that a comment to yourself?

No that was for you :D

You think I am going to wind up in big trouble here?

What do you mean?

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
CountyIT

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?

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
CountyIT

Once again a million thanks!

Share this post


Link to post
Share on other sites
KaFu

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
  • Like 1

Share this post


Link to post
Share on other sites
CountyIT

Thanks for the info KaFu. I knew I was missing something. I had to activate a different window then activate mine yet again for the change to take effect. Your way is much more elegant :)

Share this post


Link to post
Share on other sites
KaFu

#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))

Share this post


Link to post
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
Sign in to follow this  

×