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