From 84d4c7f4dadd31a073f1a86b77745cacd040fa1d Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Tue, 29 Apr 2008 12:19:55 +0000 Subject: [PATCH] - fix flickering of DirectDraw tests by Pigglesworth (Kamil Hornicek) - enumerate all available display / sound adapters dynamically at start (does not work yet) - rewrite TabCtrl_OnSelChange to reflect changes svn path=/trunk/; revision=33188 --- reactos/base/applications/dxdiag/ddtest.c | 49 +++++++++++-- reactos/base/applications/dxdiag/display.c | 65 +++++++++++++++-- reactos/base/applications/dxdiag/dxdiag.c | 85 ++++++++++++++-------- reactos/base/applications/dxdiag/precomp.h | 17 ++++- reactos/base/applications/dxdiag/sound.c | 57 +++++++++++++++ 5 files changed, 225 insertions(+), 48 deletions(-) diff --git a/reactos/base/applications/dxdiag/ddtest.c b/reactos/base/applications/dxdiag/ddtest.c index b4bd8a928ba..a68980d2a15 100644 --- a/reactos/base/applications/dxdiag/ddtest.c +++ b/reactos/base/applications/dxdiag/ddtest.c @@ -7,23 +7,22 @@ * */ - #include "precomp.h" BOOL DDPrimarySurfaceTest(HWND hWnd); BOOL DDOffscreenBufferTest(HWND hWnd, BOOL Fullscreen); VOID DDRedrawFrame(LPDIRECTDRAWSURFACE lpDDSurface); VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD); +LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -#define TEST_DURATION 5000 -#define WIDTH 800 -#define HEIGHT 600 +#define TEST_DURATION 10000 +#define WIDTH 640 +#define HEIGHT 480 #define DD_TEST_STEP 5 #define DD_SQUARE_SIZE 100 #define DD_SQUARE_STEP 2 - BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr) { WCHAR szTestDescription[256]; @@ -70,19 +69,50 @@ BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT res return FALSE; } -VOID DDTests(HWND hWnd, HINSTANCE hInstance) +VOID DDTests() { + WNDCLASSEX winClass; + HWND hWnd; + HINSTANCE hInstance = NULL; WCHAR szDescription[256]; WCHAR szCaption[256]; + winClass.cbSize = sizeof(WNDCLASSEX); + winClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + winClass.lpfnWndProc = WindowProc; + winClass.cbClsExtra = 0; + winClass.cbWndExtra = 0; + winClass.hInstance = hInstance; + winClass.hIcon = 0; + winClass.hCursor = 0; + winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + winClass.lpszMenuName = NULL; + winClass.lpszClassName = L"ddtest"; + winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + if (!RegisterClassEx(&winClass)) + return; + + hWnd = CreateWindowEx(0, winClass.lpszClassName, NULL,WS_POPUP, + (GetSystemMetrics(SM_CXSCREEN) - WIDTH)/2, + (GetSystemMetrics(SM_CYSCREEN) - HEIGHT)/2, + WIDTH, HEIGHT, NULL, NULL, hInstance, NULL); + + if (!hWnd){ + return; + } + LoadStringW(hInstance, IDS_DDTEST_DESCRIPTION, szDescription, sizeof(szDescription) / sizeof(WCHAR)); LoadStringW(hInstance, IDS_DDTEST_DESCRIPTION, szCaption, sizeof(szCaption) / sizeof(WCHAR)); if(MessageBox(NULL, szDescription, szCaption, MB_YESNO | MB_ICONQUESTION) == IDNO) - PostQuitMessage(0); + return; StartDDTest(hWnd, hInstance, IDS_DDPRIMARY_DESCRIPTION, IDS_DDPRIMARY_RESULT, 1); StartDDTest(hWnd, hInstance, IDS_DDOFFSCREEN_DESCRIPTION, IDS_DDOFFSCREEN_RESULT, 2); StartDDTest(hWnd, hInstance, IDS_DDFULLSCREEN_DESCRIPTION, IDS_DDFULLSCREEN_RESULT, 3); + + DestroyWindow(hWnd); + UnregisterClass(winClass.lpszClassName, hInstance); } BOOL DDPrimarySurfaceTest(HWND hWnd){ @@ -334,3 +364,8 @@ VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE l } } } + +LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + return DefWindowProc(hWnd, msg, wParam, lParam); +} diff --git a/reactos/base/applications/dxdiag/display.c b/reactos/base/applications/dxdiag/display.c index 213cb55e52e..946d46ce8eb 100644 --- a/reactos/base/applications/dxdiag/display.c +++ b/reactos/base/applications/dxdiag/display.c @@ -173,9 +173,16 @@ InitializeDialog(HWND hwndDlg) HWND hDlgCtrls[3]; DWORD dwMemory; DEVMODE DevMode; - DISPLAY_DEVICEW DispDevice; + /// FIXME + /// use initialization context + /// + ZeroMemory(&DispDevice, sizeof(DISPLAY_DEVICEW)); + DispDevice.cb = sizeof(DISPLAY_DEVICEW); + if (!EnumDisplayDevicesW(NULL, 0, &DispDevice, 0)) + return FALSE; + /* query display device adapter */ ZeroMemory(&DispDevice, sizeof(DISPLAY_DEVICEW)); DispDevice.cb = sizeof(DISPLAY_DEVICEW); @@ -275,6 +282,56 @@ InitializeDialog(HWND hwndDlg) return TRUE; } +void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext) +{ + DISPLAY_DEVICEW DispDevice; + HWND * hDlgs; + HWND hwndDlg; + WCHAR szDisplay[20]; + WCHAR szText[30]; + DWORD dwOffset = 0; + + while(TRUE) + { + ZeroMemory(&DispDevice, sizeof(DISPLAY_DEVICEW)); + DispDevice.cb = sizeof(DISPLAY_DEVICEW); + if (!EnumDisplayDevicesW(NULL, pContext->NumDisplayAdapter + dwOffset, &DispDevice, 0)) + return; + + /* skip devices not attached to the desktop and mirror drivers */ + if (!(DispDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) || (DispDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)) + { + dwOffset++; + continue; + } + if (pContext->NumDisplayAdapter) + hDlgs = HeapReAlloc(GetProcessHeap(), 0, pContext->hDisplayWnd, (pContext->NumDisplayAdapter + 1) * sizeof(HWND)); + else + hDlgs = HeapAlloc(GetProcessHeap(), 0, (pContext->NumDisplayAdapter + 1) * sizeof(HWND)); + + if (!hDlgs) + break; + + pContext->hDisplayWnd = hDlgs; + hwndDlg = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_DISPLAY_DIALOG), pContext->hMainDialog, DisplayPageWndProc, (LPARAM)pContext); + if (!hwndDlg) + break; + + szDisplay[0] = L'\0'; + LoadStringW(hInst, IDS_DISPLAY_DIALOG, szDisplay, sizeof(szDisplay)/sizeof(WCHAR)); + szDisplay[(sizeof(szDisplay)/sizeof(WCHAR))-1] = L'\0'; + + swprintf (szText, L"%s %u", szDisplay, pContext->NumDisplayAdapter + 1); + InsertTabCtrlItem(GetDlgItem(pContext->hMainDialog, IDC_TAB_CONTROL), pContext->NumDisplayAdapter + 1, szText); + + hDlgs[pContext->NumDisplayAdapter] = hwndDlg; + pContext->NumDisplayAdapter++; + } + + +} + + INT_PTR CALLBACK DisplayPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { @@ -295,11 +352,7 @@ DisplayPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { case IDC_BUTTON_TESTDD: /* FIXME log result errors */ - ShowWindow(pContext->hMainDialog, SW_HIDE); - StartDDTest(pContext->hMainDialog, hInst, IDS_DDPRIMARY_DESCRIPTION, IDS_DDPRIMARY_RESULT, 1); - StartDDTest(pContext->hMainDialog, hInst, IDS_DDOFFSCREEN_DESCRIPTION, IDS_DDOFFSCREEN_RESULT, 2); - StartDDTest(pContext->hMainDialog, hInst, IDS_DDFULLSCREEN_DESCRIPTION, IDS_DDFULLSCREEN_RESULT, 3); - ShowWindow(pContext->hMainDialog, SW_SHOW); + DDTests(); /* FIXME resize window */ break; } diff --git a/reactos/base/applications/dxdiag/dxdiag.c b/reactos/base/applications/dxdiag/dxdiag.c index d25b6d90b5e..45f86ed63ea 100644 --- a/reactos/base/applications/dxdiag/dxdiag.c +++ b/reactos/base/applications/dxdiag/dxdiag.c @@ -28,21 +28,29 @@ DestroyTabCtrlDialogs(PDXDIAG_CONTEXT pContext) //--------------------------------------------------------------- VOID -InsertTabCtrlItem(HWND hDlgCtrl, INT Position, UINT uId) +InsertTabCtrlItem(HWND hDlgCtrl, INT Position, LPWSTR uId) { WCHAR szName[100]; TCITEMW item; - /* load item name */ - szName[0] = L'\0'; - if (!LoadStringW(hInst, uId, szName, 100)) - return; - szName[99] = L'\0'; - /* setup item info */ memset(&item, 0, sizeof(TCITEM)); item.mask = TCIF_TEXT; - item.pszText = szName; + + /* load item name */ + if (!HIWORD(uId)) + { + szName[0] = L'\0'; + if (!LoadStringW(hInst, LOWORD(uId), szName, 100)) + return; + szName[99] = L'\0'; + item.pszText = szName; + } + else + { + item.pszText = uId; + } + SendMessageW(hDlgCtrl, TCM_INSERTITEM, Position, (LPARAM)&item); } @@ -55,42 +63,55 @@ TabCtrl_OnSelChange(PDXDIAG_CONTEXT pContext) /* retrieve new page */ CurSel = TabCtrl_GetCurSel(hTabCtrlWnd); - if (CurSel < 0 || CurSel > 7) + if (CurSel < 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 5) return; - /* show active page */ - for(Index = 0; Index < 7; Index++) - { - if (Index == CurSel) - ShowWindow(pContext->hDialogs[Index], SW_SHOW); - else - ShowWindow(pContext->hDialogs[Index], SW_HIDE); - } -} + /* hide all windows */ + for(Index = 0; Index < 5; Index++) + ShowWindow(pContext->hDialogs[Index], SW_HIDE); + for(Index = 0; Index < pContext->NumDisplayAdapter; Index++) + ShowWindow(pContext->hDisplayWnd[Index], SW_HIDE); + + for(Index = 0; Index < pContext->NumSoundAdapter; Index++) + ShowWindow(pContext->hSoundWnd[Index], SW_HIDE); + + + if (CurSel == 0 || CurSel > pContext->NumDisplayAdapter + pContext->NumSoundAdapter) + { + ShowWindow(pContext->hDialogs[min(0, CurSel-pContext->NumDisplayAdapter-pContext->NumSoundAdapter)], SW_SHOW); + return; + } + + if (CurSel -1 < pContext->NumDisplayAdapter) + { + ShowWindow(pContext->hDisplayWnd[CurSel-1], SW_SHOW); + return; + } + + CurSel -= pContext->NumDisplayAdapter + 1; + ShowWindow(pContext->hSoundWnd[CurSel], SW_SHOW); +} VOID InitializeTabCtrl(HWND hwndDlg, PDXDIAG_CONTEXT pContext) { /* create the dialogs */ pContext->hDialogs[0] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SYSTEM_DIALOG), hwndDlg, SystemPageWndProc, (LPARAM)pContext); - pContext->hDialogs[1] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_DISPLAY_DIALOG), hwndDlg, DisplayPageWndProc, (LPARAM)pContext); - pContext->hDialogs[2] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SOUND_DIALOG), hwndDlg, SoundPageWndProc, (LPARAM)pContext); - pContext->hDialogs[3] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_MUSIC_DIALOG), hwndDlg, MusicPageWndProc, (LPARAM)pContext); - pContext->hDialogs[4] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_INPUT_DIALOG), hwndDlg, InputPageWndProc, (LPARAM)pContext); - pContext->hDialogs[5] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_NETWORK_DIALOG), hwndDlg, NetworkPageWndProc, (LPARAM)pContext); - pContext->hDialogs[6] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_HELP_DIALOG), hwndDlg, HelpPageWndProc, (LPARAM)pContext); + pContext->hDialogs[1] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_MUSIC_DIALOG), hwndDlg, MusicPageWndProc, (LPARAM)pContext); + pContext->hDialogs[2] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_INPUT_DIALOG), hwndDlg, InputPageWndProc, (LPARAM)pContext); + pContext->hDialogs[3] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_NETWORK_DIALOG), hwndDlg, NetworkPageWndProc, (LPARAM)pContext); + pContext->hDialogs[4] = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_HELP_DIALOG), hwndDlg, HelpPageWndProc, (LPARAM)pContext); /* insert tab ctrl items */ hTabCtrlWnd = GetDlgItem(hwndDlg, IDC_TAB_CONTROL); - InsertTabCtrlItem(hTabCtrlWnd, 0, IDS_SYSTEM_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 1, IDS_DISPLAY_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 2, IDS_SOUND_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 3, IDS_MUSIC_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 4, IDS_INPUT_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 5, IDS_NETWORK_DIALOG); - InsertTabCtrlItem(hTabCtrlWnd, 6, IDS_HELP_DIALOG); - + InsertTabCtrlItem(hTabCtrlWnd, 0, MAKEINTRESOURCEW(IDS_SYSTEM_DIALOG)); + InitializeDisplayAdapters(pContext); + InitializeDirectSoundPage(pContext); + InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 1, MAKEINTRESOURCEW(IDS_MUSIC_DIALOG)); + InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 2, MAKEINTRESOURCEW(IDS_INPUT_DIALOG)); + InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 3, MAKEINTRESOURCEW(IDS_NETWORK_DIALOG)); + InsertTabCtrlItem(hTabCtrlWnd, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 4, MAKEINTRESOURCEW(IDS_HELP_DIALOG)); TabCtrl_OnSelChange(pContext); } diff --git a/reactos/base/applications/dxdiag/precomp.h b/reactos/base/applications/dxdiag/precomp.h index 1ef14b5a728..4e55a02dd85 100644 --- a/reactos/base/applications/dxdiag/precomp.h +++ b/reactos/base/applications/dxdiag/precomp.h @@ -20,7 +20,11 @@ typedef struct { HWND hMainDialog; - HWND hDialogs[7]; + ULONG NumDisplayAdapter; + HWND * hDisplayWnd; + ULONG NumSoundAdapter; + HWND * hSoundWnd; + HWND hDialogs[5]; }DXDIAG_CONTEXT, *PDXDIAG_CONTEXT; @@ -39,9 +43,16 @@ INT_PTR CALLBACK NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPAR INT_PTR CALLBACK HelpPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size); -/* DirectDraw tests */ -BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr); +VOID InsertTabCtrlItem(HWND hDlgCtrl, INT Position, LPWSTR uId); +/* DirectDraw tests */ +VOID DDTests(); + +/* DirectSound initialization */ +void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext); + +/* display adapter initialization */ +void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext); BOOL GetFileVersion(LPCWSTR szAppName, WCHAR * szVer, DWORD szVerSize); BOOL GetFileModifyTime(LPCWSTR pFullPath, WCHAR * szTime, int szTimeSize); diff --git a/reactos/base/applications/dxdiag/sound.c b/reactos/base/applications/dxdiag/sound.c index 83db305ce6e..00d69913b73 100644 --- a/reactos/base/applications/dxdiag/sound.c +++ b/reactos/base/applications/dxdiag/sound.c @@ -9,6 +9,62 @@ #include "precomp.h" +BOOL CALLBACK DSEnumCallback(LPGUID lpGuid, LPCWSTR lpcstrDescription, LPCWSTR lpcstrModule, LPVOID lpContext) +{ + PDXDIAG_CONTEXT pContext = (PDXDIAG_CONTEXT)lpContext; + HWND * hDlgs; + HWND hwndDlg; + WCHAR szSound[20]; + WCHAR szText[30]; + + if (!lpGuid) + return TRUE; + + if (pContext->NumSoundAdapter) + hDlgs = HeapReAlloc(GetProcessHeap(), 0, pContext->hSoundWnd, (pContext->NumSoundAdapter + 1) * sizeof(HWND)); + else + hDlgs = HeapAlloc(GetProcessHeap(), 0, (pContext->NumSoundAdapter + 1) * sizeof(HWND)); + + if (!hDlgs) + return FALSE; + + pContext->hSoundWnd = hDlgs; + hwndDlg = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SOUND_DIALOG), pContext->hMainDialog, SoundPageWndProc, (LPARAM)pContext); + if (!hwndDlg) + return FALSE; + + szSound[0] = L'\0'; + LoadStringW(hInst, IDS_SOUND_DIALOG, szSound, sizeof(szSound)/sizeof(WCHAR)); + szSound[(sizeof(szSound)/sizeof(WCHAR))-1] = L'\0'; + + swprintf (szText, L"%s %u", szSound, pContext->NumSoundAdapter + 1); + + + InsertTabCtrlItem(GetDlgItem(pContext->hMainDialog, IDC_TAB_CONTROL), pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 1, szText); + + hDlgs[pContext->NumSoundAdapter] = hwndDlg; + pContext->NumSoundAdapter++; + + return TRUE; +} + + +void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext) +{ + HRESULT hResult; + //IDirectSound8 *pObj; + + /* create DSound object */ +// hResult = DirectSoundCreate8(NULL, (LPDIRECTSOUND8*)&pObj, NULL); +// if (hResult != DS_OK) +// return; + hResult = DirectSoundEnumerateW(DSEnumCallback, pContext); + + /* release the DSound object */ +// pObj->lpVtbl->Release(pObj); +} + + INT_PTR CALLBACK SoundPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { @@ -18,6 +74,7 @@ SoundPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: { SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); + //InitializeDirectSoundPage(hDlg); return TRUE; } }