2 Proc`s Enable/Disable Sys Win Close gadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

2 Proc`s Enable/Disable Sys Win Close gadget

Post 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
malleo, caput, bang. Ego, comprehendunt in tempore