5b10bedcbf97438b9dc5f30e4bf8ab5ae3d115d1
[openafs.git] / src / WINNT / client_config / main.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 #include <afs/fs_utils.h>
14 }
15
16 #include "afs_config.h"
17 #include "isadmin.h"
18 #include "tab_general.h"
19 #include "tab_prefs.h"
20 #include "tab_hosts.h"
21 #include "tab_drives.h"
22 #include "tab_advanced.h"
23
24 /*
25  * DEFINITIONS ________________________________________________________________
26  *
27  */
28
29
30 /*
31  * VARIABLES __________________________________________________________________
32  *
33  */
34
35 GLOBALS g;
36
37
38 /*
39  * PROTOTYPES _________________________________________________________________
40  *
41  */
42
43 void Quit (void);
44
45
46 /*
47  * ROUTINES ___________________________________________________________________
48  *
49  */
50
51 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
52 {
53    TaLocale_LoadCorrespondingModule (hInst);
54
55    // Initialize winsock etc
56    //
57    WSADATA Data;
58    WSAStartup (0x0101, &Data);
59
60    InitCommonControls();
61    RegisterCheckListClass();
62    RegisterFastListClass();
63    RegisterSockAddrClass();
64    RegisterSpinnerClass();
65    fs_utils_InitMountRoot();
66
67    // Initialize our global variables and window classes
68    //
69    memset (&g, 0x00, sizeof(g));
70    g.fIsWinNT = IsWindowsNT();
71    g.fIsAdmin = IsAdmin();
72
73    // Check our command-line options
74    //
75    while (pCmdLine && (*pCmdLine=='/' || *pCmdLine=='-'))
76       {
77       switch (*(++pCmdLine))
78          {
79          case 'c':
80          case 'C':
81             g.fIsCCenter = TRUE;
82             break;
83          }
84
85       while (*pCmdLine == ' ')
86          ++pCmdLine;
87       }
88
89    // Select an appropriate help file
90    //
91    if (g.fIsCCenter)
92       lstrcpy (g.szHelpFile, TEXT("afs-cc.hlp>dialog"));
93    else if (g.fIsWinNT)
94       lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp>dialog"));
95    else
96       lstrcpy (g.szHelpFile, TEXT("afs-light.hlp>dialog"));
97
98    // Our main window is actually a tabbed dialog.
99    //
100    if ((g.psh = PropSheet_Create (((g.fIsCCenter) ? IDS_TITLE_CCENTER : (g.fIsWinNT) ? IDS_TITLE_NT : IDS_TITLE_95), FALSE, NULL)) == NULL)
101       return FALSE;
102
103    g.psh->sh.dwFlags |= PSH_NOAPPLYNOW;  // Remove the Apply button
104    g.psh->sh.dwFlags |= PSH_HASHELP;     // Add a Help button instead
105
106    if (g.fIsCCenter)
107       {
108       PropSheet_AddTab (g.psh, 0, IDD_HOSTS_CCENTER, (DLGPROC)HostsTab_DlgProc, 0, TRUE);
109       }
110    else
111       {
112       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_GENERAL_NT : IDD_GENERAL_95), (DLGPROC)GeneralTab_DlgProc, 0, TRUE);
113
114       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_DRIVES_NT : IDD_DRIVES_95), (DLGPROC)DrivesTab_DlgProc, 0, TRUE);
115
116       if (g.fIsWinNT)
117          PropSheet_AddTab (g.psh, 0, IDD_PREFS_NT, (DLGPROC)PrefsTab_DlgProc, 0, TRUE);
118
119       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_HOSTS_NT : IDD_HOSTS_95), (DLGPROC)HostsTab_DlgProc, 0, TRUE);
120
121       if (g.fIsWinNT)
122          PropSheet_AddTab (g.psh, 0, IDD_ADVANCED_NT, (DLGPROC)AdvancedTab_DlgProc, 0, TRUE);
123       }
124
125    PropSheet_ShowModal (g.psh);
126
127    return 0;
128 }
129
130
131 void Main_OnInitDialog (HWND hMain)
132 {
133    g.hMain = hMain;
134
135    // Center the window in the display
136    //
137    RECT rWindow;
138    GetWindowRect (g.hMain, &rWindow);
139
140    RECT rDesktop;
141    SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
142
143    SetWindowPos (g.hMain, NULL,
144                  rDesktop.left + ((rDesktop.right - rDesktop.left) - (rWindow.right - rWindow.left)) / 2,
145                  rDesktop.top + ((rDesktop.bottom - rDesktop.top) - (rWindow.bottom - rWindow.top)) / 2,
146                  0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
147
148    // Remove the Context Help [?] thing from the title bar
149    //
150    DWORD dwStyle = GetWindowLong (g.hMain, GWL_STYLE);
151    dwStyle &= ~DS_CONTEXTHELP;
152    SetWindowLong (g.hMain, GWL_STYLE, dwStyle);
153
154    dwStyle = GetWindowLong (hMain, GWL_EXSTYLE);
155    dwStyle &= ~WS_EX_CONTEXTHELP;
156    SetWindowLong (g.hMain, GWL_EXSTYLE, dwStyle);
157 }
158
159
160 void Main_RefreshAllTabs (void)
161 {
162    for (size_t ii = 0; ii < g.psh->cTabs; ++ii)
163       {
164       if (!g.psh->aTabs[ii].dlgproc)
165          continue;
166       if (!IsWindow (g.psh->aTabs[ii].hDlg))
167          continue;
168
169       CallWindowProc ((WNDPROC)(g.psh->aTabs[ii].dlgproc), g.psh->aTabs[ii].hDlg, WM_COMMAND, IDC_REFRESH, 0);
170       }
171 }
172
173
174 void Quit (void)
175 {
176    if (IsWindow (g.hMain))
177       {
178       DestroyWindow (g.hMain);
179       }
180    PostQuitMessage (0);
181 }
182
183
184 LPCTSTR GetCautionTitle (void)
185 {
186    static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
187    if (!szTitle[0])
188       GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_CAUTION_CCENTER : (g.fIsWinNT) ? IDS_TITLE_CAUTION_NT : IDS_TITLE_CAUTION_95);
189    return szTitle;
190 }
191
192
193 LPCTSTR GetErrorTitle (void)
194 {
195    static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
196    if (!szTitle[0])
197       GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_ERROR_CCENTER : (g.fIsWinNT) ? IDS_TITLE_ERROR_NT : IDS_TITLE_ERROR_95);
198    return szTitle;
199 }
200