home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / LOGON.PRG < prev    next >
Text File  |  1996-05-13  |  3KB  |  129 lines

  1. /////////////////////////
  2. //
  3. //    logon.prg - simple logon/login dialog
  4. //
  5. //    Written by:    John M. Skelton, May-96.
  6. //
  7. //    Copyright (C) 1993-1996 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
  8. //    All Rights Reserved.
  9. //
  10. /////////////////////////
  11.  
  12. #include "windows.ch"
  13. #define    NO_C4WCLASS
  14. #include "commands.ch"
  15. #include "topclass.ch"
  16.  
  17. static    cName, cPass
  18.  
  19.  
  20. function main()
  21. local    oApp, oWnd
  22.  
  23. CREATE APPLICATION oApp                            ;
  24.     WINDOW oWnd                                ;
  25.     TITLE "Clip-4-Win Makes Windows Apps E-A-S-Y!"            ;
  26.     ON INIT DoInit(oWnd)
  27.  
  28. return nil
  29.  
  30.  
  31. static function DoInit(oWnd)
  32. do while !LogonOK(oWnd)
  33. enddo
  34.  
  35. MenuSetup(oWnd)        // or WinExec("MainApp") or whatever
  36. return nil
  37.  
  38.  
  39. static function LogonOK(oWnd)
  40. local    aDlg, nRet
  41.  
  42. // You can use DS_SYSMODAL to keep the user out of the rest of Windows!
  43. CREATE DIALOG aDlg  TITLE "Logon"  AT 100,100 SIZE 115,54        ;
  44.     STYLE /*DS_SYSMODAL+*/ WS_POPUP+WS_CAPTION  IN oWnd
  45.  
  46. @ ID 100 SAY "User name:"     AT 10,12  SIZE 50,10  IN aDlg
  47. @ ID 101 EDIT                 AT 53,10  SIZE 50,14  IN aDlg        ;
  48.   STYLE ES_UPPERCASE + ES_AUTOHSCROLL + CTL_DEFSTYLE + WS_TABSTOP + WS_BORDER
  49.  
  50. @ ID 110 SAY "Password:"      AT 10,29  SIZE 50,10  IN aDlg
  51. @ ID 111 EDIT                 AT 53,27  SIZE 50,14  IN aDlg        ;
  52.   STYLE ES_PASSWORD + ES_UPPERCASE + ES_AUTOHSCROLL + CTL_DEFSTYLE + WS_TABSTOP + WS_BORDER
  53.  
  54. /*
  55.  *  This dialog doesn't want any buttons, but Windows still handles the
  56.  *  Esc (or Alt+F4) & Enter keys as if it has buttons with IDs IDCANCEL
  57.  *  and IDOK.
  58.  *
  59.  *  That's fine, but we'd like to grab control when Enter is pressed.
  60.  *
  61.  *  So, let's say there's an OK button, even though there isn't!
  62.  *  This only works because nothing in Clip-4-Win or elsewhere bothers
  63.  *  to test carefully that the button you claim exists actually does.
  64.  *  If this trick didn't work, you could add an OK button & then hide
  65.  *  or destroy it later.  That would still let you grab control.
  66.  *
  67.  *  Both versions of the code are below.
  68.  */
  69.  
  70. #ifdef    USE_TRICK
  71.  
  72. @ ID IDOK  BUTTON  OnOK  IN aDlg
  73.  
  74. SHOW DIALOG aDlg  RESULT nRet
  75.  
  76. #else    // USE_TRICK
  77.  
  78. @ ID IDOK  BUTTON  OnOK  TEXT ""  AT 20,40  SIZE 30,10  IN aDlg
  79.  
  80. SHOW DIALOG aDlg  RESULT nRet  ON INIT {|hDlg| InitDlg(hDlg)}
  81.  
  82. #endif    // USE_TRICK
  83.  
  84. return nRet == IDOK
  85.  
  86.  
  87. #ifndef    USE_TRICK
  88.  
  89. static function InitDlg(hDlg)
  90. // Either of these works fine:
  91. //DestroyWindow(GetDlgItem(hDlg, IDOK))
  92. ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE)
  93. return nil
  94.  
  95. #endif    // !USE_TRICK
  96.  
  97.  
  98. static function OnOK(hDlg)    // Occurs when Enter pressed
  99. cName = GetDlgItmText(hDlg, 101)
  100. cPass = GetDlgItmText(hDlg, 111)
  101.  
  102. if cName == ""
  103.     SetFocus(GetDlgItem(hDlg, 101))  // move to username field
  104. elseif GetFocus() != GetDlgItem(hDlg, 111)  // if not on password field
  105.     SetFocus(GetDlgItem(hDlg, 111))  // move to password field
  106. elseif cName == "TEST" .and. cPass == "TEST"
  107.     // You could just use:
  108.     //    return nil    // (ask for default handling)
  109.     EndDialog(hDlg, IDOK)    // terminate the dialog & return IDOK
  110. else
  111.     // bad password
  112.     MessageBeep()
  113. endif
  114. return 1    // we handled the Enter
  115.  
  116.  
  117. static function MenuSetup(oWnd)
  118. MENU IN oWnd
  119.     POPUP "&File"
  120.         MENUITEM "E&xit"   ACTION PostQuitMessage(0)
  121.     ENDPOPUP
  122.     POPUP "&Help"
  123.         MENUITEM "&About"  ACTION MessageBox( , "Easy!", "Clip-4-Win App")
  124.     ENDPOPUP
  125. ENDMENU
  126.  
  127. return nil
  128.  
  129.