Question about the focus of a dialog box

Question about the focus of a dialog box

Postby driessen » Fri Sep 12, 2008 2:34 pm

Hello,

I have a question about the focus of a dialog box.

If I have opened a dialog box, I need to execute a procedure if the dialog box gets the focus. I want to link some functions to function buttons F1 - F12. If the dialog box loses the focus, the link to the funcion buttons has to be undone.

To do so, I use this code :
Code: Select all  Expand view
DEFINE DIALOG oDlg NAME ....

......

oDlg:bGotFocus  := { || KEY_ON() }
oDlg:bLostFocus := { || KEY_OFF() }

......

ACTIVATE DIALOG oDlg ....


What is the problem : if the dialog box loses the focus, I have noticed that the link to the function buttons is undone. But if the dialog box gets the focus again (by clicking on the dialog box), the link to the functions buttons is not accomplished.

What do I have to do to repair the link to the function buttons if the dialog box regains the focus ?

Thanks a lot in advance for any help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Fri Sep 12, 2008 7:37 pm

Michel,

Please try this and check if it beeps:

oDlg:bGotFocus := { || MsgBeep(), KEY_ON() }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41351
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Fri Sep 12, 2008 8:14 pm

Antonio,

Thanks for your answer.

I can hear the beep, but only in case if I push a button which is defined in the dialogbox.

If I just click on the dialogbox to make it active (= focus), nothing happens.

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Fri Sep 12, 2008 9:30 pm

Michel,

You have to add this code to Class TDialog:

DATA bNcActivate

...

METHOD NCActivate( lOnOff ) INLINE If( ! Empty( ::bNcActivate ), Eval( ::bNcActivate, lOnOff, Self ),)

And here you have a working example:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg1

   DEFINE DIALOG oDlg1 TITLE "Dialog 1"

   oDlg1:bNCActivate = { | lOnOff | If( lOnOff, MsgBeep(),) }

   @ 2, 2 BUTTON "OK"

   ACTIVATE DIALOG oDlg1 ;
      ON INIT Another()

return nil

function Another()

   local oDlg2
   
   DEFINE DIALOG oDlg2 TITLE "Dialog 2"

   oDlg2:bNCActivate = { | lOnOff | If( lOnOff, MsgBeep(),) }

   ACTIVATE DIALOG oDlg2 NOWAIT CENTERED

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41351
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Fri Sep 12, 2008 10:54 pm

Antonio,

Thanks a lot for your answer.

I'll change the Tdialog class and add it to my library.Will you add this function to the standard Tdialog class in FWH 8.09 ?

See you.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby driessen » Fri Sep 12, 2008 11:20 pm

Antonio,

I changed the TDialog class, as you told me.

Then I changed my code and I tried this :
Code: Select all  Expand view
oDlg:bNCActivate := {|lOnOff| IF(lOnOff,KEY_ON(),KEY_OFF())}

This results in hanging my application when the dialog box loses the focus.

Then I changed my code one again :
Code: Select all  Expand view
oDlg:bNCActivate := {|lOnOff| IF(lOnOff,KEY_ON(),)}
oDlg:bLostFocus  := {|| KEY_OFF()}

This seems to be working fine with only one acception : if the dialog box loses its focus and somewhat later gets the focus back, the title bar looks ray (just like it does not have the focus) although it has the focus (it works OK but the title bar stays gray, even if I click on it).

Any idea ?

Thanks a lot. We are nearly where we have to be.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Sat Sep 13, 2008 12:25 am

Michel,

> Will you add this function to the standard Tdialog class in FWH 8.09 ?

Yes

Something I forgot to comment you is that you must return nil from those codeblocks. Try it this way:

oDlg:bNCActivate := {|lOnOff| IF(lOnOff,KEY_ON(),KEY_OFF()), nil }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41351
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests