Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 9 Monaten
Letzter Beitrag:
vor 9 Monaten
Beteiligte Autoren:
André Labuschagné, Steven Sitas, Stewart Crisler, Al, Peter Holemans

Disable X in Title Bar WD21

Startbeitrag von André Labuschagné am 23.11.2016 10:30

Hi All

How does one disable the X [close button] in the Title Bar without disabling the Close option in the System menu? I want the user to be able to close the app but not with the X in the Title Bar. The only option I am leaving there is the minimize button.



Hi André,

Several options:
- Create a window without a title bar
- Use windows API's to nuke the X-button on the title bar
- Create a new (hidden button) that has the ALT+F4 shortcut. Clicking the X button of the window (or the close option from the system menu) will be redirected to the code in this button allowing you to give more options...

Although, to me it seems to be a very specific busines case as it will break any UI Windows conventions set out... But... I assume you have a valid reason to do it this way.

Best regards,

Peter Holemans

von Peter Holemans - am 23.11.2016 11:00
Hello Andre

Here are some very old procs to turn the X on and off as well as a few other things

PROCEDURE TurnOffSystemMenuX()
// -0x1 Disable Maxime
// -0x2 Disable Minimize
// -0x8 Disable the system menu (icon, max & min buttons, etc)
// -040 Disable tittle bar
// -0x4 Disable resize
LnErrCode is 8byte int = 0

hMenu is system int // Type C :HMENU
uPosition is unsigned int = 6 // Type C :UINT
uFlags is unsigned int = 0x400 // Type C :UINT

hWnd is system int = Handle() // Type C :HWND
bRevert is boolean = 0 // Type C :BOOL

hMenu = API( "USER32", "GetSystemMenu", hWnd, bRevert )
IF NOT API( "USER32", "DeleteMenu", hMenu, uPosition, uFlags ) THEN
LnErrCode = API("KERNEL32","GetLastError")


PROCEDURE TurnOnSystemMenuX()
Masque is 8byte int

GWL_STYLE is 8byte int = -16

RDW_FRAME is system int = 1024
RDW_INVALIDATE is system int = 1
RDW_UPDATENOW is system int = 256

WS_MAXIMIZEBOX is system int = 65536
WS_MINIMIZEBOX is system int = 131072
WS_SYSMENU is system int = 524288

Masque = API("user32","GetWindowLongA",Handle(),GWL_STYLE)

Masque = BinaryOR(Masque,WS_MINIMIZEBOX)
Masque = BinaryOR(Masque,WS_MAXIMIZEBOX)
Masque = BinaryOR(Masque,WS_SYSMENU)


API("User32", "RedrawWindow", Handle(), Null, Null, RDW_FRAME+RDW_INVALIDATE+RDW_UPDATENOW)

von Al - am 23.11.2016 11:29
Hi Peter

A very specific reason for this. It is a very rich communication app with lots of functions that will pop up with messages as part of its function. The user can close the messages and then minimize the app - it always starts at runtime - the X button is too close to the minimize button and the natural tendency for users is to press X after flipping through the messages. That means it is not running and any future messages will not be caught. When minimized and a message is detected it comes to the fore and displays the message. This is one of dozens of functions. If the user wants to close the app we would prefer them to explicitly go to the system menu and close it there. The X is likely to contribute to many accidental closings of the app.

Hope that makes sense.


von André Labuschagné - am 23.11.2016 17:04
Thanks a ton for that code Al. Will try it out.


von André Labuschagné - am 23.11.2016 17:07
Hi Al

That worked but it actually removes the Close entry on the system menu. I am hoping to just disable the X on the title bar. That would be first prize.


von André Labuschagné - am 23.11.2016 17:19
Hi Andre,
then the best solution is to use the ALT-F4 technique that Peter gave you

Steven Sitas

von Steven Sitas - am 23.11.2016 17:54
Hi Steven

I have actually now been able to grey out the X button and that simply greys out the Close option in the system menu as well. I agree that Peter's option seems the best - I wonder if it is possible to halt the exit with a message? That would be ideal. I just want to turn the user's attention to what they are doing and the implications. X does not minimize - that is pretty much it. Will try that now.


von André Labuschagné - am 23.11.2016 17:59
Hi Peter

The Alt-F4 trick does not seem to work. It is not redirected to the button. There must be a spot where one can capture on exit. Looking.......


von André Labuschagné - am 23.11.2016 18:07
Hi All

Found that - on closing the app - but how can I halt a closing if the user agrees that was not the intention? Is there a way of doing that?


von André Labuschagné - am 23.11.2016 18:09
Hi Andre,

Here is the way we do it in the new version of alpha360 ERP (v0.5) - available in a couple of days.

1. On the main window - with the [x] button - we add a Popup Menu, say PopupClose.
2. In the PopupClose we have one Option Called Logout.
3. In this Option - in the code area - we have a YES NO question to the user and if a user chooses YES, we do some "cleaning" and then call EndProgram.

4. We add a BUTTON to this main window, outside the VISUAL area, to the right.
5. This BUTTON has a SHORTCUT equal to ALT+F4
6. On the Click code of this Button we just call OpenPopupMenu(PopupClose)

Thats it ...

Steven Sitas

von Steven Sitas - am 23.11.2016 18:26
Hi Steven

The Alt+F4 on my button is not working. The app just closes. I wonder what could be wrong? Maybe it must be visible. But I have called no visible buttons before.


von André Labuschagné - am 23.11.2016 18:42
Hi Andre,
the Button must be VISIBLE and of course NOT Disabled.
Thats why we add it OUTSIDE the boundaries of our WINDOW - to "hide it" without using HIDE.

Steven Sitas

von Steven Sitas - am 23.11.2016 19:07
Hi Steven

I have it as visible and enabled. Still no go. The app just closes. Must be missing something here.


von André Labuschagné - am 23.11.2016 19:18
Hi Steven

Sorted - the button was on the wrong plane. Place it on zero and boom. Works like a charm.


von André Labuschagné - am 23.11.2016 19:31
I have not tried either of these options but I would consider

(1) WinSystemButton()

(2) In the Close method of the window using ReturnToCapture()

Stewart Crisler

von Stewart Crisler - am 24.11.2016 03:17
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.