Jump to content

Disable Red "X"


 Share

Recommended Posts

Greeting,

Looking for a way to disable the red "X" in the right top cornor of the active window.

for example I use script to launch "notepad.exe" but disable the "X" close so user can not close the notepad window but wait for a while then the script close it

Thanks

usera

Link to comment
Share on other sites

it's 100% doable with help file, you need to set notepad style toosomething that dont have red X. Style I dont remember but when you look at GUICReate from hel... that page has link to possible styles.

edited

Link to comment
Share on other sites

Remove red x...

or just disable it with Opt("GUIEventOptions",1)...

#include <GUIConstantsEx.au3>

Opt("GUIEventOptions",1)

GuiCreate("Sample")
$button = GuiCtrlCreateButton("Close",10,10)
GuiSetState()
While 1
    $sMsg = GuiGetmsg()
    Switch $sMsg
        Case $GUI_EVENT_CLOSE
            ;Do nothing
        Case $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_MINIMIZE)
        Case $GUI_EVENT_RESTORE
            GUISetState(@SW_RESTORE)
        Case $button
            Exit
    EndSwitch

WEnd

Edit:~ While I was writing this I then saw the on an external application bit so this wont be of any use!

Edited by ChrisL
Link to comment
Share on other sites

So the idea is just this.

I use script to launch "notepad.exe" then wait for it open. Since I use script to open it, So for sure I know all the information about the "notepad.exe" include the windows size, buttons. so from there I disable the red "X" button, that is all.

Problem is do Not know how to write the code.

usera

Link to comment
Share on other sites

Credits to Melba23 for finding this. Change 1 to 0 to re-enable:

#include <GuiMenu.au3>
$hWnd=WinGetHandle("[CLASS:Notepad]")
_GUICtrlMenu_EnableMenuItem(_GUICtrlMenu_GetSystemMenu($hWnd), $SC_CLOSE, 1, False)
Link to comment
Share on other sites

Credits to Melba23 for finding this. Change 1 to 0 to re-enable:

#include <GuiMenu.au3>
$hWnd=WinGetHandle("[CLASS:Notepad]")
_GUICtrlMenu_EnableMenuItem(_GUICtrlMenu_GetSystemMenu($hWnd), $SC_CLOSE, 1, False)

thanks

for line

$hWnd=WinGetHandle("[CLASS:Notepad]") if I use winword.exe. what will replace "Notepad" ?

and for winwaitactive("[CLASS:notepad]") same question if I use winword.exe. what will replace "Notepad" ?

thanks

usera

Link to comment
Share on other sites

Use AU3Info.exe in SciTe (look under the Tools Menu) to find the CLASS. I don't use MS Office.

Edit: Or try this code >>

#include <GUIMenu.au3>

Global $PID = Run("Notepad.exe") ; Change to WinWord.exe
Sleep(500)
Global $hWnd = _WinGetHandleByPID($PID)
_GUICtrlMenu_EnableMenuItem(_GUICtrlMenu_GetSystemMenu($hWnd), $SC_CLOSE, 1, False)

Func _WinGetHandleByPID($i_pid, $f_array = False, $f_visibleonly = True)
    If Not IsInt($i_pid) Then $i_pid = ProcessExists($i_pid)

    Local $a_winlist = WinList()
    Local $a_retarray[$a_winlist[0][0] + 1], $i_add

    For $iwin = 1 To $a_winlist[0][0]
        If WinGetProcess($a_winlist[$iwin][1]) = $i_pid Then
            If $f_visibleonly Then
                If BitAND(WinGetState($a_winlist[$iwin][1]), 2) Then
                    If Not $f_array Then Return $a_winlist[$iwin][1]
                    $i_add += 1
                    $a_retarray[$i_add] = $a_winlist[$iwin][1]
                EndIf
            Else
                If Not $f_array Then Return $a_winlist[$iwin][1]
                $i_add += 1
                $a_retarray[$i_add] = $a_winlist[$iwin][1]
            EndIf
        EndIf
    Next

    If Not $i_add Then Return SetError(1, 0, 0)

    ReDim $a_retarray[$i_add + 1]
    $a_retarray[0] = $i_add
    Return $a_retarray
EndFunc

Edit: New version provided by SmOke_N

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Return WinGetHandle(StringSplit(StringTrimRight($sData, 1), Chr(1)))
This makes no sense. Are you suggesting that using WinGetHandle() this way actually enumerates through the StringSplit() array and makes each one a hwnd?

Your vars are a bit confusing too... maybe this is more to the point?

Func _WinGetHandleByPID($i_pid, $f_array = False, $f_visibleonly = True)
    If Not IsInt($i_pid) Then $i_pid = ProcessExists($i_pid)

    Local $a_winlist = WinList()
    Local $a_retarray[$a_winlist[0][0] + 1], $i_add

    For $iwin = 1 To $a_winlist[0][0]
        If WinGetProcess($a_winlist[$iwin][1]) = $i_pid Then
            If $f_visibleonly Then
                If BitAND(WinGetState($a_winlist[$iwin][1]), 2) Then
                    If Not $f_array Then Return $a_winlist[$iwin][1]
                    $i_add += 1
                    $a_retarray[$i_add] = $a_winlist[$iwin][1]
                EndIf
            Else
                If Not $f_array Then Return $a_winlist[$iwin][1]
                $i_add += 1
                $a_retarray[$i_add] = $a_winlist[$iwin][1]
            EndIf
        EndIf
    Next

    If Not $i_add Then Return SetError(1, 0, 0)

    ReDim $a_retarray[$i_add + 1]
    $a_retarray[0] = $i_add

    Return $a_retarray
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I found the Function from here >>

I was perhaps a little too keen to get the code onto the Forum. Thanks for the new version.

With the Variable naming I use the advice from here >> http://www.autoitscript.com/autoit3/udfs/UDF_Standards.htm

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

I found the Function from here >>

I was perhaps a little too keen to get the code onto the Forum. Thanks for the new version.

The stringsplit is fine, but you added WinGetHandle(), remember that StringSplit() returns an array, so essentially, you're getting the handle to nothing the way you modified it.

Anyway, that example shows how to return a window title, [n][0] = title, [n][1] = handle, using them appropriately you can avoid WinGetHandle() all together :) .

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I just wiped my eyes and realised you were Returning the StringSplit() Array. I hope I am allowed this one slip up on here :) I now understand. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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...