Page 1 of 1

2 Proc`s Enable/Disable Sys Win Close gadget

Posted: Thu Jan 26, 2017 1:21 pm
by Zebuddi123
Hi to all Just playing and learning came up with these 2 procedures to Enable/Disable the ConsoleWindow or Standard Window`s system close gadget (X) on the fly. OS: Window`s Only

Maybe of interest and use to some !

Example: show`s Disabling/Enabling both windows on the fly via the ConsoleWindow`s inkey()

Code: Select all

Import ""
	GetConsoleWindow() ; required for ConsoleWindow()
EndImport

Procedure EnableConsoleWindowCloseState(State.b) ; state = #True | #False
	Protected hMENU.i
	Select State
		Case #True
			hMENU = GetSystemMenu_(GetConsoleWindow(), #True)
			EnableMenuItem_(hMENU, #SC_CLOSE, #MF_ENABLED)
		Case #False
			hMENU = GetSystemMenu_(GetConsoleWindow(), #False)
			EnableMenuItem_(hMENU, #SC_CLOSE, #MF_GRAYED|#MF_DISABLED)
	EndSelect		
EndProcedure

Procedure EnableWindowCloseState(WinID.i, State.b)
	Protected hMENU.i
	Select State
		Case #True
			hMENU = GetSystemMenu_(WindowID(windowID), #True)
			EnableMenuItem_(hMENU, #SC_CLOSE, #MF_ENABLED)
		Case #False
			hMENU = GetSystemMenu_(WindowID(windowID), #False)
			EnableMenuItem_(hMENU, #SC_CLOSE, #MF_GRAYED|#MF_DISABLED)
	EndSelect		
EndProcedure


; Example enabling/disabling openconsole() and openwindow()
CompilerIf #PB_Compiler_IsMainFile
	If OpenConsole("Enable/Disable System Menu close window")
		PrintN( "d to disable (X) : e to enable(X): x to end program")
		
		OpenWindow(0, 10,10, 200, 300,"Enable/Disable System Menu close window")
		
		Repeat
			ev = WaitWindowEvent(10)
			Select Asc(Inkey())
				Case 'x'
					CloseConsole()
					ev = #PB_Event_CloseWindow
				Case 'd'
					EnableConsoleWindowCloseState(#False)
					EnableWindowCloseState(WindowID(0), #False)
				Case 'e'	
					EnableConsoleWindowCloseState(#True)
					EnableWindowCloseState(WindowID(0), #True)
			EndSelect	
		Until  ev = #PB_Event_CloseWindow
		
	EndIf
	End
CompilerEndIf