Sign in to follow this  
Followers 0
Kiti

make a certain window uncloseable ;)

9 posts in this topic

#1 ·  Posted (edited)

Update: NO BUGS now, it only blocks the specified window. Completly stealth. Move the mouse to the top LEFT corner of the screen to quit.

Here's my script! It has no tray icon, no taskbar box, there's nothing visible on the screen and it only prevents the specified window from beeing closed. Maybe some of you (who are parents), are afraid to let the computer alone to go to the toilet, because their kids will close their all so important work (at least, that's what I'm doing to my father :P ) I've done it with the help of ChrisL's transparent control function. I thought it's something useful for some, and that's why I've decided to post it. Of course some programs has the Files->Exit menu, but this is easily made by putting the transparent box on "Files" and, on click, it sets the state of the second gui to show.

Tell me if you like it, and if you find it useful. :)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

Opt("GUIOnEventMode", 1)


$Form1 = GUICreate("Form1", 0, 0, 1000, -24, BitOR($WS_POPUP, $WS_SYSMENU), -1, WinGetHandle("Program Manager"))
$Label1 = GUICtrlCreateLabel("Label1", -3, -5, 24, 24)
GUICtrlSetOnEvent(-1, "Label1Click")

_GuiCtrlMakeTrans(-1, 1)


While 1
    $b = MouseGetPos()
    If $b[0] > @desktopwidth-24 And $b[1] < 24 Then
        $a = WinGetState("C:\Documents and Settings\Cristian\Desktop\Test.au3 - SciTE") ; SPECIFY WINDOW NAME YOU WANT TO BLOCK HERE
        If BitAND($a, 8) Then
            GUISetState(@SW_SHOW)
        EndIf
    ElseIf $b[0] = 0 And $b[1] = 0 Then
        MsgBox(48, "Bye-Bye!", "Regards, Kiti")
        Exit 0
    Else
        GUISetState(@SW_HIDE)
    EndIf
WEnd


While 1
    Sleep(100)
WEnd



;----------------------FUNCTIONS-------------------------

Func Label1Click()
    MsgBox(262192, "", "Nope, you're not allowed to press that :P")
EndFunc   ;==>Label1Click

Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 Then Return SetError(1, 1, 0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 Then Return SetError(1, 2, 0)
    $aPos = ControlGetPos($pHwnd[0], "", $hWnd);Get the current pos of the control
    If @error Then Return SetError(1, 3, 0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 Then Return SetError(1, 4, 0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 Then Return SetError(1, 5, 0)
    If Not ControlMove($nHwnd, '', $hWnd, 0, 0) Then Return SetError(1, 6, -1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_SHOW, $nHwnd);show the new child gui
    WinSetTrans($nHwnd, "", $iTrans);set the transparency
    If @error Then Return SetError(1, 7, 0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

EndFunc   ;==>_GuiCtrlMakeTrans
Edited by Kiti

Share this post


Link to post
Share on other sites



What if the window is not on top? What if somebody opens another window infront of the 'protected' window? Would there be controls on the top window that get blocked?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

What if the window is not on top? What if somebody opens another window infront of the 'protected' window? Would there be controls on the top window that get blocked?

That's why I've put the If. But now I realized that $a>=32 is not the best condition. I'll have to use BitOr. I'm thinking at what it should be, so only the previously selected window cannot be closed...

While 1
    $a = WinGetState("Title")   ;THE NAME OF THE WINDOW YOU DON'T WANT TO BE CLOSED GOES HERE
    If $a >= 32 Then
        GUISetState(@SW_SHOW)
        $Note_win = WinGetHandle("Form1", "")
WinSetOnTop("Form1", "", 1)
    Else
        GUISetState(@SW_HIDE)
    EndIf
WEnd

I'm having some a little trouble at distiguishing the terms that the window: exists/ is visible/ is enabled/ is active/ is maximized.

When a window is enabled? :)

Edited by Kiti

Share this post


Link to post
Share on other sites

Here's my script! It has no tray icon, no taskbar box, there's nothing visible on the screen and it only prevents the specified window from beeing closed. Maybe some of you (who are parents), are afraid to let the computer alone to go to the toilet, because their kids will close their all so important work (at least, that's what I'm doing to my father :P ) I've done it with the help of ChrisL's transparent control function. I thought it's something useful for some, and that's why I've decided to post it. Of course some programs has the Files->Exit menu, but this is easily made by putting the transparent box on "Files" and, on click, it sets the state of the second gui to show.

Tell me if you like it, and if you find it useful. :)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 0, 0, 1000, -24, BitOR($WS_POPUP, $WS_SYSMENU), -1, WinGetHandle("Program Manager"))
$Label1 = GUICtrlCreateLabel("Label1", -3, -5, 24, 24)
GUICtrlSetOnEvent(-1, "Label1Click")

_GuiCtrlMakeTrans(-1, 1)

While 1
    $a = WinGetState("Title")   ;THE NAME OF THE WINDOW YOU DON'T WANT TO BE CLOSED GOES HERE
    If $a >= 32 Then
        GUISetState(@SW_SHOW)
        $Note_win = WinGetHandle("Form1", "")
WinSetOnTop("Form1", "", 1)
    Else
        GUISetState(@SW_HIDE)
    EndIf
WEnd


While 1
    Sleep(100)
WEnd


;----------------------FUNCTIONS-------------------------

Func Label1Click()
    MsgBox(48, "", "Nope, you're not allowed to press that :P")
EndFunc   ;==>Label1Click


Func _GuiCtrlMakeTrans($iCtrlID, $iTrans = 255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 Then Return SetError(1, 1, 0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 Then Return SetError(1, 2, 0)
    $aPos = ControlGetPos($pHwnd[0], "", $hWnd);Get the current pos of the control
    If @error Then Return SetError(1, 3, 0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 Then Return SetError(1, 4, 0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 Then Return SetError(1, 5, 0)
    If Not ControlMove($nHwnd, '', $hWnd, 0, 0) Then Return SetError(1, 6, -1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_SHOW, $nHwnd);show the new child gui
    WinSetTrans($nHwnd, "", $iTrans);set the transparency
    If @error Then Return SetError(1, 7, 0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

EndFunc   ;==>_GuiCtrlMakeTrans
Can you explain what your script is meant to do? I know you said it was to stop the window being closed but it doesn't and it's not obvious to me how it was meant to.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Can you explain what your script is meant to do? I know you said it was to stop the window being closed but it doesn't and it's not obvious to me how it was meant to.

If you replace that "Title" with an actual name of one of your window, it will really block any attempt to close that window by pressing the top right red button.

My script creates an empty, transparent, always on top label, placed like a shield over the "X" button, to catch any clicks.

The point was to make a loop that sounded like this: "If your window is active, set the state of your label to @SW_show.":

While 1
    $a = WinGetState("Title")
       If BitAnd($a, 8) Then                      ;;;;here's all the problem
        GUISetState(@SW_SHOW)
        $Note_win = WinGetHandle("Form1", "")
        WinSetOnTop("Form1", "", 1)
        sleep(10)
    Else
        GUISetState(@SW_HIDE)
    EndIf
WEnd

But here comes the buggy part, if your window is active, it will activate the label, so it won't be active anymore.

In the first post there, instead of If BitAnd($a, 8) Then is If $a >= 32 Then, and this is true when the window is maximized, but anyone can put another window on top, without minimizing the specified window.

I'm trying to find a way to use WinGetState and an "If" loop with that value (and a BitAnd), without involving the value "8" -- Window is active.

Share this post


Link to post
Share on other sites

If you replace that "Title" with an actual name of one of your window, it will really block any attempt to close that window by pressing the top right red button.

My script creates an empty, transparent, always on top label, placed like a shield over the "X" button, to catch any clicks.

The point was to make a loop that sounded like this: "If your window is active, set the state of your label to @SW_show.":

While 1
    $a = WinGetState("Title")
       If BitAnd($a, 8) Then                      ;;;;here's all the problem
        GUISetState(@SW_SHOW)
        $Note_win = WinGetHandle("Form1", "")
        WinSetOnTop("Form1", "", 1)
        sleep(10)
    Else
        GUISetState(@SW_HIDE)
    EndIf
WEnd

But here comes the buggy part, if your window is active, it will activate the label, so it won't be active anymore.

In the first post there, instead of If BitAnd($a, 8) Then is If $a >= 32 Then, and this is true when the window is maximized, but anyone can put another window on top, without minimizing the specified window.

I'm trying to find a way to use WinGetState and an "If" loop with that value (and a BitAnd), without involving the value "8" -- Window is active.

I did set the title as you noted in your script. I tried 3 different applications and I could close them all. Is it assumed that the window is maximized and the title bar is at the top of the screen? If so that won't work all the time. You would need to find if the window is active then move the label over the title bar wherever it is. Also, you would need to set the parent for the app to a hidden window to stop it appearing in the task bar where someone could select close.

I think it would be easier to hide the application completely and then show it using some hot keys. And if the "Windows Task Manager" appears then close it.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I've finally succeded!! Edited post #1, see it there. Now it's working 100%, no bugs, no other windowses blocked. Completely stealth, put mouse button on the top LEFT corner to close.

Is it assumed that the window is maximized and the title bar is at the top of the screen?

Yes, it only works for a 24x24 pixels square, with the it's up and right edges sticked to the right and up edges of the screen.

You would need to find if the window is active then move the label over the title bar wherever it is.

Yep, this is very simple, it's the same thing, but using the client coords.

Also, you would need to set the parent for the app to a hidden window to stop it appearing in the task bar where someone could select close.

The ONLY place where it appears is it in Processes tab in Task Manager, not on the task bar, nor on the tray.

I think it would be easier to hide the application completely and then show it using some hot keys.

It is hidden completly. I've set that if you put your mouse on the top left corner of the screen it shows up.

And if the "Windows Task Manager" appears then close it.

Share this post


Link to post
Share on other sites

I've finally succeded!! Edited post #1, see it there. Now it's working 100%, no bugs, no other windowses blocked. Completely stealth, put mouse button on the top LEFT corner to close.

Yes, it only works for a 24x24 pixels square, with the it's up and right edges sticked to the right and up edges of the screen.

Yep, this is very simple, it's the same thing, but using the client coords.

The ONLY place where it appears is it in Processes tab in Task Manager, not on the task bar, nor on the tray.

It is hidden completly. I've set that if you put your mouse on the top left corner of the screen it shows up.

Not really...If so, even a noob will close it 100% sure if it just starts task manager. What if I rename the process, so they won't know which one to close?

I don't think you understood what I was trying to say.

I'm not saying this does what you want or that it is better but here is what I was trying to say-

#include <guiconstants.au3>
#include <constants.au3>

Opt("TrayIconHide", 1)
$title = WinGetTitle("")
$hiddenwindow = WinGetHandle($title)
$hGui1 = GUICreate('Parent');, 800, 600, 100, 100, BitOR($WS_POPUP, $WS_SIZEBOX, $GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN))
MsgBox(262144, 'Hide ans Seek', 'To Hide the active window press F8' & @CRLF & 'To bring back the last hidden window press F9' & _
        @CRLF & 'To restore all and quit press F10')
Dim $origparent[20][2], $index = 0
Global $hiddenwindow
HotKeySet("{F8}", "Hide")
HotKeySet("{F9}", "Show")
HotKeySet("{F10}", "Leave")
While 1
    If WinExists("Windows Task Manager") Then WinClose("Windows Task Manager")
    Sleep(100)

WEnd

Func Hide()
    If $origparent[$index][0] <> 0 Then Return
    $title = WinGetTitle("")
    If $title = 'Program Manager' Then
        MsgBox(0, "ERROR", "Can't hide Program Manager")
        Return
    EndIf

    $origparent[$index][1] = WinGetHandle($title)
    $origparent[$index][0] = DllCall("user32.dll", "int", "SetParent", "hwnd", $origparent[$index][1], "hwnd", $hGui1)
    $index += 1
    If UBound($origparent) < $index + 2 Then ReDim $origparent[$index + 5][2]
EndFunc  ;==>Hide

Func Show()
    If $index = 0 Then Return
    If $origparent[$index - 1][0] = 0 Then Return
    DllCall("user32.dll", "int", "SetParent", "hwnd", $origparent[$index - 1][1], "hwnd", $origparent[$index - 1][0])
    WinActivate($origparent[$index - 1][1])
    $origparent[$index - 1][0] = 0
    $index -= 1
;Exit
EndFunc  ;==>Show

Func Leave()
    
    While $index > 0
        Show()
    WEnd
    Exit
EndFunc  ;==>Leave

Func OnAutoItExit()
    
    Leave()
    
EndFunc  ;==>OnAutoItExit

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Wow, that's cool. My fault, I understood that when task manager appears close it, the script. But anyway, I don't want to go that far. The reason I made it was that I had another script with a function on exit. And if another window was closed, it couldn't complete it's last function. This way, I've restricted the order in which the programs can be closed: first, my script and second, the window. This was my actual goal. To prevent closing some other window before the script.

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  
Followers 0