0
votes

I have a MDI window containing multiple tabs. What I want to do is to disabled the close event every time the user clicked the exit button on the tab. But I didn't know how to accomplish those. Can anyone please help me with this? Thank you.

Here is the sample tab and exit button I was referring from my question above.

tab.png

and this is what I have so far. Still the window is closing every time i clicked the exit button.

integer ext 
ext = MessageBox("","You are not allowed to close this tab",(Exclamation!),(OK!))

if (ext = 1) then
Open(w_main)
end if
3

3 Answers

0
votes

That's not easy. You should handle with user32.dll api and remove, modify and draw the menubar.

Open Global External Functions tab and insert:

Function uLong GetSystemMenu(object hwnd, boolean bRevert ) LIBRARY "user32.dll" Function uLong RemoveMenu(object hMenu, long nPosition, long wFlags ) LIBRARY "user32.dll" Function uLong DrawMenuBar(object hwnd) LIBRARY "user32.dll"

And now:

menu = GetSystemMenu(window, false) // to disable X
RemoveMenu(menu, HF060, H0)
DrawMenuBar(window)
0
votes

I am surprised your sample code even works. The MessageBox can only return one value the way you have it set up. If you are checking a return code from MessageBox you should have the fourth parameter as YesNo!, YesNoCancel!

I think whoever did this does not know what they are doing, it makes no sense at all there are zero options in this logic.

Do you want it to be a question where the user can respond? If so then do something like:

integer li_rc
li_rc = Messagebox("Confirm your intentions","Do you want to close the tab?",Question!,YesNo!,2) 
if li_rc = 1 then
  // user clicked YES because it is the first option of YesNo!
else
  // user clicked NO because it is the second option of YesNo!
end if

fyi: the last argument is the default button if the user presses enter

The window has closequery event which fires when it is closing, you can perform processing in that event to cause the window to NOT close. I don't know if the tab has anything like this but you could probably fix this question, and then disallow the close. If you just want to tell the user something then just do MessageBox("Message Subject", "Message Body", Exclamation!) there is no need to use OK! which is the default

Here is an idea:

Look in the clicked event of the tab control. There is probably code there that is closing the tab. You could put additional logic to check permissions and bypass the closing logic. Or you could set the ShowPicture property to false if the user is not able to close, or maybe show a different pic, of a disabled looking X.

0
votes

There is no way to "disable the close event", but you can disallow the requested close by scripting the window's CloseQuery event. Script it to return 1 in the cases you want to disallow the close, 0 for the cases where you want the close to continue processing.

Good luck.