How to disable the Windows Close button

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gkick17
Posts: 5
Joined: 07 Jan 2021 15:21

How to disable the Windows Close button

#1 Post by gkick17 » 04 Mar 2021 17:15

Hi all,

I am in search of a script to disable the windows close button on my database forms.
A tool like NoClose will do it, however it stays in the tray which means it can be disabled.
Also read it can be done via AutoKey, but that also would introduce an additional dependency.
Had a go at the SendMessage post in this forum but could not get it to work.

So I wonder if anyone has some script which would achieve this, the script being run via the shell command on the open forms event. On rare occasions there will be two forms open, but both will have the same title.

Hope this makes sense.

Thanks for your thoughts

aGerman
Expert
Posts: 4098
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to disable the Windows Close button

#2 Post by aGerman » 05 Mar 2021 11:09

Can't be done with pure Batch. Certainly in a PowerShell script or a hybrid.
However, I'm wondering if it's your own application if you're talking about "my database forms". If so, it would be likely easier to create a window without close button from the beginning rather than disabling it using an additional script.

Steffen

gkick17
Posts: 5
Joined: 07 Jan 2021 15:21

Re: How to disable the Windows Close button

#3 Post by gkick17 » 05 Mar 2021 15:23

Thank you Steffen,

Its a custom application in LibreOffice base, the forms just being ordinary writer forms. Assuming every Windows PC these days comes with Powershell would you know of any forum for this ?, Thks

Gerhard

aGerman
Expert
Posts: 4098
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to disable the Windows Close button

#4 Post by aGerman » 06 Mar 2021 06:39

Gerhard,

I'm quite sure you can bind a macro to the open forms event. And I would be surprised if it wouldn't be possible to declare and invoke Win32 platform API functions in LibreOffice. Unfortunately I'm not familiar with LibreOffice macros and besides of that it would be off-topic in this forum. But I still believe that this is the way you should go for. Even in PowerShell you would need platform invocation. And the fact that you would have to search for the target window (while in a macro it would be known already) makes a script solution even worse.

The only thing I can do for you is providing a couple of hints.
- You need the window handle of your form. As to what I found in the internet, there seems to be something like a window.getWindowHandle() method in LibreOffice.
- GetSystemMenu() and DeleteMenu() might be the API functions to delete the close item in the context menu and to gray the X button
- SetWindowLong() or SetWindowLongPtr() (the latter is for 64 Bit processes) might be the API function to make the window a toolwindow which doesn't appear in the task bar.
I think eventually the functionality is quite similar to the xtopmost PowerShell macro that I once wrote.

This having said, there is a reason why there is usually no simple way to disable closing a window. It's been a core functionality of windows for ages and users might be upset if you disable it. In other words - The necessity for disabling the close button is a strong indicator for having a design failure in the program logic. At least think about writing some lines of code to define the behavior of your application when the close button is pressed.

Steffen

gkick17
Posts: 5
Joined: 07 Jan 2021 15:21

Re: How to disable the Windows Close button

#5 Post by gkick17 » 06 Mar 2021 16:15

@aGerman

Hallo Steffen, Thanks for your time...

In principle I agree with your comments, however I am dealing with design flaws of LibreOffice Base which do need some work arounds.
On opening the database the database window containing all db objects can not be hidden by default. This is no good and there is no option like in MS Access to hide the code and the window.
What I can do is run a vbscript to make the container invisible aka

Code: Select all

Dim sFileName, sTitle

sFileName = "sCashFlow.odb"
sTitle = "ERROR"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

If Not oFSO.FileExists(sFileName) Then
   oShell.Popup sFileName & "  - file not found", 10, sTitle, vbCritical + vbSystemModal
   Wscript.Quit 1
End If

' run the file with quotes added 1/0 to toggle Base window visible or not
iRC = oShell.Run("""" & sFileName & """", 0, True)

' Return file error level when exiting script
Wscript.Quit iRC
Only trouble if a user closes an open form he is back to the desktop, however the process is still running in the background and subsequently the db can not be restarted prior to killing the process.

I could fire up the vbscript from a batchfile first doing a task kill, trouble with LO here is, if you kill the process you not only shutdown base, but also spreadshhets and documents as well.

cheers

Gerhard

aGerman
Expert
Posts: 4098
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to disable the Windows Close button

#6 Post by aGerman » 07 Mar 2021 04:45

We can continue this topic offline if you're interested. I'll send you my e-mail via PM.

Steffen

Post Reply