Closing Child window - winapi Case WM

General FreeBASIC programming questions.
Post Reply
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Closing Child window - winapi Case WM

Post by peter-cat »

Hello,

I've been created an app presented on the picture below:
https://drive.google.com/open?id=1NVTG4 ... JxUjH5zG5j

Pressing 1. button shows the window with chart. This window appears thanks to the Procedure:

Code: Select all

Sub Balistic_Curve(Wy As Double, Voy As Double, Cd As Double, p As Double, S As Double, m As Double)
'' Make new dialog screen
Screen 20 ' Here is the new window accelerator
' The code of procedure is hidden
End Sub
When I try to close the created child window by pressing 2. button, it does not work.
Only closing the parent (main app) window by pressing 3. button has effect: both windows are closed.

My question is what kind of WM_... should I use to pass the code below:

Code: Select all

Function DlgProc(ByVal hWin As HWND,ByVal uMsg As UINT,ByVal wParam As WPARAM,ByVal lParam As LPARAM) As Integer
	Dim As Long id, Event
	Dim hChildWin As HWND   ' Handler to the child window
	Static As Double Wy, Uyo, Voy, k, Cd, p, S, m, t
	Static As String*13 WyS, UyoS, VoyS, kS, CdS, pS, SS, mS, tS

	Select Case uMsg
		Case WM_INITDIALOG
		
		
			'
		Case WM_CLOSE
			EndDialog(hWin, 0)
			'
		Case WM_DESTROY                ' What kind of WM_... should I Use ???
			CloseWindow(hChildWin)  ' Closing the child window, right ???
			'
		Case WM_COMMAND
			id=LoWord(wParam)
			Event=HiWord(wParam)
			Select Case id
				Case IDC_BTN1
					GetDlgItemText(hWin, IDC_EDT3, WyS, Sizeof(WyS))
					GetDlgItemText(hWin, IDC_EDT7, CdS, Sizeof(CdS)) 
					GetDlgItemText(hWin, IDC_EDT6, pS, Sizeof(pS)) 
					GetDlgItemText(hWin, IDC_EDT5, SS, Sizeof(SS)) 
					GetDlgItemText(hWin, IDC_EDT4, mS, Sizeof(mS))
					Wy = Val(WyS)
					Voy = Val(VoyS)
					Cd = Val(CdS)
					p = Val(pS)
					S = Val(SS)
					m = Val(mS)
					Balistic_Curve(Wy, Voy, Cd, p, S, m)  ' The child window appears.
					hChildWin = GetWindow(hWin, 5)      ' Getting Handler to the child window, right ???
					'
				Case IDC_BTN2

					'
					'
			End Select
		Case WM_SIZE
			
			'
		Case Else
			Return FALSE
			'
	End Select
	Return TRUE

End Function
Can Anybody tell me how to manage with closing child window?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Closing Child window - winapi Case WM

Post by MrSwiss »

See: DestroyWindow() - Function (Microsoft Documentation).
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Closing Child window - winapi Case WM

Post by peter-cat »

OK, thanks, but my question is: What message is obtained when I click the [x] close button of the child window? And how can I indicate it in the procedure of system events ? I do not know the message obtained after clicking the child window close button and I do not know the command (WM.. or something else) that can indicate event of closing window.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Closing Child window - winapi Case WM

Post by MrSwiss »

peter-cat wrote:What message is obtained when I click the [x] close button of the child window?
WM_DESTROY

It needs to be handled in: WindowProc callback function

Btw. WIN-API isn't suitable for beginners (in any language).
Reason: its complex, with its layering of functionalites ... (e.g. messaging, here).
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Closing Child window - winapi Case WM

Post by peter-cat »

Thank YOU!
Could You please show me how to write the WindowProc callback function and where can I place it to obtain expected result (closing the child window)? This is my last question. I can not find it in any other forum... :( Or maybe there is some similar app in FreeBasic.net forum that works in similar way (shows child window that can be closed)? Could you provide some link to finished and working app code ?
It will help to absolutely resolve my funny simple problem, as I am really the beginer :) Or may you refer me to more simple way than windows api (some library that helps to built win GUI apps similar to Delphi or Visual C but for Freebasic) ?
Greetings! It's my last questions in this post.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Closing Child window - winapi Case WM

Post by MrSwiss »

Just a quick search result, from Platforms/Windows: Many Windows Open at Same Time...a challenge!
See the second posts code ...
Maybe not exactly what you are looking for but, gives a general idea.
(meaning: you may have to modify the code, for your intended purpose)
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Closing Child window - winapi Case WM

Post by sancho3 »

I think the problem here is that you are creating an FBGFX screen which is not a child of your api windows. At least it is not directly,.
For the button command you should be able to just use the command Screen 0 to close the graphics window.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Closing Child window - winapi Case WM

Post by peter-cat »

Hello !
Thanks for all the support! Sancho3 ->> YES, that was the problem with the specific type of window, showing by command: 'Screen'.

Adding: 'Sleep' and next line: 'Screen 0' at the end of procedure, solves the problem! The window can be closed by pressing any key or clicking the close [x] button. I was just supposing that problem can be caused by using the 'Screen' command, so that's why I had provided you code of Sub.
Mr Swiss ->> I' ll check the code, it should be useful ;)
Solved!
Thanks a lot!

The properly working code:

Code: Select all

Sub Balistic_Curve(Wy As Double, Voy As Double, Cd As Double, p As Double, S As Double, m As Double)
'' Make new FBGFX screen
Screen 20 ' Here is the new GFX Screen generator
' The code of procedure is hidden
Sleep
Screen 0
End Sub
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Closing Child window - winapi Case WM

Post by jj2007 »

peter-cat wrote:When I try to close the created child window
If you click the "x" of a child window, it sends two WM_PARENTNOTIFY messages. The first one has WM_LBUTTONDOWN in the loword of wParam, the second one WM_DESTROY.

Another way to handle this is subclassing, of course.
Post Reply