ReactOS  r76032
dxdiag.c
Go to the documentation of this file.
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 */
15 
17 // Taken from WinSpy++ 1.7
18 // http://www.catch22.net/software/winspy
19 // Copyright (c) 2002 by J Brown
20 //
21 
22 //
23 // Copied from uxtheme.h
24 // If you have this new header, then delete these and
25 // #include <uxtheme.h> instead!
26 //
27 #define ETDT_DISABLE 0x00000001
28 #define ETDT_ENABLE 0x00000002
29 #define ETDT_USETABTEXTURE 0x00000004
30 #define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE)
31 
32 //
33 typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD);
34 
35 //
36 // Try to call EnableThemeDialogTexture, if uxtheme.dll is present
37 //
39 {
40  HMODULE hUXTheme;
42 
43  hUXTheme = LoadLibraryA("uxtheme.dll");
44 
45  if(hUXTheme)
46  {
47  fnEnableThemeDialogTexture =
48  (ETDTProc)GetProcAddress(hUXTheme, "EnableThemeDialogTexture");
49 
50  if(fnEnableThemeDialogTexture)
51  {
53 
54  FreeLibrary(hUXTheme);
55  return TRUE;
56  }
57  else
58  {
59  // Failed to locate API!
60  FreeLibrary(hUXTheme);
61  return FALSE;
62  }
63  }
64  else
65  {
66  // Not running under XP? Just fail gracefully
67  return FALSE;
68  }
69 }
70 
71 //---------------------------------------------------------------
72 VOID
74 {
75  UINT Index;
76 
77  /* destroy default dialogs */
78  for(Index = 0; Index < sizeof(pContext->hDialogs) / sizeof(HWND); Index++)
79  {
80  if (pContext->hDialogs[Index])
81  DestroyWindow(pContext->hDialogs[Index]);
82  }
83 
84  /* destroy display dialogs */
85  for(Index = 0; Index < pContext->NumDisplayAdapter; Index++)
86  {
87  if (pContext->hDisplayWnd[Index])
88  DestroyWindow(pContext->hDisplayWnd[Index]);
89  }
90 
91  /* destroy audio dialogs */
92  for(Index = 0; Index < pContext->NumSoundAdapter; Index++)
93  {
94  if (pContext->hSoundWnd[Index])
95  DestroyWindow(pContext->hSoundWnd[Index]);
96  }
97 
98 }
99 
100 //---------------------------------------------------------------
101 VOID
103 {
104  WCHAR szName[100];
105  TCITEMW item;
106 
107  /* setup item info */
108  memset(&item, 0, sizeof(TCITEMW));
109  item.mask = TCIF_TEXT;
110 
111  /* load item name */
112  if (!HIWORD(uId))
113  {
114  szName[0] = L'\0';
115  if (!LoadStringW(hInst, LOWORD(uId), szName, 100))
116  return;
117  szName[99] = L'\0';
118  item.pszText = szName;
119  }
120  else
121  {
122  item.pszText = uId;
123  }
124 
125 
126  SendMessageW(hDlgCtrl, TCM_INSERTITEM, Position, (LPARAM)&item);
127 }
128 
129 VOID
131 {
132  INT Index;
133  INT CurSel;
134 
135  /* retrieve new page */
136  CurSel = TabCtrl_GetCurSel(hTabCtrlWnd);
137  if (CurSel < 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 5)
138  return;
139 
140  /* hide all windows */
141  for(Index = 0; Index < 5; Index++)
142  ShowWindow(pContext->hDialogs[Index], SW_HIDE);
143 
144  for(Index = 0; Index < pContext->NumDisplayAdapter; Index++)
145  ShowWindow(pContext->hDisplayWnd[Index], SW_HIDE);
146 
147  for(Index = 0; Index < pContext->NumSoundAdapter; Index++)
148  ShowWindow(pContext->hSoundWnd[Index], SW_HIDE);
149 
150 
151  if (CurSel == 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter)
152  {
153  if (CurSel)
154  CurSel -= pContext->NumDisplayAdapter + pContext->NumSoundAdapter;
155  ShowWindow(pContext->hDialogs[CurSel], SW_SHOW);
156  return;
157  }
158 
159  if (CurSel -1 < pContext->NumDisplayAdapter)
160  {
161  ShowWindow(pContext->hDisplayWnd[CurSel-1], SW_SHOW);
162  return;
163  }
164 
165  CurSel -= pContext->NumDisplayAdapter + 1;
166  ShowWindow(pContext->hSoundWnd[CurSel], SW_SHOW);
167 }
168 
169 VOID
171 {
172  /* get tabctrl */
174  pContext->hTabCtrl = hTabCtrlWnd;
175 
176  /* create the dialogs */
177  pContext->hDialogs[0] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SYSTEM_DIALOG), pContext->hTabCtrl, SystemPageWndProc, (LPARAM)pContext); EnableDialogTheme(pContext->hDialogs[0]);
178  pContext->hDialogs[1] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_MUSIC_DIALOG), pContext->hTabCtrl, MusicPageWndProc, (LPARAM)pContext); EnableDialogTheme(pContext->hDialogs[1]);
179  pContext->hDialogs[2] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_INPUT_DIALOG), pContext->hTabCtrl, InputPageWndProc, (LPARAM)pContext); EnableDialogTheme(pContext->hDialogs[2]);
180  pContext->hDialogs[3] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_NETWORK_DIALOG), pContext->hTabCtrl, NetworkPageWndProc, (LPARAM)pContext); EnableDialogTheme(pContext->hDialogs[3]);
181  pContext->hDialogs[4] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_HELP_DIALOG), pContext->hTabCtrl, HelpPageWndProc, (LPARAM)pContext); EnableDialogTheme(pContext->hDialogs[4]);
182 
183  /* insert tab ctrl items */
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);
192 }
193 
194 VOID
196 {
198  HICON hIcon;
199 
201  if (!pContext)
202  return;
203 
204  /* store window handle */
205  pContext->hMainDialog = hwndDlg;
206 
207  /* store the context */
208  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
209 
210  /* initialize the tab ctrl */
211  InitializeTabCtrl(hwndDlg, pContext);
212 
213  /* load application icon */
214  hIcon = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 16, 16, 0);
215  if (!hIcon)
216  return;
217  /* display icon */
218  SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
219 }
220 
221 
224 {
225  LPNMHDR pnmh;
227 
228  pContext = (PDXDIAG_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
229 
230  switch (message)
231  {
232  case WM_INITDIALOG:
233  InitializeDxDiagDialog(hwndDlg);
234  return TRUE;
235  case WM_COMMAND:
236  if (LOWORD(wParam) == IDC_BUTTON_SAVE_INFO)
237  {
238  //TODO
239  /* handle save information */
240  return TRUE;
241  }
242 
243  if (LOWORD(wParam) == IDC_BUTTON_NEXT)
244  {
245  INT CurSel;
246 
247  /* retrieve current page */
248  CurSel = TabCtrl_GetCurSel(hTabCtrlWnd);
249  CurSel++;
250 
251  /* enable/disable next button */
253  (CurSel != TabCtrl_GetItemCount(hTabCtrlWnd) - 1));
254 
255  /* switch to next tab */
257 
258  /* show next page */
259  TabCtrl_OnSelChange(pContext);
260  return TRUE;
261  }
262 
263  if (LOWORD(wParam) == IDC_BUTTON_HELP)
264  {
265  //TODO
266  /* handle help button */
267  return TRUE;
268  }
269 
270  if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_EXIT) {
271  EndDialog(hwndDlg, LOWORD(wParam));
272  return TRUE;
273  }
274  break;
275 
276  case WM_NOTIFY:
277  pnmh = (LPNMHDR)lParam;
278  if ((pnmh->hwndFrom == hTabCtrlWnd) && (pnmh->idFrom == IDC_TAB_CONTROL) && (pnmh->code == TCN_SELCHANGE))
279  {
281 
282  /* enable/disable next button */
284  (CurSel != TabCtrl_GetItemCount(hTabCtrlWnd) - 1));
285 
286  TabCtrl_OnSelChange(pContext);
287  }
288  break;
289  case WM_DESTROY:
290  DestroyTabCtrlDialogs(pContext);
291  return DefWindowProc(hwndDlg, message, wParam, lParam);
292  }
293  return 0;
294 }
295 
297  HINSTANCE hPrevInstance,
298  LPWSTR lpCmdLine,
299  int nCmdShow)
300 {
301 
303 
304  UNREFERENCED_PARAMETER(hPrevInstance);
305  UNREFERENCED_PARAMETER(lpCmdLine);
306  UNREFERENCED_PARAMETER(nCmdShow);
307 
308  InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
310  InitCommonControlsEx(&InitControls);
311 
312  hInst = hInstance;
313 
315 
316  return 0;
317 }
#define IDD_MUSIC_DIALOG
Definition: resource.h:10
INT_PTR CALLBACK MusicPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: music.c:13
INT_PTR CALLBACK NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: network.c:342
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define TabCtrl_GetItemCount(hwnd)
Definition: commctrl.h:3936
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
VOID InsertTabCtrlItem(HWND hDlgCtrl, INT Position, LPWSTR uId)
Definition: dxdiag.c:102
#define IMAGE_ICON
Definition: winuser.h:212
#define IDC_BUTTON_EXIT
Definition: resource.h:20
VOID InitializeDxDiagDialog(HWND hwndDlg)
Definition: dxdiag.c:195
#define IDC_BUTTON_NEXT
Definition: resource.h:18
#define IDS_NETWORK_DIALOG
Definition: resource.h:109
INT_PTR CALLBACK DxDiagWndProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: dxdiag.c:223
#define IDS_MUSIC_DIALOG
Definition: resource.h:107
Definition: bidi.c:75
typedef HRESULT(WINAPI *ETDTProc)(HWND
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:315
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SW_HIDE
Definition: winuser.h:762
ULONG NumDisplayAdapter
Definition: precomp.h:32
INT_PTR CALLBACK InputPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: input.c:207
#define CALLBACK
Definition: compat.h:27
HWND hTabCtrlWnd
Definition: dxdiag.c:14
HANDLE HWND
Definition: compat.h:13
LPWSTR pszText
Definition: commctrl.h:3990
#define IDC_BUTTON_SAVE_INFO
Definition: resource.h:19
#define TCM_SETCURSEL
Definition: commctrl.h:4032
#define TabCtrl_GetCurSel(hwnd)
Definition: commctrl.h:4030
#define IDS_SYSTEM_DIALOG
Definition: resource.h:104
#define TCIF_TEXT
Definition: commctrl.h:3938
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_TAB_CONTROL
Definition: resource.h:16
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
int32_t INT
Definition: typedefs.h:56
PVOID pContext
Definition: ddkmapi.h:96
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
static VOID InitControls(HWND hwnd)
Definition: mplay32.c:297
struct tagNMHDR * LPNMHDR
void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext)
Definition: sound.c:265
UINT_PTR WPARAM
Definition: windef.h:230
#define ICON_SMALL
Definition: tnclass.cpp:48
#define IDD_SYSTEM_DIALOG
Definition: resource.h:7
UINT code
Definition: winuser.h:3102
INT_PTR CALLBACK SystemPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: system.c:324
#define DialogBox
Definition: winuser.h:5606
HINSTANCE hInstance
Definition: charmap.c:19
#define ICC_TREEVIEW_CLASSES
Definition: commctrl.h:59
#define FALSE
Definition: types.h:117
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2174
LONG_PTR LPARAM
Definition: windef.h:231
UINT_PTR idFrom
Definition: winuser.h:3101
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define IDS_INPUT_DIALOG
Definition: resource.h:108
UINT mask
Definition: commctrl.h:3987
#define APIENTRY
Definition: nt_native.h:48
smooth NULL
Definition: ftsmooth.c:557
struct DXDIAG_CONTEXT * PDXDIAG_CONTEXT
#define ETDT_ENABLETAB
Definition: dxdiag.c:30
VOID DestroyTabCtrlDialogs(PDXDIAG_CONTEXT pContext)
Definition: dxdiag.c:73
#define SW_SHOW
Definition: winuser.h:769
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1581
#define TCM_INSERTITEM
Definition: commctrl.h:4016
#define TCN_SELCHANGE
Definition: commctrl.h:4099
#define FreeLibrary(x)
Definition: compat.h:405
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDD_INPUT_DIALOG
Definition: resource.h:11
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDD_MAIN_DIALOG
Definition: resource.h:6
UINT WPARAM wParam
Definition: precomp.h:53
static ETDTProc fnEnableThemeDialogTexture
Definition: uxthemesupp.c:15
HRESULT(WINAPI * ETDTProc)(HWND, DWORD)
Definition: uxthemesupp.c:14
#define IDD_NETWORK_DIALOG
Definition: resource.h:12
HANDLE HINSTANCE
Definition: typedefs.h:75
HWND * hSoundWnd
Definition: precomp.h:35
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:895
#define DWLP_USER
Definition: winuser.h:857
VOID InitializeTabCtrl(HWND hwndDlg, PDXDIAG_CONTEXT pContext)
Definition: dxdiag.c:170
#define WM_COMMAND
Definition: winuser.h:1706
#define SetWindowLongPtr
Definition: winuser.h:5699
HWND hwndFrom
Definition: winuser.h:3100
#define WINAPI
Definition: msvc.h:20
#define IDI_APPICON
Definition: resource.h:166
UINT64 Position
Definition: acefiex.h:384
HWND hTabCtrl
Definition: precomp.h:31
INT_PTR CALLBACK HelpPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: help.c:13
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
Definition: dxdiag.c:296
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define ICC_LISTVIEW_CLASSES
Definition: commctrl.h:58
ULONG NumSoundAdapter
Definition: precomp.h:34
HINSTANCE hInst
Definition: dxdiag.c:13
static ATOM item
Definition: dde.c:856
#define IDC_BUTTON_HELP
Definition: resource.h:17
typedef DWORD
Definition: dxdiag.c:33
HICON hIcon
Definition: msconfig.c:44
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDD_HELP_DIALOG
Definition: resource.h:13
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
UINT WPARAM LPARAM lParam
Definition: precomp.h:53
HWND * hDisplayWnd
Definition: precomp.h:33
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
HANDLE HMODULE
Definition: typedefs.h:75
HWND hMainDialog
Definition: precomp.h:30
static const WCHAR szName[]
Definition: msipriv.h:1212
#define SendMessage
Definition: winuser.h:5688
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define HIWORD(l)
Definition: typedefs.h:246
HWND hDialogs[5]
Definition: precomp.h:36
#define GetProcAddress(x, y)
Definition: compat.h:410
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
VOID TabCtrl_OnSelChange(PDXDIAG_CONTEXT pContext)
Definition: dxdiag.c:130
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: winuser.h:5642
#define IDCANCEL
Definition: winuser.h:825
#define memset(x, y, z)
Definition: compat.h:39
void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext)
Definition: display.c:312
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define WM_INITDIALOG
Definition: winuser.h:1705
BOOL EnableDialogTheme(HWND hwnd)
Definition: dxdiag.c:38
#define LOWORD(l)
Definition: pedump.c:82
#define WM_NOTIFY
Definition: richedit.h:61
#define IDS_HELP_DIALOG
Definition: resource.h:110
#define ICC_TAB_CLASSES
Definition: commctrl.h:61