global-mapping-20040325
[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  * ROUTINES ___________________________________________________________________
39  *
40  */
41
42 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
43 {
44    TaLocale_LoadCorrespondingModule (hInst);
45
46    // Initialize winsock etc
47    //
48    WSADATA Data;
49    WSAStartup (0x0101, &Data);
50
51    InitCommonControls();
52    RegisterCheckListClass();
53    RegisterFastListClass();
54    RegisterSockAddrClass();
55    RegisterSpinnerClass();
56    fs_utils_InitMountRoot();
57
58    // Initialize our global variables and window classes
59    //
60    memset (&g, 0x00, sizeof(g));
61    g.fIsWinNT = IsWindowsNT();
62    g.fIsAdmin = IsAdmin();
63
64    // Check our command-line options
65    //
66    while (pCmdLine && (*pCmdLine=='/' || *pCmdLine=='-'))
67       {
68       switch (*(++pCmdLine))
69          {
70          case 'c':
71          case 'C':
72             g.fIsCCenter = TRUE;
73             break;
74          }
75
76       while (*pCmdLine == ' ')
77          ++pCmdLine;
78       }
79
80    // Select an appropriate help file
81    //
82    if (g.fIsCCenter)
83       lstrcpy (g.szHelpFile, TEXT("afs-cc.hlp>dialog"));
84    else if (g.fIsWinNT)
85       lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp>dialog"));
86    else
87       lstrcpy (g.szHelpFile, TEXT("afs-light.hlp>dialog"));
88
89    // Our main window is actually a tabbed dialog.
90    //
91    if ((g.psh = PropSheet_Create (((g.fIsCCenter) ? IDS_TITLE_CCENTER : (g.fIsWinNT) ? IDS_TITLE_NT : IDS_TITLE_95), FALSE, NULL)) == NULL)
92       return FALSE;
93
94    g.psh->sh.dwFlags |= PSH_NOAPPLYNOW;  // Remove the Apply button
95    g.psh->sh.dwFlags |= PSH_HASHELP;     // Add a Help button instead
96
97    if (g.fIsCCenter)
98       {
99       PropSheet_AddTab (g.psh, 0, IDD_HOSTS_CCENTER, (DLGPROC)HostsTab_DlgProc, 0, TRUE);
100       }
101    else
102       {
103       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_GENERAL_NT : IDD_GENERAL_95), (DLGPROC)GeneralTab_DlgProc, 0, TRUE);
104
105       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_DRIVES_NT : IDD_DRIVES_95), (DLGPROC)DrivesTab_DlgProc, 0, TRUE);
106
107       if (g.fIsWinNT)
108          PropSheet_AddTab (g.psh, 0, IDD_PREFS_NT, (DLGPROC)PrefsTab_DlgProc, 0, TRUE);
109
110       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_HOSTS_NT : IDD_HOSTS_95), (DLGPROC)HostsTab_DlgProc, 0, TRUE);
111
112       if (g.fIsWinNT)
113          PropSheet_AddTab (g.psh, 0, IDD_ADVANCED_NT, (DLGPROC)AdvancedTab_DlgProc, 0, TRUE);
114       }
115
116    PropSheet_ShowModal (g.psh);
117
118    return 0;
119 }
120
121
122 void Main_OnInitDialog (HWND hMain)
123 {
124    g.hMain = hMain;
125
126    // Center the window in the display
127    //
128    RECT rWindow;
129    GetWindowRect (g.hMain, &rWindow);
130
131    RECT rDesktop;
132    SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
133
134    SetWindowPos (g.hMain, NULL,
135                  rDesktop.left + ((rDesktop.right - rDesktop.left) - (rWindow.right - rWindow.left)) / 2,
136                  rDesktop.top + ((rDesktop.bottom - rDesktop.top) - (rWindow.bottom - rWindow.top)) / 2,
137                  0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
138
139    // Remove the Context Help [?] thing from the title bar
140    //
141    DWORD dwStyle = GetWindowLong (g.hMain, GWL_STYLE);
142    dwStyle &= ~DS_CONTEXTHELP;
143    SetWindowLong (g.hMain, GWL_STYLE, dwStyle);
144
145    dwStyle = GetWindowLong (hMain, GWL_EXSTYLE);
146    dwStyle &= ~WS_EX_CONTEXTHELP;
147    SetWindowLong (g.hMain, GWL_EXSTYLE, dwStyle);
148 }
149
150
151 void Main_RefreshAllTabs (void)
152 {
153    for (size_t ii = 0; ii < g.psh->cTabs; ++ii)
154       {
155       if (!g.psh->aTabs[ii].dlgproc)
156          continue;
157       if (!IsWindow (g.psh->aTabs[ii].hDlg))
158          continue;
159
160       CallWindowProc ((WNDPROC)(g.psh->aTabs[ii].dlgproc), g.psh->aTabs[ii].hDlg, WM_COMMAND, IDC_REFRESH, 0);
161       }
162 }
163
164
165 void Quit (void)
166 {
167    if (IsWindow (g.hMain))
168       {
169       DestroyWindow (g.hMain);
170       }
171    PostQuitMessage (0);
172 }
173
174
175 LPCTSTR GetCautionTitle (void)
176 {
177    static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
178    if (!szTitle[0])
179       GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_CAUTION_CCENTER : (g.fIsWinNT) ? IDS_TITLE_CAUTION_NT : IDS_TITLE_CAUTION_95);
180    return szTitle;
181 }
182
183
184 LPCTSTR GetErrorTitle (void)
185 {
186    static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
187    if (!szTitle[0])
188       GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_ERROR_CCENTER : (g.fIsWinNT) ? IDS_TITLE_ERROR_NT : IDS_TITLE_ERROR_95);
189    return szTitle;
190 }
191