Window close button

BlitzMax Forums/BlitzMax Beginners Area/Window close button

Bremer(Posted 2005) [#1]
When creating a window with the "CreateGraphics" command you get a window with a close button on the top right side. Is it possible to create a window without that button, and if so, how?


degac(Posted 2005) [#2]
I think that with the standard MaxGUI commands this is not possibile: the only solution maybe is using the QueryGadget() or some other hack (neither I can use...)


assari(Posted 2005) [#3]
Zawran,
If you are using MaxGUI then it is possible to create windows w/o the close button. See my tutorial on CreateWindow
Othewise as degac pointed out you will need to do some hacking. There's a working example by Kev on this thread
http://www.blitzmax.com/Community/posts.php?topic=50175


degac(Posted 2005) [#4]
Hei assari I read your tutorial and they are great! But where are you write how obtaing window WITHOUT close-gadget? I would like to know 'a clear & standard' way to do it too.


Bremer(Posted 2005) [#5]
I couldn't find it either, and the examples in that thread you linked to, none of them could run in bmax v1.14. They all fail with errors. I am sure that the windows api would have to be used, but I am not that familiar with it to know what to look for.


assari(Posted 2005) [#6]
My apologies guys, I thought you meant Minimize, now I know you mean CLOSE (duh!)

Try this. Stop with the IDE stop button. Don't know how safe this is though :)

hwnd=CreateWindowExA(0,ClassName(),"Hello World".ToCString(),WS_CAPTION|WS_VISIBLE, ..
0,100,640,480,0,0,GetModuleHandleA(Null),Null)

While Not KeyDown(KEY_ESCAPE)
Wend
End


Function ClassWndProc(hwnd,msg,wp,lp) "win32"
	Return DefWindowProcA( hwnd,msg,wp,lp )
End Function

Function ClassName:Byte Ptr()
	Global _name:Byte Ptr
	Global _wc:WNDCLASS
	Global _icon
	
	If _name=Null
		_name="BLITZMAX_WINDOW_CLASS".toCString()
		_icon=LoadIconA(GetModuleHandleA(Null),Byte Ptr(101))
		_wc=New WNDCLASS
		_wc.style=CS_OWNDC|CS_HREDRAW|CS_VREDRAW
		_wc.lpfnWndProc=ClassWndProc
		_wc.hInstance=GetModuleHandleA(Null)
		_wc.hIcon=_icon
		_wc.hCursor=LoadCursorA( 0,Byte Ptr( IDC_ARROW ) )
		_wc.hbrBackground=COLOR_BTNFACE+1
		_wc.lpszMenuName=Null
		_wc.lpszClassName=_name		
		RegisterClassA(_wc)
	EndIf
	Return _name
End Function

I pinched the 2 functions from skidracer's axe module.
BlitzMax CreateGraphics function uses WS_CAPTION|WS_VISIBLE|WS_SYSMENU style. If you're game, you can modify the d3d7graphics.bmx source and remove the WS_SYSMENU from Function CreateHWND


Bremer(Posted 2005) [#7]
Thanks, I'll give it a try. Happy New Year. :)


degac(Posted 2005) [#8]
thanks.
Happy new year...


Bremer(Posted 2006) [#9]
The following code works for me as far as disabling the close button. It won't remove it, but it dims it and the window won't be closed if clicking on it.

Extern "win32"
	Function GetSystemMenu%(hWnd%, bRevert%)
	Function GetMenuItemCount%(hwnd%)
	Function RemoveMenu%(hMenu%, uPosition%, uFlags% )
	Function DrawMenuBar%( hMenu% )
End Extern

Const MF_BYPOSITION:Int = $400
const MF_DISABLED:int = $2

Local hndThisWindow:Int = GetActiveWindow()
Local hndMenu:Int = GetSystemMenu( hndThisWindow, 0 )
Local cnt:Int = GetMenuItemCount(hndMenu)
RemoveMenu(hndMenu, cnt-1, MF_DISABLED | MF_BYPOSITION )
DrawMenuBar( hndThisWindow)


The last five lines are called after creating the window.