Verify if a window is open help

Discussion forum about all things Team Developer 5.x and 6.x
Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Verify if a window is open help

Post by Headcold » 06 Dec 2019, 17:31

Is there any way to check if a window is active or open and if it is close or hide it and if its not do nothing.

Thank you

monchotgu
Honduras
Posts: 72
Joined: 24 Apr 2017, 02:55
Location: Honduras

Re: verify if a window is open help

Post by monchotgu » 09 Dec 2019, 04:10

Hi, What you can do is save the window handle that is returned by the function SalCreateWindow in a Window handle Variable.
On the SAM_Destroy message on the window set the variable to hWndNULL. To check if the window exists check if the varriable is different from hWndNULL, then the window exists and you can bring it to top with the function SalBringWindowToTop.

Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Re: verify if a window is open help

Post by Headcold » 09 Dec 2019, 17:58

thanks

Igor Ivanovic
Site Admin
Site Admin
Croatia
Posts: 1267
Joined: 05 Mar 2017, 12:37
Location: Zagreb, Croatia

Re: verify if a window is open help

Post by Igor Ivanovic » 10 Dec 2019, 09:45

Sometimes it's just inconvenient to save the window handle.
If that's the case you can use something like this:

Code: Select all

Set nType = SalCompileAndEvaluate( 'SalGetWindowState( ' || p_sFormName|| ' )', nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, TRUE, SalContextCurrent() )
If nError = 0
	! if there is no error the window has been created
	! nReturn has on of the window states
	Select Case nReturn
		Case Window_Invalid
			Break
		Case Window_Maximized
			Break
		Case Window_Normal
			Break
		Case Window_Maximized
			Break
		Case Window_Minimized
			Break
	Return TRUE
HTH
Igor Ivanovic
Image

Acclaro
Germany
Posts: 176
Joined: 16 Mar 2017, 08:13
Location: Hannover, Deutschland

Re: verify if a window is open help

Post by Acclaro » 10 Dec 2019, 11:10

take care
if you use the sample and you opend the window twice maybe you get the wrong window.

FRBhote
India
Posts: 2216
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: verify if a window is open help

Post by FRBhote » 11 Dec 2019, 05:24

What would be the best method to prevent a window being opened twice?

Right now we use:

Code: Select all

If bNseFoCSV
	Call SalBringWindowToTop( frmNseFoCSV )
Else
	Set bNseFoCSV = TRUE
	Call SalCreateWindow( frmNseFoCSV, hWndNULL )

Acclaro
Germany
Posts: 176
Joined: 16 Mar 2017, 08:13
Location: Hannover, Deutschland

Re: Verify if a window is open help

Post by Acclaro » 11 Dec 2019, 17:54

small change of your variable bNseFoCSV to
Window Handle: hWndNseFoCSV


If hWndNseFoCSV != hWndNULL
Call SalBringWindowToTop( hWndNseFoCSV )
Else
Set hWndNseFoCSV = SalCreateWindow( frmNseFoCSV, hWndNULL )

in frmNseFoCSV:
On SAM_Destroy
Set hWndNseFoCSV = hWndNULL

if you use hWndNseFoCSV as a global variable or a local /class variable ... and so on depends on your source structure

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests