Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / WINNT / afssvrcfg / get_pw_dlg.cpp
1 /*
2  * Copyright (C) 1998  Transarc Corporation.
3  * All rights reserved.
4  *
5  */
6
7
8 /*
9  * INCLUDES ___________________________________________________________________
10  *
11  */
12 extern "C" {
13 #include <afs/param.h>
14 #include <afs/stds.h>
15 }
16
17 #include "afscfg.h"             // Main header for this application
18 #include "resource.h"
19 #include "get_pw_dlg.h"
20
21
22 /*
23  * DEFINITIONS _________________________________________________________________
24  *
25  */
26 static HWND hDlg = 0;                                           // HWND for this page's dialog
27
28
29 /*
30  * PROTOTYPES _________________________________________________________________
31  *
32  */
33 static void OnInitDialog(HWND hwndDlg);
34 static void CheckEnableButtons();
35 static void SaveDlgInfo();
36 static void ShowPageInfo();
37
38 BOOL CALLBACK GetPwDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
39
40
41 /*
42  * EXPORTED FUNCTIONS _________________________________________________________
43  *
44  */
45 BOOL GetAfsPrincipalPassword(HWND hParent, TCHAR *&pszServerPW)
46 {       
47         int nResult = ModalDialog(IDD_GET_PW, hParent, (DLGPROC)GetPwDlgProc);
48     if (nResult == IDOK) {
49         pszServerPW = g_CfgData.szServerPW;
50         return TRUE;
51     }
52
53     pszServerPW = 0;
54
55         return FALSE;
56 }
57
58
59 /*
60  * Dialog Proc _________________________________________________________________
61  *
62  */
63 BOOL CALLBACK GetPwDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
64 {
65         if (AfsAppLib_HandleHelp(IDD_GET_PW, hwndDlg, msg, wp, lp))
66                 return TRUE;
67
68         switch (msg) {
69                 case WM_INITDIALOG:
70                         OnInitDialog(hwndDlg);
71                         break;
72
73                 case WM_COMMAND:
74                         switch (LOWORD(wp)) {
75                                 case IDC_PW:
76                                         if (HIWORD(wp) == EN_CHANGE)
77                                                 CheckEnableButtons();
78                                         break;
79
80                                 case IDCANCEL:
81                                         EndDialog(hDlg, IDCANCEL);
82                                         break;
83                                         
84
85                                 case IDOK:
86                                         SaveDlgInfo();
87                                         EndDialog(hDlg, IDOK);
88                                         break;
89                         }
90                 break;
91     }
92
93     return FALSE;
94 }
95
96
97 /*
98  * STATIC FUNCTIONS _________________________________________________________________
99  *
100  */
101
102 /*
103  * Event Handler Functions _________________________________________________________________
104  *
105  */
106 static void OnInitDialog(HWND hwndDlg)
107 {
108         hDlg = hwndDlg;
109 }
110
111
112 /*
113  * Utility Functions _________________________________________________________________
114  *
115  */
116 static void CheckEnableButtons()
117 {
118         BOOL bDisable = FALSE;
119
120         TCHAR szDummy[cchRESOURCE];
121
122         bDisable |= lstrlen(GetWndText(hDlg, IDC_PW, szDummy)) == 0;
123
124         SetEnable(hDlg, IDOK, (ENABLE_STATE)!bDisable);
125 }
126
127 static void SaveDlgInfo()
128 {
129         TCHAR szText[cchRESOURCE];
130         
131         lstrncpy(g_CfgData.szServerPW, GetWndText(hDlg, IDC_PW, szText), MAX_SERVER_PW_LEN);
132 }
133
134 static void ShowPageInfo()
135 {
136         SetWndText(hDlg, IDC_PW, g_CfgData.szServerPW);
137 }
138