FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour List of Open DIALOG's
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
List of Open DIALOG's
Posted: Mon Oct 06, 2008 10:02 AM
Friends,

How can I get the lsit of Open DIALOGS.

I am using DIALOG's with NOWAIT clause. I want to stop my users from opening the same DIALOG twice. For this I need some function to check whether the DIALOG is already open or NOT

I already know the code to check for Open MDI CHILD windows, But this does not work for DIALOG's.

Can anybody give me a hint on how to check for Open DIALOG's

Code to check MDI CHILD Windows
------------------------------------------------------*
Function wndSetFocus(cTitle)
*------------------------------------------------------*
/* Here is a function to prevent opening more than one copy of a MDI child window.
   It also brings the window to the top and set the focus to it. */
local i:=0,lSuccess:=.f.
cTitle:=upper(cTitle)
For i=1 to len(wndMain():oWndClient:aWnd)
  if upper( wndMain():oWndClient:aWnd[i]:cCaption )=cTitle
     wndMain():oWndClient:aWnd[i]:setFocus()
     lSuccess:=.t.
  endif
Next
Return lSuccess


Regards

Anser
Posts: 167
Joined: Thu Mar 22, 2007 11:24 AM
List of Open DIALOG's
Posted: Mon Oct 06, 2008 10:45 AM
I use next code :
#include "FiveWin.ch"
# include "common.ch"
# include "dbinfo.ch"
GLOBAL EXTERNAL oWnd

# ifdef WITHMDIDLG
//----------------------------------------------------------------------------//
PROC InitMdiDlg()
*****************
IF ! __ObjHasData(oWnd,"aDlg")
	__ObjAddData(oWnd,"aDlg")
END
oWnd:aDlg := {}
RETURN
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
FUNC DelDlg(oDlg , lValid) //, lValid)
**************************
LOCAL el , i := 0
LOCAL bValid := IIF(IsNil(oDlg:bValid) , {||.T.} , oDlg:bValid )
IF ! lValid
	RETURN .F.
END
IF ! __ObjHasData(oWnd,"aDlg")
	RETURN .T.
END
IF ! TestParent(oDlg)
	RETURN .F.
END
FOR EACH el In oWnd:aDlg
	IF oDlg==el
		i := Hb_EnumIndex()
		EXIT
	END
NEXT
IF i > 0
	aDel(oWnd:aDlg,i,.T.)
END
DlgCascade()
RETURN .T.

//----------------------------------------------------------------------------//
PROC DlgCascade()
*********************
LOCAL el , i , nrow := 48 , nRowStep := 28
LOCAL nCol := 5 , nColStep := 25
IF ! __ObjHasData(oWnd,"aDlg")
	RETURN
END
FOR EACH el In oWnd:aDlg
		IF IsIconic(el:hWnd)
			//ShowWindow(el:hWnd , 1)
			LOOP
			//trace(nrow,ncol,IsIconic(el:hWnd),el:nBottom,GetSysMetrics(1) - 80)
		ELSE
			el:move(nrow,nCol, , ,.T.)
		END
		//el:move(nrow,nCol, , ,.T.)
		# ifdef TESTFNT12
		IF el:nBottom > GetSysMetrics(1) - 80 // 80 , willekeurig na enig testen
			nRow -= (el:nBottom - GetSysMetrics(1)   + 80)
			//trace(nrow,ncol,IsIconic(el:hWnd),el:nBottom)
			el:move(nrow,nCol, , ,.T.)
		END
		# else
		IF el:nBottom > GetSysMetrics(1) - 80 // 80 , willekeurig na enig testen
			nRow -= nRowStep
			el:move(nrow,nCol, , ,.T.)
		END
		# endif
		nrow += nRowStep
		nCol += nColStep
NEXT
RETURN
***************************************************************************************************
PROC InitDlg(oDlg)
******************
LOCAL bValid := IIF(IsNil(oDlg:bValid) , {||.T.} , oDlg:bValid )
AADD(oWnd:aDlg , oDlg)
SetActiveWindow(oDlg:hWnd)
DlgCascade(oDlg)
oDlg:bValid := {||(DelDlg(oDlg , EVAL(bValid , oDlg)))}
SetActiveWindow(oDlg:hWnd)
RETURN
************************************************************************************
PROC AddMdiDlg(oMenu)
*********************
   MENUITEM "Open &vensters"
   MENU
      MENUITEM "&Selecteer Dialog"   ACTION SelDlg() ;
         MESSAGE "Dialog kiezen uit Dialog titels" ;
         //WHEN Len( oWnd:aDlg ) > 0

			MENUITEM "&Cascade" ACTION DlgCascade() ;
         MESSAGE "Overlappenede dialog's" ;
         //WHEN Len( oWnd:aDlg ) > 0


      SEPARATOR


      MENUITEM "&Iconize All"     ACTION DlgIconizeClosAll(.F.) ;
         MESSAGE "Iconize all open dialog's" ;
         //WHEN Len( oWnd:aDLg ) > 0

      MENUITEM "C&lose All"       ACTION DlgIconizeClosAll(.T.);
         MESSAGE "Close all open windows" ;
         //WHEN Len( oWnd:aDlg ) > 0
   ENDMENU

return nil
**************************************************************************************************
PROC SelDlg(cTit , lExact )
***************************************
// met cTit , geeft oDlg terug !!!!!!!!!!!!!
LOCAL el , selrec , aDlg[0]
LOCAL Block , i
IF ! __ObjHasData(oWnd,"aDlg")
	RETURN
END
IF IsNil(cTit)
	FOR EACH el In oWnd:aDlg
		AADD(aDlg,el:cCaption)
	NEXT
	IF LEN(oWnd:aDlg) > 1
		selrec := eenselx(aDlg,"Selecteer dialog")
	ELSE
		selrec := 1
	ENDIF
	IF VALTYPE(selrec) == "N" .AND. (selrec > 0 .AND. Selrec <= LEN(oWnd:aDlg) )
		IF IsIconic(oWnd:aDlg[Selrec]:hWnd)
			ShowWindow(oWnd:aDlg[Selrec]:hWnd , 1)
		END
		SetActiveWindow(oWnd:aDlg[selrec]:hWnd)
	END
ELSE
	cTit := UPPER(cTit)
	DEFAULT lExact := .F.
	IF lExact
		Block := {|j|UPPER(j:cCaption) == cTit }
	ELSE
		Block := {|j|UPPER(j:cCaption) = cTit}
	END
	FOR EACH el In oWnd:aDlg
		IF EVAL(Block,el)
			i := Hb_Enumindex()
			EXIT
		END
	NEXT
	IF IsNumber(i)
		SetActiveWindow(oWnd:aDlg[i]:hWnd)
	END
END
RETURN //nil
**************************************************************************************
PROC DlgIconizeClosAll(lMode)
*****************************
LOCAL el
DEFAULT lMode := .F. // Iconize else clos
IF ! __ObjHasData(oWnd,"aDlg")
	RETURN
END
FOR EACH el In oWnd:aDlg
	IF lMOde
		el:bValid := {||.T.}
		el:end()
	ELSE
		ShowWindow(el:hWnd , 6 )  // 6 : SW_MINIMIZED
	end
NEXT
RETURN
**************************************************************************************
PROC DlgDisEnable(lMOde)
************************
LOCAL el
DEFAULT lMode := .F. // Disable
IF ! lMode
	oWnd:oMenu:Disable()
ELSE
	oWnd:oMenu:Enable()
END
IF ! __ObjHasData(oWnd,"aDlg")
	RETURN
END
FOR EACH el In oWnd:aDlg
	IF lMode
		el:enable()
	ELSE
		el:Disable()
	end
NEXT
RETURN
********************************************************************************************
Func CheckMdiDlg(cTit , nPos , lIn , nLen)
**********************
LOCAL el , lOk := .F.
IF ! IsNil(nLen)
	lIn := .F.	
END
DEFAULT lIn := .F. , nLen := LEN(cTit) 
FOR EACH el IN (oWnd:aDlg)
	IF IIF(lIn , (UPPER(cTit) IN UPPER(el:cCaption)) , UPPER(el:cCaption) = LEFT(UPPER(cTit),nLen))
		lOk := .T.
		nPos := HB_EnumIndex()
		EXIT
	END
NEXT
RETURN (lOk)
********************************************************************************************
Proc SetMdiDlg(cTit , lExact)
*****************************
LOCAL el , Block , i
cTit := UPPER(cTit)
DEFAULT lExact := .F.
IF lExact
	Block := {|j|UPPER(j:cCaption) == cTit }
ELSE
	Block := {|j|UPPER(j:cCaption) = cTit}
END
FOR EACH el In oWnd:aDlg
	IF EVAL(Block,el)
		i := Hb_Enumindex()
		EXIT
	END
NEXT
IF ! IsNil(i)
	SetActiveWindow(oWnd:aDlg[i]:hWnd)
END
RETURN
****************************************************************************************
FUNCTION SeekDlgHandle(hWnd)
*****************************
LOCAL el , oDlg
FOR EACH el IN oWnd:aDlg
	IF el:hWnd == hWnd
		oDlg := el
		EXIT
	END
NEXT
RETURN oDlg
****************************************************************************************
PROCEDURE DlgParent(oDlg,hWnd)
*****************************
IF ! __ObjHasData(oDlg,"DlgParent")
	__ObjAddData(oDlg,"DlgParent")
END
oDlg:DlgParent := SeekDlgHandle(hWnd)
RETURN
****************************************************************************************
FUNCTION TestParent(oDlg)
*************************
LOCAL el , lOk := .T.
FOR EACH el IN oWnd:aDlg
	IF __ObjHasData(el,"DlgParent") .AND. ! IsNil(el:DlgParent)
		IF el:DlgParent == oDlg
			lOk := .F.
			SetActiveWindow(el:hWnd)
			//oDlg:SetFocus()
			EXIT
		END
	END
NEXT
RETURN lOk
# endif


In the main module , before activating the MDI window :

InitMdiDlg(oWnd)

In buildmenu

AddMdiDlg(@oMenu)


Then opening and activating a dialog :
DEFINE DIALOG oDlg RESOURCE "TESTXbrowse" OF oWnd TITLE cTit
...
ACTIVATE DIALOG oDlg NOMODAL;
ON INIT InitDlg(oDlg , .T. )) ;

cTit must be unique , dialog's are recognised by cTit

Frank
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 05:20 AM

Thank you Mr.Frank.

I understand that there are no inbuilt functions to handle NON MODAL DIALOG's like the way MDI CHILD Windows are handled. We will have to keep track of each NON MODAL DIALOG thru our code itself.

Once again thank you very much for the code.

Regards

Anser

Posts: 167
Joined: Thu Mar 22, 2007 11:24 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 10:13 AM

In previous code , to test a dialog is open you must :

IF CheckMdiDlg(cTit,@nPos , .T. )
SetActiveWindow(oWnd:aDlg[nPos]:hWnd)
IF IsIconic(oWnd:aDlg[nPos]:hWnd)
ShowWindow(oWnd:aDlg[nPos]:hWnd , 1)
END
RETURN
END

When a record from a database is edited , you can also check that the record is locked by the user .

Locking the record :

DbrLock(Recno())

Checking if it is locked by the user :

ASCAN(DbrLockList(),Recno()) > 0

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 10:24 AM

Dear Mr.Frank

I did not understand GLOBAL EXTERNAL oWnd in your code. What exactly it does.

Regards

Anser

Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 10:40 AM

GLOBAL EXTERNAL is a xHarbour Extension to declare memory variables with a global scope. This ones are resolved by compiler.

Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
Posts: 167
Joined: Thu Mar 22, 2007 11:24 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 11:04 AM
anserkk wrote:Dear Mr.Frank

I did not understand GLOBAL EXTERNAL oWnd in your code. What exactly it does.

Regards

Anser


In the main module (or the module where the MDI window oWnd is openen)is declared :

GLOBAL oWnd

In the other modules

GLOBAL EXTERNAL oWnd

Now oWnd can be used in each module , without passing it as a parameter

In Clipper (or Harbour) we could :

Declare ownd in main as Static :

STATIC oWnd

In main.prg make a function oWnd() :

Function oWnd()
RETURN oWnd

In the other modules we can now use oWnd() , which returns the MDI variable oWnd

Frank
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
List of Open DIALOG's
Posted: Tue Oct 07, 2008 11:09 AM

Thankyou Mr.Biel and Mr.Frank

Understood the possibilty of GLOBAL EXTERNAL

Regards

Anser

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
List of Open DIALOG's
Posted: Fri Oct 10, 2008 07:26 AM
Thankyou Mr.Antonio, Mr.James & Mr.Frank

I am able to control multiple openings of NON MODAL DIALOG's with the following codes.

Mr.Antonio's Code
#include "FiveWin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg TITLE "Modal" FROM 3, 3 TO 15, 40

   @ 2, 2 BUTTON "Search" ACTION MsgInfo( SearchNonModal( "Non modal" ) )

   @ 2, 10 BUTTON "Create" ACTION CreateNonModal()

   ACTIVATE DIALOG oDlg ;
      ON INIT CreateNonModal()

return nil

function SearchNonModal( cNonModalTitle )

return AScan( GetAllWin(), { | o | ValType( o ) == "O" .and. ;
              Upper( o:ClassName() ) == "TDIALOG" .and. o:cTitle == "Non modal" } )

function CreateNonModal()

   local oDlg

   if SearchNonModal( "Non modal" ) != 0  // the non modal is already created
      MsgAlert( "already exists" )
      return nil
   endif   
   
   DEFINE DIALOG oDlg TITLE "Non modal"
   
   ACTIVATE DIALOG oDlg NOWAIT CENTERED
   
return nil


Mr.James Bott's Code

#include "Fivewin.ch"


#define GW_HWNDFIRST 0
#define GW_HWNDLAST  1
#define GW_HWNDNEXT  2
#define GW_HWNDPREV  3
#define GW_OWNER     4
#define GW_CHILD     5


#define SW_NORMAL 1
#define SW_HIDE         0
 


FUNCTION MAIN()

    LOCAL hWnd := FINDWND( "Window Title" )

    IF !EMPTY( hWnd )
        ? GETWINDOWTEXT( hWnd )
        SHOWWINDOW( hWnd, SW_HIDE )
    ELSE
        ? "Window not found"
    ENDIF

    RETURN NIL


FUNCTION FINDWND( cTitle )

    LOCAL hWnd := GETWINDOW( GETDESKTOPWINDOW(), GW_CHILD )

    WHILE hWnd != 0
        IF UPPER( cTitle ) $ UPPER( GETWINDOWTEXT( hWnd ) )
            RETURN hWnd
        ENDIF

        hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
    ENDDO

RETURN NIL


I would also like to change/correct my statement posted above in this thread, so that beginners like me will not get wrong information.

Statement

I understand that there are no inbuilt functions to handle NON MODAL DIALOG's like the way MDI CHILD Windows are handled. We will have to keep track of each NON MODAL DIALOG thru our code itself.



Regards

Anser

Continue the discussion