I am writing an email monitoring program that needs to run all the time. If the user goes to File -> Exit then it should close. But I don’t want the user to click on the right-hand “x” button to close it. It’s too easy to close it by accident that way.
As Ray Chen says of you hide Close you may frustrate users since it works in every other program. It makes them feel trapped and uncomfortable
In my first post having Close do nothing will also frustrate or confuse. Instead give them a Message when Close button is pressed:
IF ~CloseAllowed THEN
IF Message('if you close this you''re emails will not be blah blah blah', |
'Close?',,'Monitor Email|Stop Email Monitoring' .... ) = 1 THEN CYCLE.
I prefer to not disable controls and leave a puzzle what is needed to enable. I would rather let them click on them then display a message ('You need to enter a yadda yadda…
MAP
CloseButtonDisable(BOOL DisableClose=True) !Disables Close button (False Enable) on the Current Window
MODULE('Win32')
GetSystemMenu(LONG hWnd, BOOL bRevert=False),LONG,PASCAL,DLL(1) !Returns hMenu
EnableMenuItem(LONG hMenu, LONG uIDEnableItem, LONG uEnable ),LONG,PROC,PASCAL,DLL(1) !Returns Prior State
END
END
CloseButtonDisable PROCEDURE(BOOL DisableClose=True) !Disables Close button (False Enable) on the Current Window
hSysMenu LONG,AUTO
uEnable LONG,AUTO
cbSC_CLOSE EQUATE(0F060h)
!MF_BYCOMMAND EQUATE(0) Indicates uIDEnableItem gives the identifier of the menu item i.e. cbSC_CLOSE
!MF_ENABLED EQUATE(0)
!MF_DISABLED EQUATE(2) 2+1 to Disable and make visually Gray
!MF_GRAYED EQUATE(1)
CODE
hSysMenu=GetSystemMenu(0{PROP:Handle},False)
IF hSysMenu THEN
IF DisableClose THEN ! uEnable = 0 + CHOOSE(~DisableClose, 0, 2+1)
uEnable = 0 + 2+1 ! Disable = 0 + 2 + 1 = MF_BYCOMMAND | MF_DISABLED | MF_GRAYED
ELSE
uEnable = 0 + 0 ! Enable = 0 + 0 = MF_BYCOMMAND | MF_ENABLED
END
EnableMenuItem(hSysMenu, cbSC_CLOSE, uEnable)
END
RETURN
I put a warning message on the close window event, which shows up if you click on the close button in the top right corner. The File->Exit menu item allows the program to quit as expected. The blue message on the toolbar tells the rest of the story.
Thanks everyone for pitching in. I always appreciate it and I have learnt a lot more about events and menus too
You could add a Minimize button to the Message to save them the extra step of reading and following your instructions. If they click the Min button set 0{PROP:Iconize}=True
Maybe button text of 'Minimize|Keep Open'. I’d put Minimize first since that’s what you want them to do. I really go to this extra work to make it easy for them to do what I want them to do. And give them button names that are easy to understand, so they don’t have to read the message too well, versus Yes/No buttons require reading and understanding.
I would also add a caption to the Message(, 'eMail Timer') because its good to have a caption. Sometimes the Message can show on the taskbar so blank is bad, mainly shows when underlying window is hide.
It took me a minute … you mean add the program icon to the Message? That would look nice and visually link it. Could also use the frame icon 0{PROP:Icon}.
IF Message('Please use File->Exit to quit |or minimize the window.', |
'eMail Timer', 0{PROP:Icon} ,'Minimize |Keep Open')=1 THEN 0{PROP:Iconize}=1.