convert line ends
[canaan.git] / prj / cam / src / framewrk / dxwrndlg.cpp
blobd4cec8c9aa0955e44396019e0a508f8765da4fc6
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ////////////////////////////////////////////////////////////////////////
7 //
8 // (c) 1998 Looking Glass Technologies Inc.
9 // David Teichholtz
11 // Description: Routines which deal with putting up the opening
12 // dialog warning message. As a famous writer once said, much ado about
13 // about nothing.
14 ////////////////////////////////////////////////////////////////////////
16 #include <windows.h>
17 #include <resource.h>
18 #include <memall.h>
19 #include <config.h>
20 #include <str.h>
21 #include <drkuires.h>
22 #include <dxwrndlg.h>
23 #include <memall.h>
24 #include <dbmem.h> // must be last header!
26 bool bNeverAgainSelected;
30 // the dialog callback routine
31 BOOL CALLBACK GameEntryDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM /* lParam */)
34 HKEY hKey;
35 DWORD retCode;
36 DWORD dwKeyBufferSize=sizeof(BOOL);
37 BOOL NeverAgain=TRUE;
38 switch (uMsg)
40 case WM_INITDIALOG:
42 SetWindowLong(hwndDlg, GWL_STYLE, 0x04);
43 RECT rcDlg, rcWnd;
44 GetWindowRect(hwndDlg, &rcDlg);
45 GetWindowRect(GetDesktopWindow(), &rcWnd);
46 int iWndCenterX = rcWnd.right/2, iWndCenterY = rcWnd.bottom/2;
47 int iWidthWindow = rcDlg.right - rcDlg.left,
48 iHeightWindow = rcDlg.bottom - rcDlg.top;
49 int iNewX = iWndCenterX - (iWidthWindow/2),
50 iNewY = ((iWndCenterY - (iHeightWindow/2)) * 66) / 100;
51 MoveWindow(hwndDlg, iNewX, iNewY, iWidthWindow, iHeightWindow, TRUE);
52 // get the text out of the LG resource system
53 cStr key_str = FetchUIString("misc","driver_text");
54 cStr never_str = FetchUIString("misc","neveragain");
55 // and display it
56 SetWindowText(GetDlgItem(hwndDlg,IDC_DXINFO),(const char*)key_str);
57 SetWindowText(GetDlgItem(hwndDlg,IDC_NEVERAGAIN),(const char *)never_str);
58 return 1;
60 case WM_COMMAND:
62 unsigned wNotifyCode = HIWORD(wParam); // notification code
63 unsigned wID = LOWORD(wParam);
64 unsigned wCheckedOrNot;
65 switch (wID)
67 case IDOK: // dialog box OK
68 if (bNeverAgainSelected) // button was checked
70 // going to have to get the app keys out
71 // of the resource system
72 cStr key_str = FetchUIString("misc","regkey");
73 // open the main key
74 retCode = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
75 (const char *)key_str,
77 KEY_WRITE,
78 &hKey);
80 if(retCode==ERROR_SUCCESS) // oxymoron
82 retCode = RegSetValueEx( // subkey
83 hKey,
84 "NeverAgain", // same in every language
85 NULL,
86 REG_DWORD,
87 (LPBYTE) &NeverAgain,
88 dwKeyBufferSize);
90 } // opened successfully
91 RegCloseKey(hKey);
92 } // bNeverAgainSelected
93 EndDialog(hwndDlg, 0);
94 break;
95 case IDC_NEVERAGAIN:
96 wCheckedOrNot =
97 IsDlgButtonChecked(hwndDlg,
98 IDC_NEVERAGAIN);
99 if (wCheckedOrNot==BST_CHECKED) {
100 bNeverAgainSelected=TRUE;
102 else {
103 bNeverAgainSelected=FALSE;
105 break;
106 EndDialog(hwndDlg, 0);
107 break;
112 return 0;
116 // Display 'Please shut down.... ' message
118 void
119 DxWarnDlg()
122 HINSTANCE hInst; // the instance of this exe
124 HKEY hKey;
125 DWORD retCode;
126 DWORD dwKeyBufferSize=sizeof(int);
127 int NeverAgain=FALSE;
129 // open the main key (which had better be there!)
130 // get the key from the resource system
131 cStr key_str = FetchUIString("misc","regkey");
132 retCode = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
133 (const char *)key_str,
135 KEY_READ,
136 &hKey);
138 if(retCode==ERROR_SUCCESS) { // oxymoron
139 retCode = RegQueryValueEx(
140 hKey,
141 "NeverAgain",
142 NULL,
143 NULL, // I don't care about it's type
144 (unsigned char *) &NeverAgain, // address of data buffer
145 &dwKeyBufferSize); // address of data buffer size
147 RegCloseKey(hKey); // we are done either way
149 // we only display the warning if NeverAgain is TRUE and we can
150 // find the dialog. Developers don't usually link in the .res.
152 if (retCode==ERROR_SUCCESS)
155 if (!NeverAgain)
157 hInst = GetModuleHandle(NULL);
158 if ( FindResource(hInst, MAKEINTRESOURCE(IDD_DXWARNDIALOG),
159 RT_DIALOG))
161 DialogBox(hInst, MAKEINTRESOURCE(IDD_DXWARNDIALOG),
162 GetDesktopWindow(), (DLGPROC)GameEntryDialogProc);
165 } // !NeverAgain
166 } // Found sub key
167 } // Found key
170 } // end of routine