home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
LOGON.PRG
< prev
next >
Wrap
Text File
|
1996-05-13
|
3KB
|
129 lines
/////////////////////////
//
// logon.prg - simple logon/login dialog
//
// Written by: John M. Skelton, May-96.
//
// Copyright (C) 1993-1996 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
// All Rights Reserved.
//
/////////////////////////
#include "windows.ch"
#define NO_C4WCLASS
#include "commands.ch"
#include "topclass.ch"
static cName, cPass
function main()
local oApp, oWnd
CREATE APPLICATION oApp ;
WINDOW oWnd ;
TITLE "Clip-4-Win Makes Windows Apps E-A-S-Y!" ;
ON INIT DoInit(oWnd)
return nil
static function DoInit(oWnd)
do while !LogonOK(oWnd)
enddo
MenuSetup(oWnd) // or WinExec("MainApp") or whatever
return nil
static function LogonOK(oWnd)
local aDlg, nRet
// You can use DS_SYSMODAL to keep the user out of the rest of Windows!
CREATE DIALOG aDlg TITLE "Logon" AT 100,100 SIZE 115,54 ;
STYLE /*DS_SYSMODAL+*/ WS_POPUP+WS_CAPTION IN oWnd
@ ID 100 SAY "User name:" AT 10,12 SIZE 50,10 IN aDlg
@ ID 101 EDIT AT 53,10 SIZE 50,14 IN aDlg ;
STYLE ES_UPPERCASE + ES_AUTOHSCROLL + CTL_DEFSTYLE + WS_TABSTOP + WS_BORDER
@ ID 110 SAY "Password:" AT 10,29 SIZE 50,10 IN aDlg
@ ID 111 EDIT AT 53,27 SIZE 50,14 IN aDlg ;
STYLE ES_PASSWORD + ES_UPPERCASE + ES_AUTOHSCROLL + CTL_DEFSTYLE + WS_TABSTOP + WS_BORDER
/*
* This dialog doesn't want any buttons, but Windows still handles the
* Esc (or Alt+F4) & Enter keys as if it has buttons with IDs IDCANCEL
* and IDOK.
*
* That's fine, but we'd like to grab control when Enter is pressed.
*
* So, let's say there's an OK button, even though there isn't!
* This only works because nothing in Clip-4-Win or elsewhere bothers
* to test carefully that the button you claim exists actually does.
* If this trick didn't work, you could add an OK button & then hide
* or destroy it later. That would still let you grab control.
*
* Both versions of the code are below.
*/
#ifdef USE_TRICK
@ ID IDOK BUTTON OnOK IN aDlg
SHOW DIALOG aDlg RESULT nRet
#else // USE_TRICK
@ ID IDOK BUTTON OnOK TEXT "" AT 20,40 SIZE 30,10 IN aDlg
SHOW DIALOG aDlg RESULT nRet ON INIT {|hDlg| InitDlg(hDlg)}
#endif // USE_TRICK
return nRet == IDOK
#ifndef USE_TRICK
static function InitDlg(hDlg)
// Either of these works fine:
//DestroyWindow(GetDlgItem(hDlg, IDOK))
ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE)
return nil
#endif // !USE_TRICK
static function OnOK(hDlg) // Occurs when Enter pressed
cName = GetDlgItmText(hDlg, 101)
cPass = GetDlgItmText(hDlg, 111)
if cName == ""
SetFocus(GetDlgItem(hDlg, 101)) // move to username field
elseif GetFocus() != GetDlgItem(hDlg, 111) // if not on password field
SetFocus(GetDlgItem(hDlg, 111)) // move to password field
elseif cName == "TEST" .and. cPass == "TEST"
// You could just use:
// return nil // (ask for default handling)
EndDialog(hDlg, IDOK) // terminate the dialog & return IDOK
else
// bad password
MessageBeep()
endif
return 1 // we handled the Enter
static function MenuSetup(oWnd)
MENU IN oWnd
POPUP "&File"
MENUITEM "E&xit" ACTION PostQuitMessage(0)
ENDPOPUP
POPUP "&Help"
MENUITEM "&About" ACTION MessageBox( , "Easy!", "Clip-4-Win App")
ENDPOPUP
ENDMENU
return nil