FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to create a Dialog by clicking outside it closes?
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM
How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 02:29 PM

I need to create a dialog, when user to click outside it closes.

Thanks

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 03:16 PM
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 04:40 PM

this topic not helped...

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 06:08 PM
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 07:11 PM

It isn't working. This is code:

#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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 09:28 PM

Here you have a working example:

#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Tue Jan 21, 2014 11:03 PM
Hello,

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

Code (fw): Select all Collapse
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
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Wed Jan 22, 2014 10:44 AM

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.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Wed Jan 22, 2014 12:42 PM

Here you have it:

Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Wed Jan 22, 2014 01:03 PM

Great Antonio, it worked...

Thanks maestro...

Posts: 537
Joined: Mon Jan 16, 2006 03:42 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Thu Dec 04, 2025 12:35 AM

Buenas Noches Antionio la funcion SetCapture( oDlg:hWnd )

donde la encuentro

Saludos

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to create a Dialog by clicking outside it closes?
Posted: Thu Dec 04, 2025 03:55 AM

La proporciona FWH en todas sus versiones

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion