Jump to content

Hide/disable closing x-button


Recommended Posts

Is it possible to hide or disable the upper-right-corner close-window button? I want to run a command prompt doing something, and want the user to see whats going on, but not be able to close that dos window...

Link to comment
Share on other sites

as far as I know you cannot remove the header/Window bar on a windows generated window (hope that makes sense)

However, as an idea only, you could run your dos window application in a full screen or maximized window and create a long narrow gui with the top-most attribute that would cover the minimize/maximize buttons and maybe place a label like " DOS WINDOW OPERATION, PLEASE WAIT.

as long as the text is more to the middle/left it wont matter if your narrow GUI is longer than the screen ( if a user has 640 x 480 display) it would still work

they could still close/minimize on the very bottom bar, however, the message would raise the chance of the end user just watching and not clicking on anything

hope it helps

8)

NEWHeader1.png

Link to comment
Share on other sites

Hi

Did use a variant of the window over dos-promt temporarily. Used a splash-screen with transparency, and made a second script that sets focus to the splashscreen if the user tries to set focus to the promt by clicking it on the taskbar.

But hiding the buttons is nicer, and gafrosts link looks really interesting. I'll give it a go tomorrow.

Link to comment
Share on other sites

Had a go using gafrosts example code, but found I lack one of the include-scripts used; ANYGUI.au3. It seems that this include-script contains the function _GuiTarget, witch is used to get the windows handle. How do I find this include-script? Or is there any other way to get the handle of the currently active window?

(Tried to use @GUI_WINHANDLE but it seems to work only for autoit-created gui-windows....)

Link to comment
Share on other sites

From the help file:

Retrieves the internal handle of a window.

WinGetHandle ( "title" [, "text"])

Parameters

title The title of the window to read.

text [optional] The text of the window to read.

Return Value

Success: Returns a string containing the window handle value.

Failure: Returns "" (blank string) and sets @error to 1 if no window matches the criteria.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

It works :) Thank you!

One more thing, I only want to disable the close button. To be sure to delete the correct menuitem, I tried to get the menustring by using:

$ret2 = DllCall("user32.dll", "str", "GetMenuStringA","hwnd",$hWnd,"int",$menuitemnumber,"ptr",$tmp,"int",$menustringlengthplusone,"str","MF_BYPOSITION")

This syntax does not work, I can't figure out how to do the pointer-parter from autoit. Any ideas?

Link to comment
Share on other sites

That would require the beta version of AutoIt and using the DllStruct* functions

if you wan't to remove the close button only "X" then here's a modified example of what i did for someone else, the "X" should be System menu item 6

#include <Array.au3>
#include <ANYGUI.au3>
#include <guiconstants.au3>
#Include <GuiTab.au3>

Opt ("WinTitleMatchMode", 3)
Opt ("WinWaitDelay", 0)
Opt ("GUIOnEventMode", 1)

Const $MF_BYCOMMAND = 0x0
Const $MF_BYPOSITION = 0x400
Const $MF_REMOVE = 0x1000

$pid = Run("notepad.exe")
WinWait("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")
$hWnd = _GuiTarget ("Untitled - Notepad", 1)

; *************************
_RemoveSystemMenus($hWnd, 6)
_RemoveMenus($hWnd)
; *************************

$child = _TargetaddChild ("", 0, 0, 5000, 20)
$newtab = GUICtrlCreateButton("+", 0, 0, 20, 20, $BS_ICON + $BS_FLAT)
$closetab = GUICtrlCreateButton("X", 25, 0, 20, 20, $BS_ICON + $BS_FLAT)
$tab = GUICtrlCreateTab(50, 0, 5000, 20)
$tabs = _ArrayCreate (GUICtrlCreateTabItem("Untitled"))
GUICtrlCreateTabItem("")

GUICtrlSetImage($newtab, "shell32.dll", 225, 0)
GUICtrlSetImage($closetab, "shell32.dll", 131, 0)

GUICtrlSetOnEvent($newtab, "onNewTab")
GUICtrlSetOnEvent($closetab, "onCloseTab")

GUISetState(@SW_SHOW)
While WinExists($hWnd)
    $size = WinGetClientSize($hWnd)
    If WinExists($hWnd) Then
        ControlMove($hWnd, "", 15, 0, 20, $size[0], $size[1] - 43)
        ControlMove($hWnd, "", "SysTabControl321", 25, 0, $size[0] - 50, 20)
        ControlMove($hWnd, "", "Button2", $size[0] - 20, 0, 20, 20)
    EndIf
    
    Sleep(100)
WEnd

Func onNewTab()
    _ArrayAdd($tabs, GUICtrlCreateTabItem("Untitled"))
    GUICtrlCreateTabItem("")
EndFunc ;==>onNewTab

Func onCloseTab()
    $curr = _GUICtrlTabGetCurSel ($tab)
    $num = _GUICtrlTabGetItemCount ($tab)
    
    If $curr < $num - 1 Then
        _GUICtrlTabDeleteItem ($tab, $curr)
        _ArrayDelete($tabs, $curr)
        _GUICtrlTabSetCurSel ($tab, $curr)
    ElseIf $num > 1 Then
        _GUICtrlTabDeleteItem ($tab, $curr)
        _ArrayDelete($tabs, $curr)
        _GUICtrlTabSetCurSel ($tab, $num - 2)
    Else
        _ArrayAdd($tabs, GUICtrlCreateTabItem("Untitled"))
        GUICtrlCreateTabItem("")
        _GUICtrlTabSetCurSel ($tab, 1)
        _GUICtrlTabDeleteItem ($tab, 0)
        _ArrayDelete($tabs, 0)
    EndIf
EndFunc ;==>onCloseTab


Func _RemoveMenus($hWnd)
    $ret = DllCall("user32.dll", "int", "GetMenu", "hwnd", $hWnd)
    $h_menu = $ret[0]
    $ret = DllCall("user32.dll", "int", "GetMenuItemCount", "int", $h_menu)
    $m_count = $ret[0]
    For $x = $m_count - 1 To 0 Step - 1
        $ret = DllCall("user32.dll", "int", "DeleteMenu", "int", $h_menu, "int", $x, "int", $MF_BYPOSITION)
    Next
    DllCall("user32.dll", "int", "DrawMenuBar", "hwnd", $hWnd)
EndFunc ;==>_RemoveMenus

Func _RemoveSystemMenus($hWnd, $i_menuitem)
    $ret = DllCall("user32.dll", "int", "GetSystemMenu", "hwnd", $hWnd, "int", 0)
    $h_menu = $ret[0]
;~   $ret = DllCall("user32.dll", "int", "GetMenuItemCount", "int", $h_menu)
;~   $m_count = $ret[0]
;~   For $x = $m_count - 1 To 0 Step - 1
;~       $ret = DllCall("user32.dll", "int", "DeleteMenu", "int", $h_menu, "int", $x, "int", $MF_BYPOSITION)
;~   Next
   $ret = DllCall("user32.dll", "int", "DeleteMenu", "int", $h_menu, "int", $i_menuitem, "int", $MF_BYPOSITION)
EndFunc ;==>_RemoveSystemMenus
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Ok, I also figured out that "close" is menu item 6. I think I will use this for now and have a look again when the next version of autoit is released. "Menu item 6" should probably work on w2k and wxp at least.

Thank you again!

Link to comment
Share on other sites

  • 1 month later...

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