How to close a window

New to FreeBASIC? Post your questions here.
Post Reply
Carlos Herrera
Posts: 82
Joined: Nov 28, 2011 13:29
Location: Dictatorship

How to close a window

Post by Carlos Herrera »

Hi All,
I asked this question before but I did not get any answer, so let me ask
again here. To be more specific consider the following program

Code: Select all

' uses WinGUI(12) by Lothar Schirm
#Include "WinGUI.bi"
Dim As HWND Window_Main, Label_txt
Dim As MSG msg
Window_Main = Window_New	(100, 100, 300, 300, "This window is always open")
Label_txt = Label_New(50, 100, 200, 20, "Still visible when closed",, Window_Main)
Do
	WaitEvent(Window_Main, msg)
Loop Until Window_Event_Close(Window_Main, msg)
Print "How to destroy this window "
Print "and keep program running ? "
Sleep
End
When the window is closed it still hangs around. How to kill the beast?
Carlos
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to close a window

Post by fxm »

DestroyWindow(Window_Main) ?
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: How to close a window

Post by jj2007 »

Just delete the Sleep (you may try a Sleep(2000), too).
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to close a window

Post by fxm »

Have you read the question carefully?
How to destroy this window and keep program running ?
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: How to close a window

Post by jj2007 »

You are right: "keep running". It seems that the WM_DESTROY handler is missing in the library - it relies on ExitProcess killing everything.

So yes, inserting DestroyWindow(Window_Main) after the loop is rude but it will do the job.

P.S.: I've made some tests, the design of Lothar's library is a bit mysterious to me... where do some of the messages go?

Code: Select all

Do
   WaitEvent(Window_Main, msg)
   if msg.message<>WM_MOUSEMOVE and msg.message<>WM_NCMOUSEMOVE then
	 print msg.message; " ";	' works fine
   endif
   if msg.message=WM_CLOSE then
   	print "CLOSING"	' never seen
   endif
   if msg.message=WM_DESTROY then
   	print "DESTROYING"	' never seen
   endif
   if msg.message=WM_LBUTTONDOWN then
   	print "LBUTTONDOWN ";	' works fine
   endif
Loop Until Window_Event_Close(Window_Main, msg)
print "Exit loop"
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How to close a window

Post by dodicat »

..
Last edited by dodicat on Aug 17, 2018 22:00, edited 1 time in total.
Carlos Herrera
Posts: 82
Joined: Nov 28, 2011 13:29
Location: Dictatorship

Re: How to close a window

Post by Carlos Herrera »

fxm wrote:DestroyWindow(Window_Main) ?
Yes, it works for me. Thank you,
Carlos
Post Reply