[NTDLL]
[reactos.git] / base / applications / games / winemine / dialog.c
1 /*
2 * WineMine (dialog.c)
3 *
4 * Copyright 2000 Joshua Thielen <jt85296@ltu.edu>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <windows.h>
22 #include <tchar.h>
23 #include "main.h"
24 #include "dialog.h"
25 #include "resource.h"
26
27 INT_PTR CALLBACK CustomDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
28 {
29 static BOARD *pBoard;
30
31 switch(uMsg)
32 {
33 case WM_INITDIALOG:
34 pBoard = (BOARD*) lParam;
35 SetDlgItemInt( hDlg, IDC_EDITROWS, pBoard->uRows, FALSE );
36 SetDlgItemInt( hDlg, IDC_EDITCOLS, pBoard->uCols, FALSE );
37 SetDlgItemInt( hDlg, IDC_EDITMINES, pBoard->uMines, FALSE );
38 return TRUE;
39
40 case WM_COMMAND:
41 switch( LOWORD( wParam ) )
42 {
43 case IDOK:
44 pBoard->uRows = GetDlgItemInt( hDlg, IDC_EDITROWS, NULL, FALSE );
45 pBoard->uCols = GetDlgItemInt( hDlg, IDC_EDITCOLS, NULL, FALSE );
46 pBoard->uMines = GetDlgItemInt( hDlg, IDC_EDITMINES, NULL, FALSE );
47 CheckLevel( pBoard );
48 /* Fall through */
49 case IDCANCEL:
50 EndDialog( hDlg, LOWORD(wParam) );
51 return TRUE;
52 }
53 break;
54 }
55
56 return FALSE;
57 }
58
59 INT_PTR CALLBACK CongratsDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
60 {
61 static BOARD *pBoard;
62
63 switch(uMsg)
64 {
65 case WM_INITDIALOG:
66 pBoard = (BOARD*) lParam;
67 SetDlgItemText( hDlg, IDC_EDITNAME, pBoard->szBestName[pBoard->Difficulty] );
68 return TRUE;
69
70 case WM_COMMAND:
71 switch( LOWORD(wParam) )
72 {
73 case IDOK:
74 GetDlgItemText( hDlg, IDC_EDITNAME,
75 pBoard->szBestName[pBoard->Difficulty],
76 sizeof( pBoard->szBestName[pBoard->Difficulty] ) );
77 EndDialog( hDlg, 0 );
78 return TRUE;
79
80 case IDCANCEL:
81 EndDialog( hDlg, 0 );
82 return TRUE;
83 }
84 break;
85 }
86 return FALSE;
87 }
88
89 INT_PTR CALLBACK TimesDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
90 {
91 static BOARD *pBoard;
92 HKEY hKey;
93 UCHAR i;
94 TCHAR szData[16];
95 TCHAR szKeyName[8];
96 TCHAR szTimes[35];
97 TCHAR szSeconds[23];
98 TCHAR szNobody[15];
99
100 switch(uMsg)
101 {
102 case WM_INITDIALOG:
103 pBoard = (BOARD*) lParam;
104
105 /* set best names */
106 for( i = 0; i < 3; i++ )
107 SetDlgItemText( hDlg, (IDC_NAME1) + i, pBoard->szBestName[i] );
108
109 /* set best times */
110 LoadString( pBoard->hInst, IDS_SECONDS, szSeconds, sizeof(szSeconds) / sizeof(TCHAR) );
111
112 for( i = 0; i < 3; i++ )
113 {
114 wsprintf(szTimes, TEXT("%d %s"), pBoard->uBestTime[i], szSeconds);
115 SetDlgItemText( hDlg, (IDC_TIME1) + i, szTimes );
116 }
117
118 return TRUE;
119
120 case WM_COMMAND:
121 switch( LOWORD( wParam ) )
122 {
123 case IDOK:
124 case IDCANCEL:
125 EndDialog( hDlg, 0 );
126 return TRUE;
127
128 case IDRESET:
129 if( RegCreateKeyEx( HKEY_CURRENT_USER, szWineMineRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL ) != ERROR_SUCCESS)
130 return TRUE;
131
132 LoadString( pBoard->hInst, IDS_NOBODY, szNobody, sizeof(szNobody) / sizeof(TCHAR) );
133 LoadString( pBoard->hInst, IDS_SECONDS, szSeconds, sizeof(szSeconds) / sizeof(TCHAR) );
134
135 for (i = 0; i < 3; i++)
136 {
137 pBoard->uBestTime[i] = 999;
138 _tcscpy(pBoard->szBestName[i], szNobody);
139 wsprintf(szTimes, TEXT("%d %s"), pBoard->uBestTime[i], szSeconds);
140
141 SetDlgItemText( hDlg, (IDC_NAME1) + i, pBoard->szBestName[i] );
142 SetDlgItemText( hDlg, (IDC_TIME1) + i, szTimes );
143 }
144
145 /* Write the changes to the registry
146 As we write to the same registry key as MS WinMine does, we have to start at 1 for the registry keys */
147 for( i = 0; i < 3; i++ )
148 {
149 wsprintf( szKeyName, TEXT("Name%u"), i + 1 );
150 _tcsncpy( szData, pBoard->szBestName[i], sizeof(szData) / sizeof(TCHAR) );
151 RegSetValueEx( hKey, szKeyName, 0, REG_SZ, (LPBYTE)szData, (_tcslen(szData) + 1) * sizeof(TCHAR) );
152 }
153
154 for( i = 0; i < 3; i++ )
155 {
156 wsprintf( szKeyName, TEXT("Time%u"), i + 1 );
157 RegSetValueEx( hKey, szKeyName, 0, REG_DWORD, (LPBYTE)&pBoard->uBestTime[i], sizeof(DWORD) );
158 }
159
160 RegCloseKey(hKey);
161 return TRUE;
162 }
163 }
164
165 return FALSE;
166 }
167