Page 1 of 1

How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 2:29 pm
by emotta_no
I need to create a dialog, when user to click outside it closes.

Thanks

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 3:16 pm
by FranciscoA

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 4:40 pm
by emotta_no
this topic not helped...

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 6:08 pm
by FranciscoA

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 7:11 pm
by emotta_no
It isn't working. This is code:

Code: Select all  Expand view

#include "fivewin.ch"

Function u_Teste2()
Local oDlg

msgstop(GetFocus())

DEFINE DIALOG oDlg Title "Selecione o Ambiente" FROM 0,0 TO 500,500 PIXEL

@ 01,01 button "teste" action msgstop("1") Size 20,20 Of oDlg
ACTIVATE DIALOG oDlg On Init(DlgEndOnLostFocus(oDlg))




   
Return





    //-------------------------------------------------------------------------//
    STATIC FUNCTION DlgEndOnLostFocus(oDlg)
    Local nI, o
    Local bLost, aAllControls:= {}
   
    CollectControls(oDlg, @aAllControls)

    #Define lFOCUS_APPLICATION ( oWndFromHwnd(GetFocus()) != NIL )
    #Define lFOCUS_NOT_DIALOG  ( AScan(aAllControls, {|o| o:hWnd == GetFocus()}) == 0 )
    #Define ON_FOCUS_LOST      If(lFOCUS_APPLICATION .AND. lFOCUS_NOT_DIALOG, oDlg:End(), NIL)

    FOR nI:= 1 to len(aAllControls)

       o:= aAllControls[nI]
       IF O:bLostFocus != NIL
          bLost:= o:bLostFocus
          o:bLostFocus:= {|x1, x2, x3, x| x:= Eval(bLost, x1, x2, x3),;
                                          ON_FOCUS_LOST,;
                                          x}
       ELSE
          o:bLostFocus:= {|x1, x2, x3, x| x:= NIL,;
                                          ON_FOCUS_LOST,;
                                          x}

       ENDIF

    NEXT
    RETURN NIL

    *
    //-------------------------------------------------------------------------//
    FUNCTION CollectControls(oDlg , aAllControls)
    LOCAL nI, nJ, Obj1 , Obj2

    Aadd(aAllControls, ODLG)

    FOR nI:= 1 TO Len(oDlg:aControls)
       Obj1:= oDlg:aControls[nI]
       Aadd(aAllControls, Obj1)
       IF Obj1:ClassName == "TFOLDER"
          FOR nJ:= 1 TO Len(Obj1:aDialogs)
             Obj2:= Obj1:aDialogs[nJ]
             CollectControls(Obj2 , @aAllControls)
          NEXT
       ENDIF
    NEXT
    RETURN
 

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 9:28 pm
by Antonio Linares
Here you have a working example:

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg

   oDlg:bStart = { || SetCapture( oDlg:hWnd ) }

   ACTIVATE DIALOG oDlg CENTERED ;
      ON CLICK oDlg:End()

return nil

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Tue Jan 21, 2014 11:03 pm
by Marcelo Via Giglio
Hello,

with previous version of FW (10.12) was possible to do

Code: Select all  Expand view

oDlg:bLostFocus := {|| oDlg:end() }
 


but with actual version it isn't possible, you can try to add a control and put the focus in it at start the dialog, and when lost the focus from this control, you can close the dialog. In this way I implement my self calendar

I hope this is what you are searching

regards

Marcelo

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Wed Jan 22, 2014 10:44 am
by emotta_no
Antonio, thanks but

It didn't work. When I click in the dialog is closed. I need

I need to DIALOG be closed only if I click off.

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Wed Jan 22, 2014 12:42 pm
by Antonio Linares
Here you have it:

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg

   oDlg:bStart = { || SetCapture( oDlg:hWnd ) }

   ACTIVATE DIALOG oDlg CENTERED ;
      ON CLICK If( nRow < 0 .or. nCol < 0 .or. ;
                   nRow > oDlg:nHeight - 30 .or. nCol > oDlg:nWidth,;
                   oDlg:End(),)
return nil

Re: How to create a Dialog by clicking outside it closes?

PostPosted: Wed Jan 22, 2014 1:03 pm
by emotta_no
Great Antonio, it worked...

Thanks maestro...