Bypass window valid statement

Post Reply
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Bypass window valid statement

Post by anserkk »

Friends,

I have a main Window with the following code

Code: Select all | Expand

nScrHeight:=GetSysMetrics(1)  // Screen Height
nScrWidth :=GetSysMetrics(0)  // Screen Width
DEFINE WINDOW oWnd FROM 1, 1 TO nScrHeight, nScrWidth MDI ;
      TITLE "Accounting Software" ;
      MENU  BuildMenu() ;
      COLOR "B/W"

ACTIVATE WINDOW oWnd MAXIMIZED ;
     ON INIT Select_Co();
      VALID MsgYesNo( "Do you want to quit this application ?" ) 


I am calling a function Select_Co() to display a Login Dialog which asks the user for a valid username and password. The dialog also contains a Login Button and Cancel Button.

Suppose the user press the Cancel button, then I need to end the application without executing the Valid statement in the Man Window.

My Intention is that if the user press cancel button from the Login Dialog, then End the application at that point itself without executing the VALID MsgYesNo( "Do you want to quit this application ?" )

I am asking this question just to know whether we have some commands to force the End.

The other possible work around is to use a variable to hold a logical value to identify whether the user pressed cancel button without a proper Login. And use that variable to decide whether to execute the Valid of oWnd.

For eg:

Code: Select all | Expand

ACTIVATE WINDOW oWnd MAXIMIZED;
     ON INIT Select_Co();
      VALID if(mValidLogin,MsgYesNo( "Do you want to quit this application ?" ),.T.)   



I just wanted to know whether other alternatives are availabe or not and that I am doing it in the right way or not.

Regards

Anser

Screen Snapshots

Login Screen
Image

Main Window Valid screen
[img=http://img214.imageshack.us/img214/9291/exitconfirmationsf2.th.jpg]

If you notice my Login screen, the size of the text box for user name and password different. I need the text box of both the usname and password to be same.

Right now I have used to say and get. The fields variable size of both usrname and password are different. Is there any way to overcome this display problem faced by me.

My code for the Login Dialog

Code: Select all | Expand

mUserName:=spac(30)  *--- See the variable size it is 30
mPass:=spac(20)         *--- Size is only 20

DEFINE DIALOG oDlg TITLE "Login"

@01,02 say "Login Name"
@02,02 say "Password"

@01,06 get mUserName picture "@!" valid !empty(mUserName)
@02,06 get mPass picture "@!" valid !empty(mPass)
@03,08 BUTTON oBtn PROMPT "Login" ACTION { ||  mResult:=ValidateLogin(),;
                                    if(mResult,oDlg:End(),if(nNoOfTries > 2,oWnd:End(),) ) } 
@03,15 BUTTON "Cancel" ACTION { oDlg:End(),oWnd:End()} CANCEL   

ACTIVATE DIALOG oDlg CENTERED


Right now I am not used with using the resources to design the dialogs and windows. I thought I will try by the coding way and later as I advance in my learning skills I' ll start using the resources and the usage of "redefine".

Regards

Anser[/img]
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Post by Antonio Linares »

Here you have a working example. Please notice the use of SIZE in the GETs (can be used for other controls too) and how oWnd:bValid is set to nil:

test.prg

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT Login( oWnd ) ;
      VALID MsgYesNo( "Do you want to end ?" )

return nil

function Login( oWnd )

   local oDlg, mUserName := Space( 30 ), mPass := Space( 20 )

   DEFINE DIALOG oDlg TITLE "Login"

   @ 01, 02 SAY "Login Name"
   @ 02, 02 SAY "Password"

   @ 01.2, 06 GET mUserName PICTURE "@!" VALID ! Empty( mUserName ) SIZE 90, 12
   @ 02.3, 06 GET mPass PICTURE "@!" VALID ! Empty( mPass ) SIZE 90, 12

   @ 03, 08 BUTTON oBtn PROMPT "Login" ;
      ACTION ( mResult := .T., If( mResult,oDlg:End(), If( nNoOfTries > 2, ( oWnd:bValid := nil, oWnd:End() ),) ) ) 
     
   @ 03, 15 BUTTON "Cancel" ACTION ( oDlg:End(), oWnd:bValid := nil, oWnd:End() ) CANCEL   

   ACTIVATE DIALOG oDlg CENTERED

return nil   
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Post by anserkk »

Thankyou Antonio,

You gave me exactly what I needed. By the way I forgot to ask in my post on how to use the mask in get for passwords entries.

Regards

Anser
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Post by Antonio Linares »

@ 02.3, 06 GET mPass PICTURE "@!" VALID ! Empty( mPass ) SIZE 90, 12 PASSWORD
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Post by anserkk »

Antonio Linares wrote:@ 02.3, 06 GET mPass PICTURE "@!" VALID ! Empty( mPass ) SIZE 90, 12 PASSWORD


Thank you Antonio,

Just now I got it from TestPass.Prg in Samples too

Regards
Anser
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Post by Horizon »

Antonio,

How can I control ESC and Close button in this example.

Thanks,

Antonio Linares wrote:Here you have a working example. Please notice the use of SIZE in the GETs (can be used for other controls too) and how oWnd:bValid is set to nil:

test.prg

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT Login( oWnd ) ;
      VALID MsgYesNo( "Do you want to end ?" )

return nil

function Login( oWnd )

   local oDlg, mUserName := Space( 30 ), mPass := Space( 20 )

   DEFINE DIALOG oDlg TITLE "Login"

   @ 01, 02 SAY "Login Name"
   @ 02, 02 SAY "Password"

   @ 01.2, 06 GET mUserName PICTURE "@!" VALID ! Empty( mUserName ) SIZE 90, 12
   @ 02.3, 06 GET mPass PICTURE "@!" VALID ! Empty( mPass ) SIZE 90, 12

   @ 03, 08 BUTTON oBtn PROMPT "Login" ;
      ACTION ( mResult := .T., If( mResult,oDlg:End(), If( nNoOfTries > 2, ( oWnd:bValid := nil, oWnd:End() ),) ) ) 
     
   @ 03, 15 BUTTON "Cancel" ACTION ( oDlg:End(), oWnd:bValid := nil, oWnd:End() ) CANCEL   

   ACTIVATE DIALOG oDlg CENTERED

return nil   
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Post by anserkk »

Hakan,

Code: Select all | Expand

nStyle :=nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION ) // Removes the ? and x from the dialogue title bar
DEFINE DIALOG oDlg TITLE "Login" style nStyle


Regards

Anser
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Post by Horizon »

Thanks Anser,

It removed the ? and x from dialog bar, but ESC key still works.

How can i cancel the ESC key?

Thanks again.


anserkk wrote:Hakan,

Code: Select all | Expand

nStyle :=nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION ) // Removes the ? and x from the dialogue title bar
DEFINE DIALOG oDlg TITLE "Login" style nStyle


Regards

Anser
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Post by Detlef Hoefner »

Hakan,

you may try this:

Code: Select all | Expand

   ACTIVATE DIALOG oDlg VALID !GETKEYSTATE( VK_ESCAPE ) 

Regards,
Detlef
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Post by Antonio Linares »

Full control on ESC and Close:

Code: Select all | Expand

#include "FiveWin.ch" 

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT Login( oWnd ) ;
      VALID MsgYesNo( "Do you want to end ?" )

return nil

function Login( oWnd )

   local oDlg, mUserName := Space( 30 ), mPass := Space( 20 ), lOk := .F.

   DEFINE DIALOG oDlg TITLE "Login"

   @ 01, 02 SAY "Login Name"
   @ 02, 02 SAY "Password"

   @ 01.2, 06 GET mUserName PICTURE "@!" VALID ! Empty( mUserName ) SIZE 90, 12
   @ 02.3, 06 GET mPass PICTURE "@!" VALID ! Empty( mPass ) SIZE 90, 12 PASSWORD

   @ 03, 08 BUTTON oBtn PROMPT "Login" ;
      ACTION ( lOk := .T., oDlg:End() ) 
     
   @ 03, 15 BUTTON "Cancel" ACTION ( lOk := .F., oDlg:End() ) CANCEL   

   ACTIVATE DIALOG oDlg CENTERED

   if ! lOk
      oWnd:bValid = nil
      oWnd:End()
   endif   

return nil   
regards, saludos

Antonio Linares
www.fivetechsoft.com
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Post by Horizon »

Thanks Deflet, Antonio,

Both solution is worked for me.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Post Reply