⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d3denum.cpp

📁 大家好!这是一个网络游戏源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

//-----------------------------------------------------------------------------
// Name: D3DEnum_GetDevices()
// Desc: Returns a ptr to the array of D3DEnum_DeviceInfo structures.
//-----------------------------------------------------------------------------
VOID D3DEnum_GetDevices( D3DEnum_DeviceInfo** ppDevices, DWORD* pdwCount )
{
    if( ppDevices )
        (*ppDevices) = g_pDeviceList;
    if( pdwCount )
        (*pdwCount)  = g_dwNumDevices;
}




//-----------------------------------------------------------------------------
// Name: UpdateDialogControls()
// Desc: Builds the list of devices and modes for the combo boxes in the device
//       select dialog box.
//-----------------------------------------------------------------------------
static VOID UpdateDialogControls( HWND hDlg, D3DEnum_DeviceInfo* pCurrentDevice,
                                  DWORD dwCurrentMode, BOOL bWindowed,
                                  BOOL bStereo )
{
    /*
	// Get access to the enumerated device list
    D3DEnum_DeviceInfo* pDeviceList;
    DWORD               dwNumDevices;
    D3DEnum_GetDevices( &pDeviceList, &dwNumDevices );

    // Access to UI controls
    
	HWND hwndDevice         = GetDlgItem( hDlg, IDC_DEVICE_COMBO );
    HWND hwndMode           = GetDlgItem( hDlg, IDC_MODE_COMBO );
    HWND hwndWindowed       = GetDlgItem( hDlg, IDC_WINDOWED_CHECKBOX );
    HWND hwndStereo         = GetDlgItem( hDlg, IDC_STEREO_CHECKBOX );
    HWND hwndFullscreenText = GetDlgItem( hDlg, IDC_FULLSCREEN_TEXT );

    // Reset the content in each of the combo boxes
    ComboBox_ResetContent( hwndDevice );
    ComboBox_ResetContent( hwndMode );

    // Don't let non-GDI devices be windowed
    if( FALSE == pCurrentDevice->bDesktopCompatible )
        bWindowed = FALSE;

    // Add a list of devices to the device combo box
    for( DWORD device = 0; device < dwNumDevices; device++ )
    {
        D3DEnum_DeviceInfo* pDevice = &pDeviceList[device];

        // Add device name to the combo box
        DWORD dwItem = ComboBox_AddString( hwndDevice, pDevice->strDesc );
        
        // Set the remaining UI states for the current device
        if( pDevice == pCurrentDevice )
        {
            // Set the combobox selection on the current device
            ComboBox_SetCurSel( hwndDevice, dwItem );

            // Enable/set the fullscreen checkbox, as appropriate
            if( hwndWindowed )
            {
                EnableWindow( hwndWindowed, pDevice->bDesktopCompatible );
                Button_SetCheck( hwndWindowed, bWindowed );
            }
            
            // Enable/set the stereo checkbox, as appropriate
            if( hwndStereo )
            {
                EnableWindow( hwndStereo, pDevice->bStereoCompatible && !bWindowed );
                Button_SetCheck( hwndStereo, bStereo );
            }

            // Enable/set the fullscreen modes combo, as appropriate
            EnableWindow( hwndMode, !bWindowed );
            EnableWindow( hwndFullscreenText, !bWindowed );

            // Build the list of fullscreen modes
            for( DWORD mode = 0; mode < pDevice->dwNumModes; mode++ )
            {
                DDSURFACEDESC2* pddsdMode = &pDevice->pddsdModes[mode];

                // Skip non-stereo modes, if the device is in stereo mode
                if( 0 == (pddsdMode->ddsCaps.dwCaps2&DDSCAPS2_STEREOSURFACELEFT) )
                    if( bStereo )
                        continue;

                TCHAR strMode[80];
                wsprintf( strMode, _T("%ld x %ld x %ld"),
                          pddsdMode->dwWidth, pddsdMode->dwHeight,
                          pddsdMode->ddpfPixelFormat.dwRGBBitCount );

                // Add mode desc to the combo box
                DWORD dwItem = ComboBox_AddString( hwndMode, strMode );

                // Set the item data to identify this mode
                ComboBox_SetItemData( hwndMode, dwItem, mode );

                // Set the combobox selection on the current mode
                if( mode == dwCurrentMode )
                    ComboBox_SetCurSel( hwndMode, dwItem );

                // Since not all modes support stereo, select a default mode in
                // case none was chosen yet.
                if( bStereo && ( CB_ERR == ComboBox_GetCurSel( hwndMode ) ) )
                    ComboBox_SetCurSel( hwndMode, dwItem );
            }
        }
    }*/
}




//-----------------------------------------------------------------------------
// Name: ChangeDeviceProc()
// Desc: Windows message handling function for the device select dialog
//-----------------------------------------------------------------------------
static BOOL CALLBACK ChangeDeviceProc( HWND hDlg, UINT uiMsg, WPARAM wParam, 
                                       LPARAM lParam )
{
        /*
   static D3DEnum_DeviceInfo** ppDeviceArg;
    static D3DEnum_DeviceInfo* pCurrentDevice;
    static DWORD dwCurrentMode;
    static BOOL  bCurrentWindowed;
    static BOOL  bCurrentStereo;

    // Get access to the enumerated device list
    D3DEnum_DeviceInfo* pDeviceList;
    DWORD               dwNumDevices;
    D3DEnum_GetDevices( &pDeviceList, &dwNumDevices );

    // Handle the initialization message
    if( WM_INITDIALOG == uiMsg )
    {
        // Get the app's current device, passed in as an lParam argument        
        ppDeviceArg = (D3DEnum_DeviceInfo**)lParam;
        if( NULL == ppDeviceArg )
            return FALSE;

        // Setup temp storage pointers for dialog
        pCurrentDevice = (*ppDeviceArg);
        dwCurrentMode    = pCurrentDevice->dwCurrentMode;
        bCurrentWindowed = pCurrentDevice->bWindowed;
        bCurrentStereo   = pCurrentDevice->bStereo;

        //UpdateDialogControls( hDlg, pCurrentDevice, dwCurrentMode,
        //                      bCurrentWindowed, bCurrentStereo );

        return TRUE;
    }
    else if( WM_COMMAND == uiMsg )
    {
  		HWND hwndDevice   = GetDlgItem( hDlg, IDC_DEVICE_COMBO );
        HWND hwndMode     = GetDlgItem( hDlg, IDC_MODE_COMBO );
        HWND hwndWindowed = GetDlgItem( hDlg, IDC_WINDOWED_CHECKBOX );
        HWND hwndStereo   = GetDlgItem( hDlg, IDC_STEREO_CHECKBOX );

        // Get current UI state
        DWORD dwDevice   = ComboBox_GetCurSel( hwndDevice );
        DWORD dwModeItem = ComboBox_GetCurSel( hwndMode );
        DWORD dwMode     = ComboBox_GetItemData( hwndMode, dwModeItem );
        BOOL  bWindowed  = hwndWindowed ? Button_GetCheck( hwndWindowed ) : 0;
        BOOL  bStereo    = hwndStereo   ? Button_GetCheck( hwndStereo )   : 0;
		
        
        D3DEnum_DeviceInfo* pDevice = &pDeviceList[dwDevice];
        
        if( IDOK == LOWORD(wParam) )
        {
            // Handle the case when the user hits the OK button. Check if any
            // of the options were changed
            if( pDevice != pCurrentDevice || dwMode != dwCurrentMode ||
                bWindowed != bCurrentWindowed || bStereo != bCurrentStereo )
            {
                // Return the newly selected device and its new properties
                (*ppDeviceArg)              = pDevice;
                pDevice->bWindowed          = bWindowed;
                pDevice->bStereo            = bStereo;
                pDevice->dwCurrentMode      = dwMode;
                pDevice->ddsdFullscreenMode = pDevice->pddsdModes[dwMode];

                EndDialog( hDlg, IDOK );
            }
            else
                EndDialog( hDlg, IDCANCEL );

            return TRUE;
        }
        else if( IDCANCEL == LOWORD(wParam) )
        {
            // Handle the case when the user hits the Cancel button
            EndDialog( hDlg, IDCANCEL );
            return TRUE;
        }
        else if( CBN_SELENDOK == HIWORD(wParam) )
        {
            if( LOWORD(wParam) == IDC_DEVICE_COMBO )
            {
                // Handle the case when the user chooses the device combo
                dwMode    = pDeviceList[dwDevice].dwCurrentMode;
                bWindowed = pDeviceList[dwDevice].bWindowed;
                bStereo   = pDeviceList[dwDevice].bStereo;
            }
        }

        // Keep the UI current
        //UpdateDialogControls( hDlg, &pDeviceList[dwDevice], dwMode, bWindowed, bStereo );
        return TRUE;
    }
*/
    return FALSE;
}




//-----------------------------------------------------------------------------
// Name: D3DEnum_UserChangeDevice()
// Desc: Pops up a dialog which allows the user to select a new device.
//-----------------------------------------------------------------------------
HRESULT D3DEnum_UserChangeDevice( D3DEnum_DeviceInfo** ppDevice )
{
    return E_FAIL;
}




//-----------------------------------------------------------------------------
// Name: D3DEnum_SelectDefaultDevice()
// Desc: Pick a default device, preferably hardware and desktop compatible.
//-----------------------------------------------------------------------------
HRESULT D3DEnum_SelectDefaultDevice( D3DEnum_DeviceInfo** ppDevice,
                                     DWORD dwFlags )
{
    // Check arguments
    if( NULL == ppDevice )
        return E_INVALIDARG;

    // Get access to the enumerated device list
    D3DEnum_DeviceInfo* pDeviceList;
    DWORD               dwNumDevices;
    D3DEnum_GetDevices( &pDeviceList, &dwNumDevices );

    // Look for windowable software, hardware, and hardware TnL devices
    D3DEnum_DeviceInfo* pRefRastDevice     = NULL;
    D3DEnum_DeviceInfo* pSoftwareDevice    = NULL;
    D3DEnum_DeviceInfo* pHardwareDevice    = NULL;
    D3DEnum_DeviceInfo* pHardwareTnLDevice = NULL;

    for( DWORD i=0; i<dwNumDevices; i++ )
    {
        if( pDeviceList[i].bDesktopCompatible )
        {
            if( pDeviceList[i].bHardware )
            {
                if( (*pDeviceList[i].pDeviceGUID) == IID_IDirect3DTnLHalDevice )
                    pHardwareTnLDevice = &pDeviceList[i];
                else
                    pHardwareDevice = &pDeviceList[i];
            }
            else
            {
                if( (*pDeviceList[i].pDeviceGUID) == IID_IDirect3DRefDevice )
                    pRefRastDevice = &pDeviceList[i];
                else
                    pSoftwareDevice = &pDeviceList[i];
            }
        }
    }

    // Prefer a hardware TnL device first, then a non-TnL hardware device, and
    // finally, a software device.
    if( 0 == ( dwFlags & D3DENUM_SOFTWAREONLY ) && pHardwareTnLDevice )
        (*ppDevice) = pHardwareTnLDevice;
    else if( 0 == ( dwFlags & D3DENUM_SOFTWAREONLY ) && pHardwareDevice )
        (*ppDevice) = pHardwareDevice;
    else if( pSoftwareDevice )
        (*ppDevice) = pSoftwareDevice;
    else if( pRefRastDevice )
        (*ppDevice) = pRefRastDevice;
    else
        return D3DENUMERR_NOCOMPATIBLEDEVICES;

    // Set the windowed state of the newly selected device  
    (*ppDevice)->bWindowed = TRUE;

    return S_OK;
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -