How to close a window

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

How to close a window

Postby Carlos Herrera » Aug 17, 2018 8:13

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
Posts: 8298
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: How to close a window

Postby fxm » Aug 17, 2018 9:01

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

Re: How to close a window

Postby jj2007 » Aug 17, 2018 9:30

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

Re: How to close a window

Postby fxm » Aug 17, 2018 9:36

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

Re: How to close a window

Postby jj2007 » Aug 17, 2018 11:23

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: 5091
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How to close a window

Postby dodicat » Aug 17, 2018 20:48

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

Re: How to close a window

Postby Carlos Herrera » Aug 17, 2018 20:54

fxm wrote:DestroyWindow(Window_Main) ?

Yes, it works for me. Thank you,
Carlos

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests