[NTDLL]
[reactos.git] / base / applications / dxdiag / dxdiag.c
1 /*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/dxdiag.c
5 * PURPOSE: ReactX diagnosis application entry
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
7 *
8 */
9
10 #include "precomp.h"
11
12 /* globals */
13 HINSTANCE hInst = 0;
14 HWND hTabCtrlWnd;
15
16 //---------------------------------------------------------------
17 VOID
18 DestroyTabCtrlDialogs(PDXDIAG_CONTEXT pContext)
19 {
20 UINT Index;
21
22 /* destroy default dialogs */
23 for(Index = 0; Index < sizeof(pContext->hDialogs) / sizeof(HWND); Index++)
24 {
25 if (pContext->hDialogs[Index])
26 DestroyWindow(pContext->hDialogs[Index]);
27 }
28
29 /* destroy display dialogs */
30 for(Index = 0; Index < pContext->NumDisplayAdapter; Index++)
31 {
32 if (pContext->hDisplayWnd[Index])
33 DestroyWindow(pContext->hDisplayWnd[Index]);
34 }
35
36 /* destroy audio dialogs */
37 for(Index = 0; Index < pContext->NumSoundAdapter; Index++)
38 {
39 if (pContext->hSoundWnd[Index])
40 DestroyWindow(pContext->hSoundWnd[Index]);
41 }
42
43 }
44
45 //---------------------------------------------------------------
46 VOID
47 InsertTabCtrlItem(HWND hDlgCtrl, INT Position, LPWSTR uId)
48 {
49 WCHAR szName[100];
50 TCITEMW item;
51
52 /* setup item info */
53 memset(&item, 0, sizeof(TCITEM));
54 item.mask = TCIF_TEXT;
55
56 /* load item name */
57 if (!HIWORD(uId))
58 {
59 szName[0] = L'\0';
60 if (!LoadStringW(hInst, LOWORD(uId), szName, 100))
61 return;
62 szName[99] = L'\0';
63 item.pszText = szName;
64 }
65 else
66 {
67 item.pszText = uId;
68 }
69
70
71 SendMessageW(hDlgCtrl, TCM_INSERTITEM, Position, (LPARAM)&item);
72 }
73
74 VOID
75 TabCtrl_OnSelChange(PDXDIAG_CONTEXT pContext)
76 {
77 INT Index;
78 INT CurSel;
79
80 /* retrieve new page */
81 CurSel = TabCtrl_GetCurSel(hTabCtrlWnd);
82 if (CurSel < 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 5)
83 return;
84
85 /* hide all windows */
86 for(Index = 0; Index < 5; Index++)
87 ShowWindow(pContext->hDialogs[Index], SW_HIDE);
88
89 for(Index = 0; Index < pContext->NumDisplayAdapter; Index++)
90 ShowWindow(pContext->hDisplayWnd[Index], SW_HIDE);
91
92 for(Index = 0; Index < pContext->NumSoundAdapter; Index++)
93 ShowWindow(pContext->hSoundWnd[Index], SW_HIDE);
94
95
96 if (CurSel == 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter)
97 {
98 if (CurSel)
99 CurSel -= pContext->NumDisplayAdapter + pContext->NumSoundAdapter;
100 ShowWindow(pContext->hDialogs[CurSel], SW_SHOW);
101 return;
102 }
103
104 if (CurSel -1 < pContext->NumDisplayAdapter)
105 {
106 ShowWindow(pContext->hDisplayWnd[CurSel-1], SW_SHOW);
107 return;
108 }
109
110 CurSel -= pContext->NumDisplayAdapter + 1;
111 ShowWindow(pContext->hSoundWnd[CurSel], SW_SHOW);
112 }
113
114 VOID
115 InitializeTabCtrl(HWND hwndDlg, PDXDIAG_CONTEXT pContext)
116 {
117 /* get tabctrl */
118 hTabCtrlWnd = GetDlgItem(hwndDlg, IDC_TAB_CONTROL);
119 pContext->hTabCtrl = hTabCtrlWnd;
120
121 /* create the dialogs */
122 pContext->hDialogs[0] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SYSTEM_DIALOG), hTabCtrlWnd, SystemPageWndProc, (LPARAM)pContext);
123 pContext->hDialogs[1] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_MUSIC_DIALOG), hTabCtrlWnd, MusicPageWndProc, (LPARAM)pContext);
124 pContext->hDialogs[2] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_INPUT_DIALOG), hTabCtrlWnd, InputPageWndProc, (LPARAM)pContext);
125 pContext->hDialogs[3] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_NETWORK_DIALOG), hTabCtrlWnd, NetworkPageWndProc, (LPARAM)pContext);
126 pContext->hDialogs[4] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_HELP_DIALOG), hTabCtrlWnd, HelpPageWndProc, (LPARAM)pContext);
127
128 /* insert tab ctrl items */
129
130 InsertTabCtrlItem(hTabCtrlWnd, 0, MAKEINTRESOURCEW(IDS_SYSTEM_DIALOG));
131 InitializeDisplayAdapters(pContext);
132 InitializeDirectSoundPage(pContext);
133 InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 1, MAKEINTRESOURCEW(IDS_MUSIC_DIALOG));
134 InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 2, MAKEINTRESOURCEW(IDS_INPUT_DIALOG));
135 InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 3, MAKEINTRESOURCEW(IDS_NETWORK_DIALOG));
136 InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 4, MAKEINTRESOURCEW(IDS_HELP_DIALOG));
137 TabCtrl_OnSelChange(pContext);
138 }
139
140 VOID
141 InitializeDxDiagDialog(HWND hwndDlg)
142 {
143 PDXDIAG_CONTEXT pContext;
144 HICON hIcon;
145
146 pContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DXDIAG_CONTEXT));
147 if (!pContext)
148 return;
149
150 /* store window handle */
151 pContext->hMainDialog = hwndDlg;
152
153 /* store the context */
154 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
155
156 /* initialize the tab ctrl */
157 InitializeTabCtrl(hwndDlg, pContext);
158
159 /* load application icon */
160 hIcon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 16, 16, 0);
161 if (!hIcon)
162 return;
163 /* display icon */
164 SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
165 }
166
167
168 INT_PTR CALLBACK
169 DxDiagWndProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
170 {
171 LPNMHDR pnmh;
172 PDXDIAG_CONTEXT pContext;
173
174 pContext = (PDXDIAG_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
175
176 switch (message)
177 {
178 case WM_INITDIALOG:
179 InitializeDxDiagDialog(hwndDlg);
180 return TRUE;
181 case WM_COMMAND:
182 if (LOWORD(wParam) == IDC_BUTTON_SAVE_INFO)
183 {
184 //TODO
185 /* handle save information */
186 return TRUE;
187 }
188
189 if (LOWORD(wParam) == IDC_BUTTON_NEXT)
190 {
191 //TODO
192 /* handle next button */
193 return TRUE;
194 }
195
196 if (LOWORD(wParam) == IDC_BUTTON_HELP)
197 {
198 //TODO
199 /* handle help button */
200 return TRUE;
201 }
202
203 if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_EXIT) {
204 EndDialog(hwndDlg, LOWORD(wParam));
205 return TRUE;
206 }
207 break;
208
209 case WM_NOTIFY:
210 pnmh = (LPNMHDR)lParam;
211 if ((pnmh->hwndFrom == hTabCtrlWnd) && (pnmh->idFrom == IDC_TAB_CONTROL) && (pnmh->code == TCN_SELCHANGE))
212 {
213 TabCtrl_OnSelChange(pContext);
214 }
215 break;
216 case WM_DESTROY:
217 DestroyTabCtrlDialogs(pContext);
218 return DefWindowProc(hwndDlg, message, wParam, lParam);
219 }
220 return 0;
221 }
222
223 int APIENTRY wWinMain(HINSTANCE hInstance,
224 HINSTANCE hPrevInstance,
225 LPWSTR lpCmdLine,
226 int nCmdShow)
227 {
228
229 INITCOMMONCONTROLSEX InitControls;
230
231 UNREFERENCED_PARAMETER(hPrevInstance);
232 UNREFERENCED_PARAMETER(lpCmdLine);
233 UNREFERENCED_PARAMETER(nCmdShow);
234
235 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
236 InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES | ICC_STANDARD_CLASSES | ICC_TREEVIEW_CLASSES;
237 InitCommonControlsEx(&InitControls);
238
239 hInst = hInstance;
240
241 DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, DxDiagWndProc);
242
243 return 0;
244 }