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
16 ////////////////////////////////////////////////////////////////////////////////
17 // Taken from WinSpy++ 1.7
18 // http://www.catch22.net/software/winspy
19 // Copyright (c) 2002 by J Brown
23 // Copied from uxtheme.h
24 // If you have this new header, then delete these and
25 // #include <uxtheme.h> instead!
27 #define ETDT_DISABLE 0x00000001
28 #define ETDT_ENABLE 0x00000002
29 #define ETDT_USETABTEXTURE 0x00000004
30 #define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE)
33 typedef HRESULT (WINAPI
* ETDTProc
) (HWND
, DWORD
);
36 // Try to call EnableThemeDialogTexture, if uxtheme.dll is present
38 BOOL
EnableDialogTheme(HWND hwnd
)
41 ETDTProc fnEnableThemeDialogTexture
;
43 hUXTheme
= LoadLibraryA("uxtheme.dll");
47 fnEnableThemeDialogTexture
=
48 (ETDTProc
)GetProcAddress(hUXTheme
, "EnableThemeDialogTexture");
50 if(fnEnableThemeDialogTexture
)
52 fnEnableThemeDialogTexture(hwnd
, ETDT_ENABLETAB
);
54 FreeLibrary(hUXTheme
);
59 // Failed to locate API!
60 FreeLibrary(hUXTheme
);
66 // Not running under XP? Just fail gracefully
71 //---------------------------------------------------------------
73 DestroyTabCtrlDialogs(PDXDIAG_CONTEXT pContext
)
77 /* destroy default dialogs */
78 for(Index
= 0; Index
< sizeof(pContext
->hDialogs
) / sizeof(HWND
); Index
++)
80 if (pContext
->hDialogs
[Index
])
81 DestroyWindow(pContext
->hDialogs
[Index
]);
84 /* destroy display dialogs */
85 for(Index
= 0; Index
< pContext
->NumDisplayAdapter
; Index
++)
87 if (pContext
->hDisplayWnd
[Index
])
88 DestroyWindow(pContext
->hDisplayWnd
[Index
]);
91 /* destroy audio dialogs */
92 for(Index
= 0; Index
< pContext
->NumSoundAdapter
; Index
++)
94 if (pContext
->hSoundWnd
[Index
])
95 DestroyWindow(pContext
->hSoundWnd
[Index
]);
100 //---------------------------------------------------------------
102 InsertTabCtrlItem(HWND hDlgCtrl
, INT Position
, LPWSTR uId
)
107 /* setup item info */
108 memset(&item
, 0, sizeof(TCITEMW
));
109 item
.mask
= TCIF_TEXT
;
115 if (!LoadStringW(hInst
, LOWORD(uId
), szName
, 100))
118 item
.pszText
= szName
;
126 SendMessageW(hDlgCtrl
, TCM_INSERTITEM
, Position
, (LPARAM
)&item
);
130 TabCtrl_OnSelChange(PDXDIAG_CONTEXT pContext
)
135 /* retrieve new page */
136 CurSel
= TabCtrl_GetCurSel(hTabCtrlWnd
);
137 if (CurSel
< 0 || CurSel
> pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 5)
140 /* hide all windows */
141 for(Index
= 0; Index
< 5; Index
++)
142 ShowWindow(pContext
->hDialogs
[Index
], SW_HIDE
);
144 for(Index
= 0; Index
< pContext
->NumDisplayAdapter
; Index
++)
145 ShowWindow(pContext
->hDisplayWnd
[Index
], SW_HIDE
);
147 for(Index
= 0; Index
< pContext
->NumSoundAdapter
; Index
++)
148 ShowWindow(pContext
->hSoundWnd
[Index
], SW_HIDE
);
151 if (CurSel
== 0 || CurSel
> pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
)
154 CurSel
-= pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
;
155 ShowWindow(pContext
->hDialogs
[CurSel
], SW_SHOW
);
159 if (CurSel
-1 < pContext
->NumDisplayAdapter
)
161 ShowWindow(pContext
->hDisplayWnd
[CurSel
-1], SW_SHOW
);
165 CurSel
-= pContext
->NumDisplayAdapter
+ 1;
166 ShowWindow(pContext
->hSoundWnd
[CurSel
], SW_SHOW
);
170 InitializeTabCtrl(HWND hwndDlg
, PDXDIAG_CONTEXT pContext
)
173 hTabCtrlWnd
= GetDlgItem(hwndDlg
, IDC_TAB_CONTROL
);
174 pContext
->hTabCtrl
= hTabCtrlWnd
;
176 /* create the dialogs */
177 pContext
->hDialogs
[0] = CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_SYSTEM_DIALOG
), pContext
->hMainDialog
, SystemPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(pContext
->hDialogs
[0]);
178 pContext
->hDialogs
[1] = CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_MUSIC_DIALOG
), pContext
->hMainDialog
, MusicPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(pContext
->hDialogs
[1]);
179 pContext
->hDialogs
[2] = CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_INPUT_DIALOG
), pContext
->hMainDialog
, InputPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(pContext
->hDialogs
[2]);
180 pContext
->hDialogs
[3] = CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_NETWORK_DIALOG
), pContext
->hMainDialog
, NetworkPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(pContext
->hDialogs
[3]);
181 pContext
->hDialogs
[4] = CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_HELP_DIALOG
), pContext
->hMainDialog
, HelpPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(pContext
->hDialogs
[4]);
183 /* insert tab ctrl items */
184 InsertTabCtrlItem(hTabCtrlWnd
, 0, MAKEINTRESOURCEW(IDS_SYSTEM_DIALOG
));
185 InitializeDisplayAdapters(pContext
);
186 InitializeDirectSoundPage(pContext
);
187 InsertTabCtrlItem(hTabCtrlWnd
, pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 1, MAKEINTRESOURCEW(IDS_MUSIC_DIALOG
));
188 InsertTabCtrlItem(hTabCtrlWnd
, pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 2, MAKEINTRESOURCEW(IDS_INPUT_DIALOG
));
189 InsertTabCtrlItem(hTabCtrlWnd
, pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 3, MAKEINTRESOURCEW(IDS_NETWORK_DIALOG
));
190 InsertTabCtrlItem(hTabCtrlWnd
, pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 4, MAKEINTRESOURCEW(IDS_HELP_DIALOG
));
191 TabCtrl_OnSelChange(pContext
);
195 InitializeDxDiagDialog(HWND hwndDlg
)
197 PDXDIAG_CONTEXT pContext
;
200 pContext
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DXDIAG_CONTEXT
));
204 /* store window handle */
205 pContext
->hMainDialog
= hwndDlg
;
207 /* store the context */
208 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pContext
);
210 /* initialize the tab ctrl */
211 InitializeTabCtrl(hwndDlg
, pContext
);
213 /* load application icon */
214 hIcon
= LoadImageW(hInst
, MAKEINTRESOURCEW(IDI_APPICON
), IMAGE_ICON
, 16, 16, 0);
218 SendMessage(hwndDlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
)hIcon
);
223 DxDiagWndProc(HWND hwndDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
226 PDXDIAG_CONTEXT pContext
;
228 pContext
= (PDXDIAG_CONTEXT
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
233 InitializeDxDiagDialog(hwndDlg
);
236 if (LOWORD(wParam
) == IDC_BUTTON_SAVE_INFO
)
239 /* handle save information */
243 if (LOWORD(wParam
) == IDC_BUTTON_NEXT
)
247 /* retrieve current page */
248 CurSel
= TabCtrl_GetCurSel(hTabCtrlWnd
);
251 /* enable/disable next button */
252 EnableWindow(GetDlgItem(hwndDlg
, IDC_BUTTON_NEXT
),
253 (CurSel
!= TabCtrl_GetItemCount(hTabCtrlWnd
) - 1));
255 /* switch to next tab */
256 SendMessageW(hTabCtrlWnd
, TCM_SETCURSEL
, CurSel
, 0L);
259 TabCtrl_OnSelChange(pContext
);
263 if (LOWORD(wParam
) == IDC_BUTTON_HELP
)
266 /* handle help button */
270 if (LOWORD(wParam
) == IDCANCEL
|| LOWORD(wParam
) == IDC_BUTTON_EXIT
) {
271 EndDialog(hwndDlg
, LOWORD(wParam
));
277 pnmh
= (LPNMHDR
)lParam
;
278 if ((pnmh
->hwndFrom
== hTabCtrlWnd
) && (pnmh
->idFrom
== IDC_TAB_CONTROL
) && (pnmh
->code
== TCN_SELCHANGE
))
280 INT CurSel
= TabCtrl_GetCurSel(hTabCtrlWnd
);
282 /* enable/disable next button */
283 EnableWindow(GetDlgItem(hwndDlg
, IDC_BUTTON_NEXT
),
284 (CurSel
!= TabCtrl_GetItemCount(hTabCtrlWnd
) - 1));
286 TabCtrl_OnSelChange(pContext
);
290 DestroyTabCtrlDialogs(pContext
);
291 return DefWindowProc(hwndDlg
, message
, wParam
, lParam
);
296 int APIENTRY
wWinMain(HINSTANCE hInstance
,
297 HINSTANCE hPrevInstance
,
302 INITCOMMONCONTROLSEX InitControls
;
304 UNREFERENCED_PARAMETER(hPrevInstance
);
305 UNREFERENCED_PARAMETER(lpCmdLine
);
306 UNREFERENCED_PARAMETER(nCmdShow
);
308 InitControls
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
309 InitControls
.dwICC
= ICC_TAB_CLASSES
| ICC_LISTVIEW_CLASSES
| ICC_STANDARD_CLASSES
| ICC_TREEVIEW_CLASSES
;
310 InitCommonControlsEx(&InitControls
);
314 DialogBox(hInst
, MAKEINTRESOURCE(IDD_MAIN_DIALOG
), NULL
, DxDiagWndProc
);