home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / dxview / dxview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  134.6 KB  |  3,701 lines

  1. /****************************************************************************
  2.  
  3.     Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4.  
  5.     PROGRAM: dxview.c
  6.  
  7.     PURPOSE: DirectX Device Viewer
  8.  
  9.     FUNCTIONS:
  10.  
  11.     COMMENTS:
  12.  
  13. ****************************************************************************/
  14.  
  15. #include "dxview.h"
  16.  
  17. #pragma comment(lib, "dxguid")
  18. #pragma comment(lib, "ddraw")
  19. #pragma comment(lib, "dsound")
  20. #pragma comment(lib, "dplayx")
  21. #pragma comment(lib, "dinput")
  22. #pragma comment(lib, "comctl32")
  23.  
  24. /****************************************************************************
  25.  ***************************************************************************/
  26.  
  27. HINSTANCE   g_hInstance;
  28. char        g_szAppName[]   = "DXView";
  29. char        g_szClassName[] = "DXView";
  30. char        g_szTitle[]     = "DirectX Device Viewer";
  31. HWND        g_hwndMain;
  32.  
  33. HWND        g_hwndLV;        // List view
  34. HWND        g_hwndTV;        // Tree view
  35. HIMAGELIST  g_hImageList;
  36. HFONT       g_hFont;
  37. int         g_xPaneSplit;
  38. int         g_xHalfSplitWidth;
  39. BOOL        g_bSplitMove;
  40. DWORD       g_dwViewState;
  41. DWORD       g_tmAveCharWidth;
  42. extern BOOL g_PrintToFile;
  43. UINT        g_idTimer;
  44. LPLOCALAPP    g_lpLocalApp;
  45.  
  46. HINSTANCE g_hDSoundLib = NULL;
  47.  
  48. typedef HRESULT (WINAPI * PFN_DSCREATE)(LPGUID lpguid, LPDIRECTSOUND * ppDS, IUnknown FAR * pUnkOuter);
  49. typedef BOOL (WINAPI * PFN_DSENUMERATE)(LPDSENUMCALLBACK lpDSEnumCallback, LPVOID lpContext);
  50. typedef HRESULT (WINAPI * PFN_DSCCREATE)(LPGUID lpGUID,    LPDIRECTSOUNDCAPTURE *lplpDSC,LPUNKNOWN pUnkOuter);
  51. typedef BOOL (WINAPI * PFN_DSCENUMERATE)(LPDSENUMCALLBACK lpDSEnumCallback,LPVOID lpContext);
  52.  
  53. /****************************************************************************
  54.  ***************************************************************************/
  55.  
  56. IDirectDraw *lpDD;                  // DirectDraw object
  57. IDirectDraw2 *lpDD2;                // DirectDraw object
  58. IDirect3D2  *lp3D;                  // Direct3D object
  59. GUID *       ddid;
  60.  
  61. IDirectSound *lpDS;                 // DirectSound object
  62. GUID *       dsid;
  63.  
  64. IDirectSoundCapture *lpDSC;         // DirectSoundCapture object
  65. GUID *       dscid;
  66.  
  67. IDirectPlay3A  *lpDP3A;             // DirectPlay object
  68. GUID *       dpid;
  69.  
  70. /****************************************************************************
  71.  ***************************************************************************/
  72.  
  73. #define DDCAPDEF(name,val,flag) {name, FIELD_OFFSET(DDCAPS,val), flag}
  74. #define DDVALDEF(name,val)      {name, FIELD_OFFSET(DDCAPS,val), 0}
  75. #define DDHEXDEF(name,val)      {name, FIELD_OFFSET(DDCAPS,val), 0xFFFFFFFF}
  76. #define ROPDEF(name,dwRops,rop) DDCAPDEF(name,dwRops[((rop>>16)&0xFF)/32],(1<<((rop>>16)&0xFF)%32))
  77.  
  78. #define DSCAPDEF(name,val,flag) {name, FIELD_OFFSET(DSCAPS,val), flag}
  79. #define DSVALDEF(name,val)      {name, FIELD_OFFSET(DSCAPS,val), 0}
  80.  
  81. #define DSCCAPDEF(name,val,flag) {name, FIELD_OFFSET(DSCCAPS,val), flag}
  82. #define DSCVALDEF(name,val)      {name, FIELD_OFFSET(DSCCAPS,val), 0}
  83.  
  84. #define DPCAPDEF(name,val,flag) {name, FIELD_OFFSET(DPCAPS,val), flag}
  85. #define DPHEXDEF(name,val)      {name, FIELD_OFFSET(DPCAPS,val), 0xFFFFFFFF}
  86. #define DPVALDEF(name,val)      {name, FIELD_OFFSET(DPCAPS,val), 0}
  87.  
  88. #define D3CAPDEF(name,val,flag) {name, FIELD_OFFSET(D3DDEVICEDESC,val), flag}
  89. #define D3HEXDEF(name,val)      {name, FIELD_OFFSET(D3DDEVICEDESC,val), 0xFFFFFFFF}
  90. #define D3VALDEF(name,val)      {name, FIELD_OFFSET(D3DDEVICEDESC,val), 0}
  91.  
  92. #define SURFCAPDEF(name,val,flag) {name, FIELD_OFFSET(DDSURFACEDESC,val), flag}
  93. #define SURFVALDEF(name,val)      {name, FIELD_OFFSET(DDSURFACEDESC,val), 0}
  94.  
  95. #define MAKEMODE(xres,yres,bpp) (((DWORD)xres << 20) | ((DWORD)yres << 8) | bpp)
  96. #define GETXRES(mode)           (int)((mode >> 20) & 0x0FFF)
  97. #define GETYRES(mode)           (int)((mode >> 8)  & 0x0FFF)
  98. #define GETCRES(mode)           (int)((mode >> 0)  & 0x00FF)
  99.  
  100. IDirectDraw * DDCreate(GUID *pid);
  101.  
  102. BOOL PrintValueLine(char * szText, DWORD dwValue, PRINTCBINFO *lpInfo)
  103. {
  104.     char    szBuff[80];
  105.     DWORD cchLen;
  106.     int xName, xVal, yLine;
  107.  
  108.     // Calculate Name and Value column x offsets
  109.     xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  110.     xVal    = xName + (32 * lpInfo->dwCharWidth);
  111.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  112.  
  113.     // Print name
  114.     wsprintf (szBuff, szText);
  115.     cchLen = _tcslen (szText);
  116.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  117.         return FALSE;
  118.  
  119.     // Print value
  120.     wsprintf (szBuff, "%d", dwValue);
  121.     cchLen = _tcslen (szBuff);
  122.     if (! PrintLine (xVal, yLine, szBuff, cchLen, lpInfo))
  123.         return FALSE;
  124.  
  125.     // Advance to next line on page
  126.     if (! PrintNextLine (lpInfo))
  127.         return FALSE;
  128.  
  129.    return TRUE;
  130. }
  131.  
  132. VOID VidMem(long lParam1, long foo2)
  133. {
  134.     HRESULT ddrval;
  135.     DWORD dwTotalMem;
  136.     DWORD dwFreeMem;
  137.     DDSCAPS DDSCaps;
  138.  
  139.     LVAddColumn(g_hwndLV, 0, "Type", 24);
  140.     LVAddColumn(g_hwndLV, 1, "Total", 10);
  141.     LVAddColumn(g_hwndLV, 2, "Free", 10);
  142.  
  143.     if (DDCreate((GUID*)lParam1))
  144.     {
  145.         IDirectDraw_QueryInterface(lpDD,&IID_IDirectDraw2,&lpDD2);
  146.  
  147.         DDSCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
  148.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  149.         if(ddrval != DD_OK)
  150.         {
  151.             dwTotalMem = 0;
  152.             dwFreeMem = 0;
  153.         };
  154.         LVAddText(g_hwndLV, 0, "Video");
  155.         LVAddText(g_hwndLV, 1, "%d", dwTotalMem);
  156.         LVAddText(g_hwndLV, 2, "%d", dwFreeMem);
  157.  
  158.         DDSCaps.dwCaps = DDSCAPS_LOCALVIDMEM;
  159.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  160.         if(ddrval != DD_OK)
  161.         {
  162.             dwTotalMem = 0;
  163.             dwFreeMem = 0;
  164.         };
  165.         LVAddText(g_hwndLV, 0, "Video (local)");
  166.         LVAddText(g_hwndLV, 1, "%d", dwTotalMem);
  167.         LVAddText(g_hwndLV, 2, "%d", dwFreeMem);
  168.  
  169.         DDSCaps.dwCaps = DDSCAPS_NONLOCALVIDMEM;
  170.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  171.         if(ddrval != DD_OK)
  172.         {
  173.             dwTotalMem = 0;
  174.             dwFreeMem = 0;
  175.         };
  176.         LVAddText(g_hwndLV, 0, "Video (non-local)");
  177.         LVAddText(g_hwndLV, 1, "%d", dwTotalMem);
  178.         LVAddText(g_hwndLV, 2, "%d", dwFreeMem);
  179.  
  180.         DDSCaps.dwCaps = DDSCAPS_TEXTURE;
  181.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  182.         if(ddrval != DD_OK)
  183.         {
  184.             dwTotalMem = 0;
  185.             dwFreeMem = 0;
  186.         };
  187.         LVAddText(g_hwndLV, 0, "Texture");
  188.         LVAddText(g_hwndLV, 1, "%d", dwTotalMem);
  189.         LVAddText(g_hwndLV, 2, "%d", dwFreeMem);
  190.     }
  191. }
  192.  
  193. BOOL VidMemPrint(long lParam1, long lParam2, PRINTCBINFO *lpInfo)
  194. {
  195.     HRESULT ddrval;
  196.     DWORD dwTotalMem;
  197.     DWORD dwFreeMem;
  198.     DDSCAPS DDSCaps;
  199.  
  200.     if (DDCreate((GUID*)lParam1))
  201.     {
  202.         IDirectDraw_QueryInterface(lpDD,&IID_IDirectDraw2,&lpDD2);
  203.  
  204.         DDSCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
  205.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  206.         if(ddrval != DD_OK)
  207.         {
  208.             dwTotalMem = 0;
  209.             dwFreeMem = 0;
  210.         };
  211.         PrintValueLine("TotalMem",dwTotalMem,lpInfo);
  212.         PrintValueLine("FreeMem",dwFreeMem,lpInfo);
  213.  
  214.         DDSCaps.dwCaps = DDSCAPS_LOCALVIDMEM;
  215.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  216.         if(ddrval != DD_OK)
  217.         {
  218.             dwTotalMem = 0;
  219.             dwFreeMem = 0;
  220.         };
  221.         PrintValueLine("TotalVideoMem",dwTotalMem,lpInfo);
  222.         PrintValueLine("FreeVideoMem",dwFreeMem,lpInfo);
  223.  
  224.         DDSCaps.dwCaps = DDSCAPS_NONLOCALVIDMEM;
  225.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  226.         if(ddrval != DD_OK)
  227.         {
  228.             dwTotalMem = 0;
  229.             dwFreeMem = 0;
  230.         };
  231.         PrintValueLine("TotalAGPMem",dwTotalMem,lpInfo);
  232.         PrintValueLine("FreeAGPMem",dwFreeMem,lpInfo);
  233.  
  234.         DDSCaps.dwCaps = DDSCAPS_TEXTURE;
  235.         ddrval = IDirectDraw2_GetAvailableVidMem(lpDD2, &DDSCaps, &dwTotalMem, &dwFreeMem );
  236.         if(ddrval != DD_OK)
  237.         {
  238.             dwTotalMem = 0;
  239.             dwFreeMem = 0;
  240.         };
  241.         PrintValueLine("TotalTextureMem",dwTotalMem,lpInfo);
  242.         PrintValueLine("FreeTextureMem",dwFreeMem,lpInfo);
  243.     }
  244.     return TRUE; 
  245. };
  246.  
  247. /****************************************************************************
  248.  ***************************************************************************/
  249. CAPDEF OtherInfoDefs[] =
  250. {
  251.     DDVALDEF("VidMemTotal",                   dwVidMemTotal),
  252.     DDVALDEF("VidMemFree",                    dwVidMemFree),
  253.     DDHEXDEF("AlphaBltConstBitDepths",        dwAlphaBltConstBitDepths),
  254.     DDCAPDEF("  8",                           dwAlphaBltConstBitDepths, DDBD_8),
  255.     DDCAPDEF("  16",                          dwAlphaBltConstBitDepths, DDBD_16),
  256.     DDCAPDEF("  24",                          dwAlphaBltConstBitDepths, DDBD_24),
  257.     DDCAPDEF("  32",                          dwAlphaBltConstBitDepths, DDBD_32),
  258.     DDHEXDEF("AlphaBltPixelBitDepths",        dwAlphaBltPixelBitDepths),
  259.     DDCAPDEF("  8",                           dwAlphaBltPixelBitDepths, DDBD_8),
  260.     DDCAPDEF("  16",                          dwAlphaBltPixelBitDepths, DDBD_16),
  261.     DDCAPDEF("  24",                          dwAlphaBltPixelBitDepths, DDBD_24),
  262.     DDCAPDEF("  32",                          dwAlphaBltPixelBitDepths, DDBD_32),
  263.     DDHEXDEF("AlphaBltSurfaceBitDepths",      dwAlphaBltSurfaceBitDepths),
  264.     DDCAPDEF("  8",                           dwAlphaBltSurfaceBitDepths, DDBD_8),
  265.     DDCAPDEF("  16",                          dwAlphaBltSurfaceBitDepths, DDBD_16),
  266.     DDCAPDEF("  24",                          dwAlphaBltSurfaceBitDepths, DDBD_24),
  267.     DDCAPDEF("  32",                          dwAlphaBltSurfaceBitDepths, DDBD_32),
  268.     DDHEXDEF("AlphaOverlayConstBitDepths",    dwAlphaOverlayConstBitDepths),
  269.     DDCAPDEF("  8",                           dwAlphaOverlayConstBitDepths, DDBD_8),
  270.     DDCAPDEF("  16",                          dwAlphaOverlayConstBitDepths, DDBD_16),
  271.     DDCAPDEF("  24",                          dwAlphaOverlayConstBitDepths, DDBD_24),
  272.     DDCAPDEF("  32",                          dwAlphaOverlayConstBitDepths, DDBD_32),
  273.     DDHEXDEF("AlphaOverlayPixelBitDepths",    dwAlphaOverlayPixelBitDepths),
  274.     DDCAPDEF("  8",                           dwAlphaOverlayPixelBitDepths, DDBD_8),
  275.     DDCAPDEF("  16",                          dwAlphaOverlayPixelBitDepths, DDBD_16),
  276.     DDCAPDEF("  24",                          dwAlphaOverlayPixelBitDepths, DDBD_24),
  277.     DDCAPDEF("  32",                          dwAlphaOverlayPixelBitDepths, DDBD_32),
  278.     DDHEXDEF("AlphaOverlaySurfaceBitDepths",  dwAlphaOverlaySurfaceBitDepths),
  279.     DDCAPDEF("  8",                           dwAlphaOverlaySurfaceBitDepths, DDBD_8),
  280.     DDCAPDEF("  16",                          dwAlphaOverlaySurfaceBitDepths, DDBD_16),
  281.     DDCAPDEF("  24",                          dwAlphaOverlaySurfaceBitDepths, DDBD_24),
  282.     DDCAPDEF("  32",                          dwAlphaOverlaySurfaceBitDepths, DDBD_32),
  283.     DDHEXDEF("ZBufferBitDepths",              dwZBufferBitDepths),
  284.     DDCAPDEF("  8",                           dwZBufferBitDepths, DDBD_8),
  285.     DDCAPDEF("  16",                          dwZBufferBitDepths, DDBD_16),
  286.     DDCAPDEF("  24",                          dwZBufferBitDepths, DDBD_24),
  287.     DDCAPDEF("  32",                          dwZBufferBitDepths, DDBD_32),
  288.     DDVALDEF("MaxVisibleOverlays",            dwMaxVisibleOverlays),
  289.     DDVALDEF("CurrVisibleOverlays",           dwCurrVisibleOverlays),
  290.     DDVALDEF("NumFourCCCodes",                dwNumFourCCCodes),
  291.     DDVALDEF("AlignBoundarySrc",              dwAlignBoundarySrc),
  292.     DDVALDEF("AlignSizeSrc",                  dwAlignSizeSrc),
  293.     DDVALDEF("AlignBoundaryDest",             dwAlignBoundaryDest),
  294.     DDVALDEF("AlignSizeDest",                 dwAlignSizeDest),
  295.     DDVALDEF("AlignStrideAlign",              dwAlignStrideAlign),
  296.     DDVALDEF("MinOverlayStretch",             dwMinOverlayStretch),
  297.     DDVALDEF("MaxOverlayStretch",             dwMaxOverlayStretch),
  298.     DDVALDEF("MinLiveVideoStretch",           dwMinLiveVideoStretch),
  299.     DDVALDEF("MaxLiveVideoStretch",           dwMaxLiveVideoStretch),
  300.     DDVALDEF("MinHwCodecStretch",             dwMinHwCodecStretch),
  301.     DDVALDEF("MaxHwCodecStretch",             dwMaxHwCodecStretch),
  302.     DDVALDEF("dwReserved1",                   dwReserved1),
  303.     DDVALDEF("dwReserved2",                   dwReserved2),
  304.     DDVALDEF("dwReserved3",                   dwReserved3),
  305.  
  306.     //DDHEXDEF("dwCaps",                      dwCaps),
  307.     DDVALDEF("dwMaxVideoPorts",               dwMaxVideoPorts),
  308.     DDVALDEF("dwCurrVideoPorts",               dwCurrVideoPorts),
  309.     //DDVALDEF("dwSVBCaps2",                   dwSVBCaps2),
  310.     { "", 0, 0 }
  311. };
  312.  
  313. /****************************************************************************
  314.  ***************************************************************************/
  315.  
  316. #define GEN_CAPS(dwCaps)                                                     \
  317. \
  318.     DDCAPDEF("3D",                        dwCaps, DDCAPS_3D),                   \
  319.     DDCAPDEF("ALIGNBOUNDARYDEST",         dwCaps, DDCAPS_ALIGNBOUNDARYDEST),    \
  320.     DDCAPDEF("ALIGNSIZEDEST",             dwCaps, DDCAPS_ALIGNSIZEDEST),        \
  321.     DDCAPDEF("ALIGNBOUNDARYSRC",          dwCaps, DDCAPS_ALIGNBOUNDARYSRC),     \
  322.     DDCAPDEF("ALIGNSIZESRC",              dwCaps, DDCAPS_ALIGNSIZESRC),         \
  323.     DDCAPDEF("ALIGNSTRIDE",               dwCaps, DDCAPS_ALIGNSTRIDE),          \
  324.     DDCAPDEF("GDI",                       dwCaps, DDCAPS_GDI),                  \
  325.     DDCAPDEF("OVERLAY",                   dwCaps, DDCAPS_OVERLAY),              \
  326.     DDCAPDEF("OVERLAYCANTCLIP",           dwCaps, DDCAPS_OVERLAYCANTCLIP),      \
  327.     DDCAPDEF("OVERLAYFOURCC",             dwCaps, DDCAPS_OVERLAYFOURCC),        \
  328.     DDCAPDEF("OVERLAYSTRETCH",            dwCaps, DDCAPS_OVERLAYSTRETCH),       \
  329.     DDCAPDEF("PALETTE",                   dwCaps, DDCAPS_PALETTE),              \
  330.     DDCAPDEF("PALETTEVSYNC",              dwCaps, DDCAPS_PALETTEVSYNC),         \
  331.     DDCAPDEF("READSCANLINE",              dwCaps, DDCAPS_READSCANLINE),         \
  332.     DDCAPDEF("STEREOVIEW",                dwCaps, DDCAPS_STEREOVIEW),           \
  333.     DDCAPDEF("VBI",                       dwCaps, DDCAPS_VBI),                  \
  334.     DDCAPDEF("ZOVERLAYS",                 dwCaps, DDCAPS_ZOVERLAYS),            \
  335.     DDCAPDEF("NOHARDWARE",                dwCaps, DDCAPS_NOHARDWARE),           \
  336.     DDCAPDEF("BANKSWITCHED",              dwCaps, DDCAPS_BANKSWITCHED),
  337.  
  338.  
  339. #define GEN_CAPS2(dwCaps2)                                                      \
  340.     DDCAPDEF("CERTIFIED",                 dwCaps2,DDCAPS2_CERTIFIED),           \
  341.     DDCAPDEF("NO2DDURING3DSCENE",         dwCaps2,DDCAPS2_NO2DDURING3DSCENE),   \
  342.     DDCAPDEF("VIDEOPORT",                 dwCaps2,DDCAPS2_VIDEOPORT),           \
  343.     DDCAPDEF("AUTOFLIPOVERLAY",           dwCaps2,DDCAPS2_AUTOFLIPOVERLAY),     \
  344.     DDCAPDEF("CANBOBINTERLEAVED",         dwCaps2,DDCAPS2_CANBOBINTERLEAVED),   \
  345.     DDCAPDEF("CANBOBNONINTERLEAVED",      dwCaps2,DDCAPS2_CANBOBNONINTERLEAVED),\
  346.     DDCAPDEF("COLORCONTROLOVERLAY",       dwCaps2,DDCAPS2_COLORCONTROLOVERLAY), \
  347.     DDCAPDEF("COLORCONTROLPRIMARY",       dwCaps2,DDCAPS2_COLORCONTROLPRIMARY), \
  348.     DDCAPDEF("NONLOCALVIDMEM",            dwCaps2,DDCAPS2_NONLOCALVIDMEM),      \
  349.     DDCAPDEF("NONLOCALVIDMEMCAPS",        dwCaps2,DDCAPS2_NONLOCALVIDMEMCAPS),  \
  350.     DDCAPDEF("WIDESURFACES",              dwCaps2,DDCAPS2_WIDESURFACES),        \
  351.     DDCAPDEF("NOPAGELOCKREQUIRED",        dwCaps2,DDCAPS2_NOPAGELOCKREQUIRED),  
  352.  
  353.  
  354. #define GEN_BLTCAPS(dwCaps)                                                     \
  355.     DDCAPDEF("BLT",                       dwCaps, DDCAPS_BLT),                  \
  356.     DDCAPDEF("BLTCOLORFILL",              dwCaps, DDCAPS_BLTCOLORFILL),         \
  357.     DDCAPDEF("BLTDEPTHFILL",              dwCaps, DDCAPS_BLTDEPTHFILL),         \
  358.     DDCAPDEF("BLTFOURCC",                 dwCaps, DDCAPS_BLTFOURCC),            \
  359.     DDCAPDEF("BLTSTRETCH",                dwCaps, DDCAPS_BLTSTRETCH),           \
  360.     DDCAPDEF("BLTQUEUE",                  dwCaps, DDCAPS_BLTQUEUE),             \
  361.     DDCAPDEF("COLORKEY",                  dwCaps, DDCAPS_COLORKEY),             \
  362.     DDCAPDEF("ALPHA",                     dwCaps, DDCAPS_ALPHA),                \
  363.     DDCAPDEF("CKEYHWASSIST",              dwCaps, DDCAPS_COLORKEYHWASSIST),     \
  364.     DDCAPDEF("CANCLIP",                   dwCaps, DDCAPS_CANCLIP),              \
  365.     DDCAPDEF("CANCLIPSTRETCHED",          dwCaps, DDCAPS_CANCLIPSTRETCHED),     \
  366.     DDCAPDEF("CANBLTSYSMEM",              dwCaps, DDCAPS_CANBLTSYSMEM),         \
  367.     DDCAPDEF("ZBLTS",                     dwCaps, DDCAPS_ZBLTS),                
  368.  
  369.  
  370. #define GEN_BLTCAPS2(dwCaps2)                                                   \
  371.     DDCAPDEF("CANDROPZ16BIT",             dwCaps2,DDCAPS2_CANDROPZ16BIT),       \
  372.     DDCAPDEF("NOPAGELOCKREQUIRED",        dwCaps2,DDCAPS2_NOPAGELOCKREQUIRED),  
  373.  
  374.  
  375. /****************************************************************************
  376.  ***************************************************************************/
  377. CAPDEF GenCaps[] =
  378. {
  379.     GEN_CAPS(dwCaps)
  380.     GEN_CAPS2(dwCaps2)
  381.     { "", 0, 0 }
  382. };
  383.  
  384. //
  385. // NOTE GenCaps and CapsDefs are the same
  386. // because some are blt caps that apply to VRAM->VRAM blts and
  387. // some are "general" caps...
  388. //
  389. CAPDEF CapsDefs[] =
  390. {
  391.     GEN_BLTCAPS(dwCaps)
  392.     GEN_BLTCAPS2(dwCaps2)
  393.     { "", 0, 0 }
  394. };
  395. CAPDEF SVBCapsDefs[] =
  396. {
  397.     GEN_BLTCAPS(dwSVBCaps)
  398.     GEN_BLTCAPS2(dwSVBCaps2)
  399.     { "", 0, 0 }
  400. };
  401. CAPDEF VSBCapsDefs[] =
  402. {
  403.     GEN_BLTCAPS(dwVSBCaps)
  404. //  GEN_BLTCAPS2(dwVSBCaps2)
  405.     { "", 0, 0 }
  406. };
  407. CAPDEF SSBCapsDefs[] =
  408. {
  409.     GEN_BLTCAPS(dwSSBCaps)
  410. //  GEN_BLTCAPS2(dwSSBCaps2)
  411.     { "", 0, 0 }
  412. };
  413. CAPDEF NLVBCapsDefs[] =
  414. {
  415.     GEN_BLTCAPS(dwNLVBCaps)
  416.     GEN_BLTCAPS2(dwNLVBCaps2)
  417.     { "", 0, 0 }
  418. };
  419.  
  420. /****************************************************************************
  421.  ***************************************************************************/
  422. #define GEN_CKCAPS(dwCKeyCaps)                                                              \
  423.     DDCAPDEF("DESTBLT",                 dwCKeyCaps, DDCKEYCAPS_DESTBLT),                  \
  424.     DDCAPDEF("DESTBLTCLRSPACE",         dwCKeyCaps, DDCKEYCAPS_DESTBLTCLRSPACE),          \
  425.     DDCAPDEF("DESTBLTCLRSPACEYUV",      dwCKeyCaps, DDCKEYCAPS_DESTBLTCLRSPACEYUV),       \
  426.     DDCAPDEF("DESTBLTYUV",              dwCKeyCaps, DDCKEYCAPS_DESTBLTYUV),               \
  427.     DDCAPDEF("DESTOVERLAY",             dwCKeyCaps, DDCKEYCAPS_DESTOVERLAY),              \
  428.     DDCAPDEF("DESTOVERLAYCLRSPACE",     dwCKeyCaps, DDCKEYCAPS_DESTOVERLAYCLRSPACE),      \
  429.     DDCAPDEF("DESTOVERLAYCLRSPACEYUV",  dwCKeyCaps, DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),   \
  430.     DDCAPDEF("DESTOVERLAYONEACTIVE",    dwCKeyCaps, DDCKEYCAPS_DESTOVERLAYONEACTIVE),     \
  431.     DDCAPDEF("DESTOVERLAYYUV",          dwCKeyCaps, DDCKEYCAPS_DESTOVERLAYYUV),           \
  432.     DDCAPDEF("SRCBLT",                  dwCKeyCaps, DDCKEYCAPS_SRCBLT),                   \
  433.     DDCAPDEF("SRCBLTCLRSPACE",          dwCKeyCaps, DDCKEYCAPS_SRCBLTCLRSPACE),           \
  434.     DDCAPDEF("SRCBLTCLRSPACEYUV",       dwCKeyCaps, DDCKEYCAPS_SRCBLTCLRSPACEYUV),        \
  435.     DDCAPDEF("SRCBLTYUV",               dwCKeyCaps, DDCKEYCAPS_SRCBLTYUV),                \
  436.     DDCAPDEF("SRCOVERLAY",              dwCKeyCaps, DDCKEYCAPS_SRCOVERLAY),               \
  437.     DDCAPDEF("SRCOVERLAYCLRSPACE",      dwCKeyCaps, DDCKEYCAPS_SRCOVERLAYCLRSPACE),       \
  438.     DDCAPDEF("SRCOVERLAYCLRSPACEYUV",   dwCKeyCaps, DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),    \
  439.     DDCAPDEF("SRCOVERLAYONEACTIVE",     dwCKeyCaps, DDCKEYCAPS_SRCOVERLAYONEACTIVE),      \
  440.     DDCAPDEF("SRCOVERLAYYUV",           dwCKeyCaps, DDCKEYCAPS_SRCOVERLAYYUV),
  441.  
  442. CAPDEF CKeyCapsDefs[] =
  443. {
  444.     GEN_CKCAPS(dwCKeyCaps)
  445.     { "", 0, 0}
  446. };
  447. CAPDEF VSBCKeyCapsDefs[] =
  448. {
  449.     GEN_CKCAPS(dwVSBCKeyCaps)
  450.     { "", 0, 0}
  451. };
  452. CAPDEF SVBCKeyCapsDefs[] =
  453. {
  454.     GEN_CKCAPS(dwSVBCKeyCaps)
  455.     { "", 0, 0}
  456. };
  457. CAPDEF SSBCKeyCapsDefs[] =
  458. {
  459.     GEN_CKCAPS(dwSSBCKeyCaps)
  460.     { "", 0, 0}
  461. };
  462. CAPDEF NLVBCKeyCapsDefs[] =
  463. {
  464.     GEN_CKCAPS(dwNLVBCKeyCaps)
  465.     { "", 0, 0}
  466. };
  467.  
  468.  
  469. /****************************************************************************
  470.  ***************************************************************************/
  471. #define GEN_FXCAPS(dwFXCaps)                                                            \
  472.     DDCAPDEF("BLTARITHSTRETCHY",          dwFXCaps, DDFXCAPS_BLTARITHSTRETCHY),         \
  473.     DDCAPDEF("BLTARITHSTRETCHYN",         dwFXCaps, DDFXCAPS_BLTARITHSTRETCHYN),        \
  474.     DDCAPDEF("BLTMIRRORLEFTRIGHT",        dwFXCaps, DDFXCAPS_BLTMIRRORLEFTRIGHT),       \
  475.     DDCAPDEF("BLTMIRRORUPDOWN",           dwFXCaps, DDFXCAPS_BLTMIRRORUPDOWN),          \
  476.     DDCAPDEF("BLTROTATION",               dwFXCaps, DDFXCAPS_BLTROTATION),              \
  477.     DDCAPDEF("BLTROTATION90",             dwFXCaps, DDFXCAPS_BLTROTATION90),            \
  478.     DDCAPDEF("BLTSHRINKX",                dwFXCaps, DDFXCAPS_BLTSHRINKX),               \
  479.     DDCAPDEF("BLTSHRINKXN",               dwFXCaps, DDFXCAPS_BLTSHRINKXN),              \
  480.     DDCAPDEF("BLTSHRINKY",                dwFXCaps, DDFXCAPS_BLTSHRINKY),               \
  481.     DDCAPDEF("BLTSHRINKYN",               dwFXCaps, DDFXCAPS_BLTSHRINKYN),              \
  482.     DDCAPDEF("BLTSTRETCHX",               dwFXCaps, DDFXCAPS_BLTSTRETCHX),              \
  483.     DDCAPDEF("BLTSTRETCHXN",              dwFXCaps, DDFXCAPS_BLTSTRETCHXN),             \
  484.     DDCAPDEF("BLTSTRETCHY",               dwFXCaps, DDFXCAPS_BLTSTRETCHY),              \
  485.     DDCAPDEF("BLTSTRETCHYN",              dwFXCaps, DDFXCAPS_BLTSTRETCHYN),             \
  486.     DDCAPDEF("OVERLAYARITHSTRETCHY",      dwFXCaps, DDFXCAPS_OVERLAYARITHSTRETCHY),     \
  487.     DDCAPDEF("OVERLAYARITHSTRETCHYN",     dwFXCaps, DDFXCAPS_OVERLAYARITHSTRETCHYN),    \
  488.     DDCAPDEF("OVERLAYSHRINKX",            dwFXCaps, DDFXCAPS_OVERLAYSHRINKX),           \
  489.     DDCAPDEF("OVERLAYSHRINKXN",           dwFXCaps, DDFXCAPS_OVERLAYSHRINKXN),          \
  490.     DDCAPDEF("OVERLAYSHRINKY",            dwFXCaps, DDFXCAPS_OVERLAYSHRINKY),           \
  491.     DDCAPDEF("OVERLAYSHRINKYN",           dwFXCaps, DDFXCAPS_OVERLAYSHRINKYN),          \
  492.     DDCAPDEF("OVERLAYSTRETCHX",           dwFXCaps, DDFXCAPS_OVERLAYSTRETCHX),          \
  493.     DDCAPDEF("OVERLAYSTRETCHXN",          dwFXCaps, DDFXCAPS_OVERLAYSTRETCHXN),         \
  494.     DDCAPDEF("OVERLAYSTRETCHY",           dwFXCaps, DDFXCAPS_OVERLAYSTRETCHY),          \
  495.     DDCAPDEF("OVERLAYSTRETCHYN",          dwFXCaps, DDFXCAPS_OVERLAYSTRETCHYN),         \
  496.     DDCAPDEF("OVERLAYMIRRORLEFTRIGHT",    dwFXCaps, DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),   \
  497.     DDCAPDEF("OVERLAYMIRRORUPDOWN",       dwFXCaps, DDFXCAPS_OVERLAYMIRRORUPDOWN),
  498.  
  499. CAPDEF FXCapsDefs[] =
  500. {
  501.     GEN_FXCAPS(dwFXCaps)
  502.     { "", 0, 0}
  503. };
  504. CAPDEF VSBFXCapsDefs[] =
  505. {
  506.     GEN_FXCAPS(dwVSBFXCaps)
  507.     { "", 0, 0}
  508. };
  509. CAPDEF SVBFXCapsDefs[] =
  510. {
  511.     GEN_FXCAPS(dwSVBFXCaps)
  512.     { "", 0, 0}
  513. };
  514. CAPDEF SSBFXCapsDefs[] =
  515. {
  516.     GEN_FXCAPS(dwSSBFXCaps)
  517.     { "", 0, 0}
  518. };
  519. CAPDEF NLVBFXCapsDefs[] =
  520. {
  521.     GEN_FXCAPS(dwNLVBFXCaps)
  522.     { "", 0, 0}
  523. };
  524.  
  525. /****************************************************************************
  526.  ***************************************************************************/
  527. CAPDEF PalCapsDefs[] =
  528. {
  529.     DDCAPDEF("4BIT",              dwPalCaps, DDPCAPS_4BIT),
  530.     DDCAPDEF("8BITENTRIES",       dwPalCaps, DDPCAPS_8BITENTRIES),
  531.     DDCAPDEF("8BIT",              dwPalCaps, DDPCAPS_8BIT),
  532.     DDCAPDEF("INITIALIZE",        dwPalCaps, DDPCAPS_INITIALIZE),
  533.     DDCAPDEF("PRIMARYSURFACE",    dwPalCaps, DDPCAPS_PRIMARYSURFACE),
  534.     DDCAPDEF("PRIMARYSURFACELEFT",dwPalCaps, DDPCAPS_PRIMARYSURFACELEFT),
  535.     DDCAPDEF("VSYNC",             dwPalCaps, DDPCAPS_VSYNC),
  536.     { "", 0, 0}
  537. };
  538.  
  539. /****************************************************************************
  540.  ***************************************************************************/
  541. CAPDEF SurfCapsDefs[] =
  542. {
  543.     DDCAPDEF( "3DDEVICE",             ddsCaps.dwCaps, DDSCAPS_3DDEVICE),
  544.     DDCAPDEF( "ALPHA",                ddsCaps.dwCaps, DDSCAPS_ALPHA),
  545.     DDCAPDEF( "BACKBUFFER",           ddsCaps.dwCaps, DDSCAPS_BACKBUFFER),
  546.     DDCAPDEF( "COMPLEX",              ddsCaps.dwCaps, DDSCAPS_COMPLEX),
  547.     DDCAPDEF( "FLIP",                 ddsCaps.dwCaps, DDSCAPS_FLIP),
  548.     DDCAPDEF( "FRONTBUFFER",          ddsCaps.dwCaps, DDSCAPS_FRONTBUFFER),
  549.     DDCAPDEF( "MIPMAP",               ddsCaps.dwCaps, DDSCAPS_MIPMAP),
  550.     DDCAPDEF( "OFFSCREENPLAIN",       ddsCaps.dwCaps, DDSCAPS_OFFSCREENPLAIN),
  551.     DDCAPDEF( "OVERLAY",              ddsCaps.dwCaps, DDSCAPS_OVERLAY),
  552.     DDCAPDEF( "PALETTE",              ddsCaps.dwCaps, DDSCAPS_PALETTE),
  553.     DDCAPDEF( "PRIMARYSURFACE",       ddsCaps.dwCaps, DDSCAPS_PRIMARYSURFACE),
  554.     DDCAPDEF( "PRIMARYSURFACELEFT",   ddsCaps.dwCaps, DDSCAPS_PRIMARYSURFACELEFT),
  555.     DDCAPDEF( "SYSTEMMEMORY",         ddsCaps.dwCaps, DDSCAPS_SYSTEMMEMORY),
  556.     DDCAPDEF( "TEXTURE",              ddsCaps.dwCaps, DDSCAPS_TEXTURE),
  557.     DDCAPDEF( "VIDEOMEMORY",          ddsCaps.dwCaps, DDSCAPS_VIDEOMEMORY),
  558.     DDCAPDEF( "VISIBLE",              ddsCaps.dwCaps, DDSCAPS_VISIBLE),
  559.     DDCAPDEF( "WRITEONLY",            ddsCaps.dwCaps, DDSCAPS_WRITEONLY),
  560.     DDCAPDEF( "ZBUFFER",              ddsCaps.dwCaps, DDSCAPS_ZBUFFER),
  561.     DDCAPDEF( "OWNDC",                ddsCaps.dwCaps, DDSCAPS_OWNDC),
  562.     DDCAPDEF( "LIVEVIDEO",            ddsCaps.dwCaps, DDSCAPS_LIVEVIDEO),
  563.     DDCAPDEF( "HWCODEC",              ddsCaps.dwCaps, DDSCAPS_HWCODEC),
  564.     DDCAPDEF( "MODEX",                ddsCaps.dwCaps, DDSCAPS_MODEX),
  565.     { "", 0, 0}
  566. };
  567.  
  568. /****************************************************************************
  569.  ***************************************************************************/
  570. CAPDEF SVisionCapsDefs[] =
  571. {
  572.     DDCAPDEF( "ENIGMA",  dwSVCaps, DDSVCAPS_ENIGMA),
  573.     DDCAPDEF( "FLICKER", dwSVCaps, DDSVCAPS_FLICKER),
  574.     DDCAPDEF( "REDBLUE", dwSVCaps, DDSVCAPS_REDBLUE),
  575.     DDCAPDEF( "SPLIT",   dwSVCaps, DDSVCAPS_SPLIT),
  576.     { "", 0, 0}
  577. };
  578.  
  579. /****************************************************************************
  580.  ***************************************************************************/
  581. #define GEN_ROPS(dwRops)                        \
  582.     ROPDEF("SRCCOPY",    dwRops, SRCCOPY),      \
  583.     ROPDEF("SRCPAINT",   dwRops, SRCPAINT),     \
  584.     ROPDEF("SRCAND",     dwRops, SRCAND),       \
  585.     ROPDEF("SRCINVERT",  dwRops, SRCINVERT),    \
  586.     ROPDEF("SRCERASE",   dwRops, SRCERASE),     \
  587.     ROPDEF("NOTSRCCOPY", dwRops, NOTSRCCOPY),   \
  588.     ROPDEF("NOTSRCERASE",dwRops, NOTSRCERASE),  \
  589.     ROPDEF("MERGECOPY",  dwRops, MERGECOPY),    \
  590.     ROPDEF("MERGEPAINT", dwRops, MERGEPAINT),   \
  591.     ROPDEF("PATCOPY",    dwRops, PATCOPY),      \
  592.     ROPDEF("PATPAINT",   dwRops, PATPAINT),     \
  593.     ROPDEF("PATINVERT",  dwRops, PATINVERT),    \
  594.     ROPDEF("DSTINVERT",  dwRops, DSTINVERT),    \
  595.     ROPDEF("BLACKNESS",  dwRops, BLACKNESS),    \
  596.     ROPDEF("WHITENESS",  dwRops, WHITENESS),
  597.  
  598. CAPDEF ROPCapsDefs[] =
  599. {
  600.     GEN_ROPS(dwRops)
  601.     {"", 0, 0}
  602. };
  603. CAPDEF VSBROPCapsDefs[] =
  604. {
  605.     GEN_ROPS(dwVSBRops)
  606.     {"", 0, 0}
  607. };
  608. CAPDEF SVBROPCapsDefs[] =
  609. {
  610.     GEN_ROPS(dwSVBRops)
  611.     {"", 0, 0}
  612. };
  613. CAPDEF SSBROPCapsDefs[] =
  614. {
  615.     GEN_ROPS(dwSSBRops)
  616.     {"", 0, 0}
  617. };
  618. CAPDEF NLVBROPCapsDefs[] =
  619. {
  620.     GEN_ROPS(dwNLVBRops)
  621.     {"", 0, 0}
  622. };
  623.  
  624. /****************************************************************************
  625.  ***************************************************************************/
  626. CAPDEFS DDCapDefs[] =
  627. {
  628.     {"",                    NULL,               (LPARAM)0,                  NULL},
  629.     {"Memory",              VidMem,             (LPARAM)0,                  VidMemPrint},
  630.  
  631.     {"+Caps",               NULL,               (LPARAM)0,                  NULL},
  632.     {"General",             DDAddCaps,          (LPARAM)GenCaps,           DDPrintCaps},
  633.     {"Palette Caps",        DDAddCaps,          (LPARAM)PalCapsDefs,        DDPrintCaps},
  634.     {"Surface Caps",        DDAddCaps,          (LPARAM)SurfCapsDefs,       DDPrintCaps},
  635.     {"Stereo Vision Caps",  DDAddCaps,          (LPARAM)SVisionCapsDefs,    DDPrintCaps},
  636.  
  637.     {"+Video - Video",      NULL,               (LPARAM)0,                  NULL},
  638.     {"General",             DDAddCaps,          (LPARAM)CapsDefs,           DDPrintCaps},
  639.     {"Color Key",           DDAddCaps,          (LPARAM)CKeyCapsDefs,       DDPrintCaps},
  640.     {"FX",                  DDAddCaps,          (LPARAM)FXCapsDefs,         DDPrintCaps},
  641.     {"ROPS",                DDAddCaps,          (LPARAM)ROPCapsDefs,        DDPrintCaps},
  642.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  643.  
  644.     {"+System - Video",     NULL,               (LPARAM)0,                  NULL},
  645.     {"General",             DDAddCaps,          (LPARAM)SVBCapsDefs,        DDPrintCaps},
  646.     {"Color Key",           DDAddCaps,          (LPARAM)SVBCKeyCapsDefs,    DDPrintCaps},
  647.     {"FX",                  DDAddCaps,          (LPARAM)SVBFXCapsDefs,      DDPrintCaps},
  648.     {"ROPS",                DDAddCaps,          (LPARAM)SVBROPCapsDefs,     DDPrintCaps},
  649.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  650.  
  651.     {"+Video - System",     NULL,               (LPARAM)0,                  NULL},
  652.     {"General",             DDAddCaps,          (LPARAM)VSBCapsDefs,        DDPrintCaps},
  653.     {"Color Key",           DDAddCaps,          (LPARAM)SSBCKeyCapsDefs,    DDPrintCaps},
  654.     {"FX",                  DDAddCaps,          (LPARAM)SSBFXCapsDefs,      DDPrintCaps},
  655.     {"ROPS",                DDAddCaps,          (LPARAM)VSBROPCapsDefs,     DDPrintCaps},
  656.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  657.  
  658.     {"+System - System",    NULL,               (LPARAM)0,                  NULL},
  659.     {"General",             DDAddCaps,          (LPARAM)SSBCapsDefs,        DDPrintCaps},
  660.     {"Color Key",           DDAddCaps,          (LPARAM)SSBCKeyCapsDefs,    DDPrintCaps},
  661.     {"FX",                  DDAddCaps,          (LPARAM)SSBFXCapsDefs,      DDPrintCaps},
  662.     {"ROPS",                DDAddCaps,          (LPARAM)SSBROPCapsDefs,     DDPrintCaps},
  663.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  664.  
  665.     {"+NonLocal - Video",   NULL,               (LPARAM)0,                  NULL},
  666.     {"General",             DDAddCaps,          (LPARAM)NLVBCapsDefs,       DDPrintCaps},
  667.     {"Color Key",           DDAddCaps,          (LPARAM)NLVBCKeyCapsDefs,   DDPrintCaps},
  668.     {"FX",                  DDAddCaps,          (LPARAM)NLVBFXCapsDefs,     DDPrintCaps},
  669.     {"ROPS",                DDAddCaps,          (LPARAM)NLVBROPCapsDefs,    DDPrintCaps},
  670.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  671.  
  672.     {"-",                   NULL,               (LPARAM)0,                  NULL},
  673.  
  674.     {"Video Modes",         DDAddVideoModes,    (LPARAM)0,                  DDPrintVideoModes},
  675.     {"FourCC Formats",      DDFourCCFormat,     (LPARAM)0,                  DDPrintFourCCFormat},
  676.     {"Other",               DDAddCaps,          (LPARAM)OtherInfoDefs,      DDPrintCaps},
  677.  
  678.     { NULL, 0, 0, NULL}
  679. };
  680.  
  681. /****************************************************************************
  682.  ***************************************************************************/
  683. CAPDEF ValidFlags[] =
  684. {
  685.     D3CAPDEF("COLORMODEL",            dwFlags, D3DDD_COLORMODEL),           
  686.     D3CAPDEF("DEVCAPS",               dwFlags, D3DDD_DEVCAPS),              
  687.     D3CAPDEF("TRANSFORMCAPS",         dwFlags, D3DDD_TRANSFORMCAPS),        
  688.     D3CAPDEF("LIGHTINGCAPS",          dwFlags, D3DDD_LIGHTINGCAPS),         
  689.     D3CAPDEF("BCLIPPING",             dwFlags, D3DDD_BCLIPPING),            
  690.     D3CAPDEF("LINECAPS",              dwFlags, D3DDD_LINECAPS),             
  691.     D3CAPDEF("TRICAPS",               dwFlags, D3DDD_TRICAPS),              
  692.     D3CAPDEF("DEVICERENDERBITDEPTH",  dwFlags, D3DDD_DEVICERENDERBITDEPTH), 
  693.     D3CAPDEF("DEVICEZBUFFERBITDEPTH", dwFlags, D3DDD_DEVICEZBUFFERBITDEPTH),
  694.     D3CAPDEF("MAXBUFFERSIZE",         dwFlags, D3DDD_MAXBUFFERSIZE),        
  695.     D3CAPDEF("MAXVERTEXCOUNT",        dwFlags, D3DDD_MAXVERTEXCOUNT),       
  696.     {"",0,0}
  697. };
  698.  
  699. /****************************************************************************
  700.  ***************************************************************************/
  701. CAPDEF ColorModel[] =
  702. {
  703.     D3CAPDEF("D3DCOLOR_MONO",           dcmColorModel, D3DCOLOR_MONO),
  704.     D3CAPDEF("D3DCOLOR_RGB",            dcmColorModel, D3DCOLOR_RGB),
  705.     {"",0,0}
  706. };
  707.  
  708. /****************************************************************************
  709.  ***************************************************************************/
  710. CAPDEF DevCaps[] =
  711. {
  712.     D3CAPDEF("SORTINCREASINGZ",             dwDevCaps, D3DDEVCAPS_SORTINCREASINGZ),
  713.     D3CAPDEF("SORTDECREASINGZ",             dwDevCaps, D3DDEVCAPS_SORTDECREASINGZ),
  714.     D3CAPDEF("SORTEXACT",                   dwDevCaps, D3DDEVCAPS_SORTEXACT),
  715.     D3CAPDEF("EXECUTESYSTEMMEMORY",         dwDevCaps, D3DDEVCAPS_EXECUTESYSTEMMEMORY),
  716.     D3CAPDEF("EXECUTEVIDEOMEMORY",          dwDevCaps, D3DDEVCAPS_EXECUTEVIDEOMEMORY),
  717.     D3CAPDEF("TLVERTEXSYSTEMEMORY",         dwDevCaps, D3DDEVCAPS_TLVERTEXSYSTEMMEMORY),
  718.     D3CAPDEF("TLVERTEXVIDEOMEMORY",         dwDevCaps, D3DDEVCAPS_TLVERTEXVIDEOMEMORY),
  719.     D3CAPDEF("TEXTURESYSTEMMEMORY",         dwDevCaps, D3DDEVCAPS_TEXTURESYSTEMMEMORY),
  720.     D3CAPDEF("TEXTUREVIDEOMEMORY",          dwDevCaps, D3DDEVCAPS_TEXTUREVIDEOMEMORY),
  721.     D3CAPDEF("FLOATTLVERTEX"              , dwDevCaps, D3DDEVCAPS_FLOATTLVERTEX),
  722.     D3CAPDEF("DRAWPRIMTLVERTEX"           , dwDevCaps, D3DDEVCAPS_DRAWPRIMTLVERTEX),
  723.     D3CAPDEF("CANRENDERAFTERFLIP"         , dwDevCaps, D3DDEVCAPS_CANRENDERAFTERFLIP),
  724.     D3CAPDEF("TEXTURENONLOCALVIDMEM" , dwDevCaps, D3DDEVCAPS_TEXTURENONLOCALVIDMEM),
  725.  
  726.     {"",0,0}
  727. };
  728.  
  729. /****************************************************************************
  730.  ***************************************************************************/
  731. CAPDEF TransformCaps[] =
  732. {
  733.     D3CAPDEF("CLIP",  dtcTransformCaps.dwCaps, D3DTRANSFORMCAPS_CLIP),  
  734.     {"",0,0}
  735. };
  736.  
  737. /****************************************************************************
  738.  ***************************************************************************/
  739. CAPDEF LightingCaps[] =
  740. {
  741.     D3CAPDEF("D3DLIGHTINGMODEL_RGB",       dlcLightingCaps.dwLightingModel, D3DLIGHTINGMODEL_RGB),      
  742.     D3CAPDEF("D3DLIGHTINGMODEL_MONO",      dlcLightingCaps.dwLightingModel, D3DLIGHTINGMODEL_MONO),     
  743.  
  744.     D3CAPDEF("D3DLIGHTCAPS_POINT",         dlcLightingCaps.dwCaps,          D3DLIGHTCAPS_POINT),        
  745.     D3CAPDEF("D3DLIGHTCAPS_SPOT",          dlcLightingCaps.dwCaps,          D3DLIGHTCAPS_SPOT),         
  746.     D3CAPDEF("D3DLIGHTCAPS_DIRECTIONAL",   dlcLightingCaps.dwCaps,          D3DLIGHTCAPS_DIRECTIONAL),  
  747.     D3CAPDEF("D3DLIGHTCAPS_PARALLELPOINT", dlcLightingCaps.dwCaps,          D3DLIGHTCAPS_PARALLELPOINT),
  748.     D3VALDEF("dwNumLights",                dlcLightingCaps.dwNumLights),   
  749.     {"",0,0}
  750. };
  751.  
  752. /****************************************************************************
  753.  ***************************************************************************/
  754. CAPDEF BClipping[] =
  755. {
  756.     D3CAPDEF("bClipping", bClipping, TRUE),
  757.     {"",0,0}
  758. };
  759.  
  760. /****************************************************************************
  761.  ***************************************************************************/
  762. CAPDEF TriMisc[] =
  763. {
  764.     D3CAPDEF("MASKPLANES",            dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_MASKPLANES),
  765.     D3CAPDEF("MASKZ",                 dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_MASKZ),
  766.     D3CAPDEF("LINEPATTERNREP",        dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_LINEPATTERNREP),
  767.     D3CAPDEF("CONFORMANT",            dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CONFORMANT),
  768.     D3CAPDEF("CULLNONE",              dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLNONE),
  769.     D3CAPDEF("CULLCW",                dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLCW),
  770.     D3CAPDEF("CULLCCW",               dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLCCW),
  771.  
  772.     D3CAPDEF("DITHER",              dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_DITHER),
  773.     D3CAPDEF("ROP2",                dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_ROP2),
  774.     D3CAPDEF("XOR",                 dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_XOR),
  775.     D3CAPDEF("PAT",                 dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_PAT),
  776.     D3CAPDEF("ZTEST",               dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_ZTEST),
  777.     D3CAPDEF("SUBPIXEL",            dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_SUBPIXEL),
  778.     D3CAPDEF("SUBPIXELX",           dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_SUBPIXELX),
  779.     D3CAPDEF("FOGVERTEX",           dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_FOGVERTEX),
  780.     D3CAPDEF("FOGTABLE",            dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_FOGTABLE),
  781.  
  782.     {"",0,0}
  783. };
  784.  
  785. /****************************************************************************
  786.  ***************************************************************************/
  787. CAPDEF TriFog[] =
  788. {
  789.     D3CAPDEF("FOGVERTEX",       dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_FOGVERTEX),
  790.     D3CAPDEF("FOGTABLE",        dpcTriCaps.dwRasterCaps,         D3DPRASTERCAPS_FOGTABLE),
  791.  
  792.     D3CAPDEF("FOG FLAT",        dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGFLAT             ),
  793.     D3CAPDEF("FOG GOURAUD",     dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGGOURAUD          ),
  794.     D3CAPDEF("FOG PHONG",       dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGPHONG            ),
  795.  
  796.     {"",0,0}
  797. };
  798.  
  799.  
  800. /****************************************************************************
  801.  ***************************************************************************/
  802. CAPDEF TriCull[] =
  803. {
  804.     D3CAPDEF("CULL NONE",           dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLNONE),
  805.     D3CAPDEF("CULL CW",             dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLCW),
  806.     D3CAPDEF("CULL CCW",            dpcTriCaps.dwMiscCaps,           D3DPMISCCAPS_CULLCCW),
  807.  
  808.     {"",0,0}
  809. };
  810.  
  811. /****************************************************************************
  812.  ***************************************************************************/
  813. CAPDEF TriTextureBlend[] =
  814. {
  815.     D3CAPDEF("DECAL",           dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_DECAL              ),
  816.     D3CAPDEF("MODULATE",        dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_MODULATE           ),
  817.     D3CAPDEF("DECALALPHA",      dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_DECALALPHA         ),
  818.     D3CAPDEF("MODULATEALPHA",   dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_MODULATEALPHA      ),
  819.     D3CAPDEF("DECALMASK",       dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_DECALMASK          ),
  820.     D3CAPDEF("MODULATEMASK",    dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_MODULATEMASK       ),
  821.     D3CAPDEF("COPY",            dpcTriCaps.dwTextureBlendCaps,   D3DPTBLENDCAPS_COPY               ),
  822.  
  823.     {"",0,0}
  824. };
  825.  
  826. /****************************************************************************
  827.  ***************************************************************************/
  828. CAPDEF TriTextureFilter[] =
  829. {
  830.     D3CAPDEF("NEAREST",         dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_NEAREST           ),
  831.     D3CAPDEF("LINEAR",          dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_LINEAR            ),
  832.     D3CAPDEF("MIPNEAREST",      dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_MIPNEAREST        ),
  833.     D3CAPDEF("MIPLINEAR",       dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_MIPLINEAR         ),
  834.     D3CAPDEF("LINEARMIPNEAREST",dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_LINEARMIPNEAREST  ),
  835.     D3CAPDEF("LINEARMIPLINEAR", dpcTriCaps.dwTextureFilterCaps,  D3DPTFILTERCAPS_LINEARMIPLINEAR   ),
  836.  
  837.     {"",0,0}
  838. };
  839.  
  840. /****************************************************************************
  841.  ***************************************************************************/
  842. CAPDEF TriTextureCaps[] =
  843. {
  844.     D3CAPDEF("PERSPECTIVE",     dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_PERSPECTIVE       ),
  845.     D3CAPDEF("POW2",            dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_POW2              ),
  846.     D3CAPDEF("ALPHA",           dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_ALPHA             ),
  847.     D3CAPDEF("TRANSPARENCY",    dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_TRANSPARENCY      ),
  848.     D3CAPDEF("BORDER",          dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_BORDER            ),
  849.     D3CAPDEF("SQUAREONLY",      dpcTriCaps.dwTextureCaps,        D3DPTEXTURECAPS_SQUAREONLY        ),
  850.     
  851.     D3CAPDEF("WRAP",            dpcTriCaps.dwTextureAddressCaps, D3DPTADDRESSCAPS_WRAP             ),
  852.     D3CAPDEF("MIRROR",          dpcTriCaps.dwTextureAddressCaps, D3DPTADDRESSCAPS_MIRROR           ),
  853.     D3CAPDEF("CLAMP",           dpcTriCaps.dwTextureAddressCaps, D3DPTADDRESSCAPS_CLAMP            ),
  854.     D3CAPDEF("BORDER",          dpcTriCaps.dwTextureAddressCaps, D3DPTADDRESSCAPS_BORDER           ),
  855.     D3CAPDEF("INDEPENDENTUV",   dpcTriCaps.dwTextureAddressCaps, D3DPTADDRESSCAPS_INDEPENDENTUV    ),
  856.  
  857.     {"",0,0}
  858. };
  859.  
  860. /****************************************************************************
  861.  ***************************************************************************/
  862. CAPDEF TriZCmpCaps[] =
  863. {
  864.     D3CAPDEF("NEVER",               dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_NEVER                 ),
  865.     D3CAPDEF("LESS",                dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_LESS                  ),
  866.     D3CAPDEF("EQUAL",               dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_EQUAL                 ),
  867.     D3CAPDEF("LESSEQUAL",           dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_LESSEQUAL             ),
  868.     D3CAPDEF("GREATER",             dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_GREATER               ),
  869.     D3CAPDEF("NOTEQUAL",            dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_NOTEQUAL              ),
  870.     D3CAPDEF("GREATEREQUAL",        dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_GREATEREQUAL          ),
  871.     D3CAPDEF("ALWAYS",              dpcTriCaps.dwZCmpCaps,           D3DPCMPCAPS_ALWAYS                ),
  872.  
  873.     {"",0,0}
  874. };
  875.  
  876.  
  877. /****************************************************************************
  878.  ***************************************************************************/
  879. CAPDEF TriACmpCaps[] =
  880. {
  881.     D3CAPDEF("NEVER",                  dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_NEVER                 ),
  882.     D3CAPDEF("LESS",                   dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_LESS                  ),
  883.     D3CAPDEF("EQUAL",                  dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_EQUAL                 ),
  884.     D3CAPDEF("LESSEQUAL",              dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_LESSEQUAL             ),
  885.     D3CAPDEF("GREATER",                dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_GREATER               ),
  886.     D3CAPDEF("NOTEQUAL",               dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_NOTEQUAL              ),
  887.     D3CAPDEF("GREATEREQUAL",           dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_GREATEREQUAL          ),
  888.     D3CAPDEF("ALWAYS",                 dpcTriCaps.dwAlphaCmpCaps,       D3DPCMPCAPS_ALWAYS                ),
  889.  
  890.     {"",0,0}
  891. };
  892.  
  893. /****************************************************************************
  894.  ***************************************************************************/
  895. CAPDEF TriSrcBlendCaps[] =
  896. {
  897.     D3CAPDEF("ZERO",                 dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_ZERO                ),
  898.     D3CAPDEF("ONE",                  dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_ONE                 ),
  899.     D3CAPDEF("SRCCOLOR",             dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_SRCCOLOR            ),
  900.     D3CAPDEF("INVSRCCOLOR",          dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_INVSRCCOLOR         ),
  901.     D3CAPDEF("SRCALPHA",             dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_SRCALPHA            ),
  902.     D3CAPDEF("INVSRCALPHA",          dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_INVSRCALPHA         ),
  903.     D3CAPDEF("DESTALPHA",            dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_DESTALPHA           ),
  904.     D3CAPDEF("INVDESTALPHA",         dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_INVDESTALPHA        ),
  905.     D3CAPDEF("DESTCOLOR",            dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_DESTCOLOR           ),
  906.     D3CAPDEF("INVDESTCOLOR",         dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_INVDESTCOLOR        ),
  907.     D3CAPDEF("SRCALPHASAT",          dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_SRCALPHASAT         ),
  908.     D3CAPDEF("BOTHSRCALPHA",         dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_BOTHSRCALPHA        ),
  909.     D3CAPDEF("BOTHINVSRCALPHA",      dpcTriCaps.dwSrcBlendCaps,       D3DPBLENDCAPS_BOTHINVSRCALPHA     ),
  910.  
  911.     {"",0,0}
  912. };
  913.     
  914. /****************************************************************************
  915.  ***************************************************************************/
  916. CAPDEF TriDestBlendCaps[] =
  917. {
  918.     D3CAPDEF("ZERO",                 dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_ZERO                ),
  919.     D3CAPDEF("ONE",                  dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_ONE                 ),
  920.     D3CAPDEF("SRCCOLOR",             dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_SRCCOLOR            ),
  921.     D3CAPDEF("INVSRCCOLOR",          dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_INVSRCCOLOR         ),
  922.     D3CAPDEF("SRCALPHA",             dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_SRCALPHA            ),
  923.     D3CAPDEF("INVSRCALPHA",          dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_INVSRCALPHA         ),
  924.     D3CAPDEF("DESTALPHA",            dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_DESTALPHA           ),
  925.     D3CAPDEF("INVDESTALPHA",         dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_INVDESTALPHA        ),
  926.     D3CAPDEF("DESTCOLOR",            dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_DESTCOLOR           ),
  927.     D3CAPDEF("INVDESTCOLOR",         dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_INVDESTCOLOR        ),
  928.     D3CAPDEF("SRCALPHASAT",          dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_SRCALPHASAT         ),
  929.     D3CAPDEF("BOTHSRCALPHA",         dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_BOTHSRCALPHA        ),
  930.     D3CAPDEF("BOTHINVSRCALPHA",      dpcTriCaps.dwDestBlendCaps,      D3DPBLENDCAPS_BOTHINVSRCALPHA     ),
  931.  
  932.     {"",0,0}
  933. };
  934.     
  935. /****************************************************************************
  936.  ***************************************************************************/
  937. CAPDEF TriShadeCaps[] =
  938. {
  939.     D3CAPDEF("COLOR FLAT MONO",        dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORFLATMONO       ),
  940.     D3CAPDEF("COLOR FLAT RGB",         dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORFLATRGB        ),
  941.     D3CAPDEF("COLOR GOURAUD MONO",     dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORGOURAUDMONO    ),
  942.     D3CAPDEF("COLOR GOURAUD RGB",      dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORGOURAUDRGB     ),
  943.     D3CAPDEF("COLOR PHONG MONO",       dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORPHONGMONO      ),
  944.     D3CAPDEF("COLOR PHONG RGB",        dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_COLORPHONGRGB       ),
  945.     
  946.     D3CAPDEF("SPECULAR FLAT MONO",     dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARFLATMONO    ),
  947.     D3CAPDEF("SPECULAR FLAT RGB",      dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARFLATRGB     ),
  948.     D3CAPDEF("SPECULAR GOURAUD MONO",  dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARGOURAUDMONO ),
  949.     D3CAPDEF("SPECULAR GOURAUD RGB",   dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARGOURAUDRGB  ),
  950.     D3CAPDEF("SPECULAR PHONG MONO",    dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARPHONGMONO   ),
  951.     D3CAPDEF("SPECULAR PHONG RGB",     dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_SPECULARPHONGRGB    ),
  952.     
  953.     D3CAPDEF("ALPHA FLAT BLEND",       dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAFLATBLEND      ),
  954.     D3CAPDEF("ALPHA FLAT STIPPLED",    dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAFLATSTIPPLED   ),
  955.     D3CAPDEF("ALPHA GOURAUD BLEND",    dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAGOURAUDBLEND   ),
  956.     D3CAPDEF("ALPHA GOURAUD STIPPLED", dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED),
  957.     D3CAPDEF("ALPHA PHONG BLEND",      dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAPHONGBLEND     ),
  958.     D3CAPDEF("ALPHA PHONG STIPPLED",   dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_ALPHAPHONGSTIPPLED  ),
  959.     
  960.     D3CAPDEF("FOG FLAT",               dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGFLAT             ),
  961.     D3CAPDEF("FOG GOURAUD",            dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGGOURAUD          ),
  962.     D3CAPDEF("FOG PHONG",              dpcTriCaps.dwShadeCaps,          D3DPSHADECAPS_FOGPHONG            ),
  963.     
  964.     {"",0,0}
  965. };
  966.  
  967.  
  968. /****************************************************************************
  969.  ***************************************************************************/
  970. CAPDEF D3dMisc[] =
  971. {
  972.     D3CAPDEF("D3DCOLOR_MONO",         dcmColorModel, D3DCOLOR_MONO),
  973.     D3CAPDEF("D3DCOLOR_RGB",          dcmColorModel, D3DCOLOR_RGB),
  974.  
  975.     D3CAPDEF("bClipping", bClipping, TRUE),
  976.     D3CAPDEF("CLIP",  dtcTransformCaps.dwCaps, D3DTRANSFORMCAPS_CLIP),  
  977.  
  978.  
  979.     D3VALDEF("MaxBufferSize",         dwMaxBufferSize),        
  980.     D3VALDEF("MaxVertexCount",        dwMaxVertexCount),       
  981.     D3HEXDEF("DeviceRenderBitDepth",  dwDeviceRenderBitDepth),
  982.     D3CAPDEF("  8",                   dwDeviceRenderBitDepth, DDBD_8),
  983.     D3CAPDEF("  16",                  dwDeviceRenderBitDepth, DDBD_16),
  984.     D3CAPDEF("  24",                  dwDeviceRenderBitDepth, DDBD_24),
  985.     D3CAPDEF("  32",                  dwDeviceRenderBitDepth, DDBD_32),
  986.     D3HEXDEF("DeviceZBufferBitDepth", dwDeviceZBufferBitDepth),
  987.     D3CAPDEF("  8",                   dwDeviceZBufferBitDepth, DDBD_8),
  988.     D3CAPDEF("  16",                  dwDeviceZBufferBitDepth, DDBD_16),
  989.     D3CAPDEF("  24",                  dwDeviceZBufferBitDepth, DDBD_24),
  990.     D3CAPDEF("  32",                  dwDeviceZBufferBitDepth, DDBD_32),
  991.     D3VALDEF("MinTextureWidth",       dwMinTextureWidth),
  992.     D3VALDEF("MinTextureHeight",      dwMinTextureHeight),
  993.     D3VALDEF("MaxTextureWidth",       dwMaxTextureWidth),
  994.     D3VALDEF("MaxTextureHeight",      dwMaxTextureHeight),
  995.     D3VALDEF("MinStippleWidth",       dwMinStippleWidth),
  996.     D3VALDEF("MaxStippleWidth",       dwMaxStippleWidth),
  997.     D3VALDEF("MinStippleHeight",      dwMinStippleHeight),
  998.     D3VALDEF("MaxStippleHeight",      dwMaxStippleHeight),
  999.  
  1000.     {"",0,0}
  1001. };
  1002.  
  1003. /****************************************************************************
  1004.  ***************************************************************************/
  1005. CAPDEFS D3CapDefs[] =
  1006. {
  1007.     {"",                D3AddCaps, (LPARAM)ValidFlags,       D3PrintCaps},
  1008.     {"DevCaps",         D3AddCaps, (LPARAM)DevCaps,          D3PrintCaps},
  1009.     {"Misc",            D3AddCaps, (LPARAM)D3dMisc,          D3PrintCaps},
  1010. //  {"ColorModel",      D3AddCaps, (LPARAM)ColorModel,       D3PrintCaps},
  1011. //  {"TransformCaps",   D3AddCaps, (LPARAM)TransformCaps,    D3PrintCaps},
  1012. //  {"BClipping",       D3AddCaps, (LPARAM)BClipping,        D3PrintCaps},
  1013.     {"LightingCaps",    D3AddCaps, (LPARAM)LightingCaps,     D3PrintCaps},
  1014.  
  1015.     {"+Triangle Caps",      NULL,      (LPARAM)0,                NULL},
  1016.     {"Z Compare",           D3AddCaps, (LPARAM)TriZCmpCaps,      D3PrintCaps},
  1017.     {"Alpha Compare",       D3AddCaps, (LPARAM)TriACmpCaps,      D3PrintCaps},
  1018.     {"Misc",                D3AddCaps, (LPARAM)TriMisc,          D3PrintCaps},
  1019.     {"Cull",                D3AddCaps, (LPARAM)TriCull,          D3PrintCaps},
  1020.     {"Fog",                 D3AddCaps, (LPARAM)TriFog,           D3PrintCaps},
  1021.     {"Texture Caps",        D3AddCaps, (LPARAM)TriTextureCaps,   D3PrintCaps},
  1022.     {"Texture Filter",      D3AddCaps, (LPARAM)TriTextureFilter, D3PrintCaps},
  1023.     {"Texture Blend",       D3AddCaps, (LPARAM)TriTextureBlend,  D3PrintCaps},
  1024.     {"Texture Source Blend",D3AddCaps, (LPARAM)TriSrcBlendCaps,  D3PrintCaps},
  1025.     {"Texture Dest Blend",  D3AddCaps, (LPARAM)TriDestBlendCaps, D3PrintCaps},
  1026.     {"-",                   NULL,      (LPARAM)0,                NULL},
  1027.  
  1028.     {"+Line Caps",          NULL,          (LPARAM)0,                NULL},
  1029.     {"Z Compare",           D3AddLineCaps, (LPARAM)TriZCmpCaps,      D3PrintCaps},
  1030.     {"Alpha Compare",       D3AddLineCaps, (LPARAM)TriACmpCaps,      D3PrintCaps},
  1031.     {"Misc",                D3AddLineCaps, (LPARAM)TriMisc,          D3PrintCaps},
  1032.     {"Cull",                D3AddLineCaps, (LPARAM)TriCull,          D3PrintCaps},
  1033.     {"Fog",                 D3AddLineCaps, (LPARAM)TriFog,           D3PrintCaps},
  1034.     {"Texture Caps",        D3AddLineCaps, (LPARAM)TriTextureCaps,   D3PrintCaps},
  1035.     {"Texture Filter",      D3AddLineCaps, (LPARAM)TriTextureFilter, D3PrintCaps},
  1036.     {"Texture Blend",       D3AddLineCaps, (LPARAM)TriTextureBlend,  D3PrintCaps},
  1037.     {"Texture Source Blend",D3AddLineCaps, (LPARAM)TriSrcBlendCaps,  D3PrintCaps},
  1038.     {"Texture Dest Blend",  D3AddLineCaps, (LPARAM)TriDestBlendCaps, D3PrintCaps},
  1039.     {"-",                   NULL,          (LPARAM)0,                NULL},
  1040.  
  1041.     {"Texture Formats",     D3AddTexF, (LPARAM)0,                0},
  1042.     {NULL, 0, 0, NULL}
  1043. };
  1044.  
  1045. /****************************************************************************
  1046.  ***************************************************************************/
  1047. CAPDEF DSInfo[] =
  1048. {
  1049.     DSVALDEF("MinSecondarySampleRate",          dwMinSecondarySampleRate),
  1050.     DSVALDEF("MaxSecondarySampleRate",          dwMaxSecondarySampleRate),
  1051.     DSVALDEF("PrimaryBuffers",                  dwPrimaryBuffers),
  1052.     DSVALDEF("MaxHwMixingAllBuffers",           dwMaxHwMixingAllBuffers),
  1053.     DSVALDEF("MaxHwMixingStaticBuffers",        dwMaxHwMixingStaticBuffers),
  1054.     DSVALDEF("MaxHwMixingStreamingBuffers",     dwMaxHwMixingStreamingBuffers),
  1055.     DSVALDEF("FreeHwMixingAllBuffers",          dwFreeHwMixingAllBuffers),
  1056.     DSVALDEF("FreeHwMixingStaticBuffers",       dwFreeHwMixingStaticBuffers),
  1057.     DSVALDEF("FreeHwMixingStreamingBuffers",    dwFreeHwMixingStreamingBuffers),
  1058.     DSVALDEF("MaxHw3DAllBuffers",               dwMaxHw3DAllBuffers),
  1059.     DSVALDEF("MaxHw3DStaticBuffers",            dwMaxHw3DStaticBuffers),
  1060.     DSVALDEF("MaxHw3DStreamingBuffers",         dwMaxHw3DStreamingBuffers),
  1061.     DSVALDEF("FreeHw3DAllBuffers",              dwFreeHw3DAllBuffers),
  1062.     DSVALDEF("FreeHw3DStaticBuffers",           dwFreeHw3DStaticBuffers),
  1063.     DSVALDEF("FreeHw3DStreamingBuffers",        dwFreeHw3DStreamingBuffers),
  1064.     DSVALDEF("TotalHwMemBytes",                 dwTotalHwMemBytes),
  1065.     DSVALDEF("FreeHwMemBytes",                  dwFreeHwMemBytes),
  1066.     DSVALDEF("MaxContigFreeHwMemBytes",         dwMaxContigFreeHwMemBytes),
  1067.     DSVALDEF("UnlockTransferRateHwBuffers",     dwUnlockTransferRateHwBuffers),
  1068.     DSVALDEF("PlayCpuOverheadSwBuffers",        dwPlayCpuOverheadSwBuffers),
  1069.     {"", 0, 0}
  1070. };
  1071.  
  1072. /****************************************************************************
  1073.  ***************************************************************************/
  1074. CAPDEF DSGeneralCaps[] =
  1075. {
  1076.     DSCAPDEF("PRIMARYMONO",       dwFlags,    DSCAPS_PRIMARYMONO),
  1077.     DSCAPDEF("PRIMARYSTEREO",     dwFlags,    DSCAPS_PRIMARYSTEREO),
  1078.     DSCAPDEF("PRIMARY8BIT",       dwFlags,    DSCAPS_PRIMARY8BIT),
  1079.     DSCAPDEF("PRIMARY16BIT",      dwFlags,    DSCAPS_PRIMARY16BIT),
  1080.     DSCAPDEF("CONTINUOUSRATE",    dwFlags,    DSCAPS_CONTINUOUSRATE),
  1081.     DSCAPDEF("EMULDRIVER",        dwFlags,    DSCAPS_EMULDRIVER),
  1082.     DSCAPDEF("SECONDARYMONO",     dwFlags,    DSCAPS_SECONDARYMONO),
  1083.     DSCAPDEF("SECONDARYSTEREO",   dwFlags,    DSCAPS_SECONDARYSTEREO),
  1084.     DSCAPDEF("SECONDARY8BIT",     dwFlags,    DSCAPS_SECONDARY8BIT),
  1085.     DSCAPDEF("SECONDARY16BIT",    dwFlags,    DSCAPS_SECONDARY16BIT),
  1086.     {"", 0, 0}
  1087. };
  1088.  
  1089. /****************************************************************************
  1090.  ***************************************************************************/
  1091. CAPDEFS DSCapDefs[] =
  1092. {
  1093.     {"",                    DSAddCaps,          (LPARAM)DSInfo,         DSPrintCaps},
  1094.     {"General",             DSAddCaps,          (LPARAM)DSInfo,         DSPrintCaps},
  1095.     {"General Caps",        DSAddCaps,          (LPARAM)DSGeneralCaps,  DSPrintCaps},
  1096.     {NULL, 0, 0, NULL}
  1097. };
  1098.  
  1099. /****************************************************************************
  1100.  ***************************************************************************/
  1101. CAPDEF DSCInfo[] =
  1102. {
  1103.     DSCVALDEF("Channels",          dwChannels),
  1104.     {"", 0, 0}
  1105. };
  1106.  
  1107. /****************************************************************************
  1108.  ***************************************************************************/
  1109. CAPDEF DSCGeneralCaps[] =
  1110. {
  1111.     DSCCAPDEF("EMULDRIVER",        dwFlags,    DSCCAPS_EMULDRIVER),
  1112.     DSCCAPDEF("WAVE_FORMAT_1M08",  dwFormats,  WAVE_FORMAT_1M08),
  1113.     DSCCAPDEF("WAVE_FORMAT_1S08",  dwFormats,  WAVE_FORMAT_1S08),
  1114.     DSCCAPDEF("WAVE_FORMAT_1M16",  dwFormats,  WAVE_FORMAT_1M16),
  1115.     DSCCAPDEF("WAVE_FORMAT_1S16",  dwFormats,  WAVE_FORMAT_1S16),
  1116.     DSCCAPDEF("WAVE_FORMAT_2M08",  dwFormats,  WAVE_FORMAT_2M08),
  1117.     DSCCAPDEF("WAVE_FORMAT_2S08",  dwFormats,  WAVE_FORMAT_2S08),
  1118.     DSCCAPDEF("WAVE_FORMAT_2M16",  dwFormats,  WAVE_FORMAT_2M16),
  1119.     DSCCAPDEF("WAVE_FORMAT_2S16",  dwFormats,  WAVE_FORMAT_2S16),
  1120.     DSCCAPDEF("WAVE_FORMAT_4M08",  dwFormats,  WAVE_FORMAT_4M08),
  1121.     DSCCAPDEF("WAVE_FORMAT_4S08",  dwFormats,  WAVE_FORMAT_4S08),
  1122.     DSCCAPDEF("WAVE_FORMAT_4M16",  dwFormats,  WAVE_FORMAT_4M16),
  1123.     DSCCAPDEF("WAVE_FORMAT_4S16",  dwFormats,  WAVE_FORMAT_4S16),
  1124.     {"", 0, 0}
  1125. };
  1126.  
  1127. /****************************************************************************
  1128.  ***************************************************************************/
  1129. CAPDEFS DSCCapDefs[] =
  1130. {
  1131.     {"",                    DSCAddCaps,          (LPARAM)DSCInfo,         DSCPrintCaps},
  1132.     {"General",             DSCAddCaps,          (LPARAM)DSCInfo,         DSCPrintCaps},
  1133.     {"General Caps",        DSCAddCaps,          (LPARAM)DSCGeneralCaps,  DSCPrintCaps},
  1134.     {NULL, 0, 0, NULL}
  1135. };
  1136.  
  1137. /****************************************************************************
  1138.  ***************************************************************************/
  1139. CAPDEF DPInfo[] =
  1140. {
  1141.     DPVALDEF("Size",                dwSize),
  1142.     DPHEXDEF("Flags",               dwFlags),
  1143.     DPVALDEF("MaxBufferSize",       dwMaxBufferSize),
  1144.     DPVALDEF("MaxQueueSize",        dwMaxQueueSize),
  1145.     DPVALDEF("MaxPlayers",          dwMaxPlayers),
  1146.     DPVALDEF("HundredBaud",         dwHundredBaud),
  1147.     DPVALDEF("Latency",             dwLatency),
  1148.     DPVALDEF("MaxLocalPlayers",     dwMaxLocalPlayers),
  1149.     DPVALDEF("HeaderLength",        dwHeaderLength),
  1150.     DPVALDEF("Timeout",             dwTimeout),
  1151.     {"", 0, 0}
  1152. };
  1153.  
  1154. /****************************************************************************
  1155.  ***************************************************************************/
  1156. CAPDEFS DPCapDefs[] =
  1157. {
  1158.     {"",                    DPAddCaps,            (LPARAM)DPInfo,              DPPrintCaps},
  1159.     {"Sessions",            DPAddSessions,      (LPARAM)0,            DPPrintSessions},
  1160.     {NULL, 0, 0}
  1161. };
  1162.  
  1163. /****************************************************************************
  1164.  ***************************************************************************/
  1165. CAPDEFS DPLocalAppsDef[] =
  1166. {
  1167.     {"LocalApplications",    DPAddLocalApps,    (LPARAM)0,    DPPrintLocalApps},
  1168.     {NULL, 0, 0}
  1169. };
  1170.  
  1171. //================================================================
  1172. //  WinMain - entry point
  1173. //================================================================
  1174. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  1175. {
  1176.     MSG msg;
  1177.  
  1178.     CoInitialize( NULL );
  1179.     g_hInstance = hInstance; // Store instance handle in our global variable
  1180.     g_idTimer = 0;                  //Used by DPlay
  1181.     g_lpLocalApp = NULL;    //Used by DPLay
  1182.  
  1183.     // Try to load the dsound.dll
  1184.     g_hDSoundLib = LoadLibrary("DSOUND.DLL");
  1185.     if (g_hDSoundLib == NULL)
  1186.     {       // couldn't load the library so put up a message and quit.
  1187.         MessageBox(g_hwndMain, "Could not load DSOUND.DLL", g_szAppName, MB_OK);
  1188.         CoUninitialize();
  1189.         return 0;       // terminate after showing the message.
  1190.     }
  1191.  
  1192.     //Create the initial local app list.
  1193.     DPAddLocalApps(0L, 0);
  1194.  
  1195.     if (InitInstance(hInstance, lpCmdLine, nCmdShow, DXView_WIDTH, DXView_HEIGHT))
  1196.     {
  1197.         while(GetMessage(&msg, NULL, 0, 0))
  1198.         {
  1199.             TranslateMessage(&msg);
  1200.             DispatchMessage(&msg);
  1201.         }
  1202.     }
  1203.  
  1204.     if (g_lpLocalApp)
  1205.         FreeLocalAppList();
  1206.  
  1207.     // Unload dsound.dll
  1208.     FreeLibrary(g_hDSoundLib);
  1209.  
  1210.     CoUninitialize();
  1211.     return(msg.wParam);
  1212. }
  1213.  
  1214. //================================================================
  1215. //  InitInstance - create main window
  1216. //================================================================
  1217. BOOL InitInstance(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow, int iWidth, int iHeight)
  1218. {
  1219.     WNDCLASS  wc;
  1220.  
  1221.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  1222.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  1223.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  1224.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  1225.     wc.hInstance     = hInstance;               // Owner of this class
  1226.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIRECTX)); // Icon name from .RC
  1227.     wc.hCursor       = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_SPLIT));// Cursor
  1228.     wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); // Default color
  1229.     wc.lpszMenuName  = "Menu";                   // Menu name from .RC
  1230.     wc.lpszClassName = g_szClassName;            // Name to register as
  1231.  
  1232.     if(!RegisterClass(&wc))
  1233.     {
  1234.         return FALSE;
  1235.     }
  1236.  
  1237.     // Create a main window for this application instance.
  1238.     g_hwndMain = CreateWindowEx(
  1239.         0,
  1240.         g_szClassName,   // See RegisterClass() call.
  1241.         g_szTitle,       // Text for window title bar.
  1242.         WS_OVERLAPPEDWINDOW,// Window style.
  1243.         CW_USEDEFAULT, CW_USEDEFAULT, iWidth, iHeight, // Use default positioning
  1244.         NULL,            // Overlapped windows have no parent.
  1245.         NULL,            // Use the window class menu.
  1246.         hInstance,       // This instance owns this window.
  1247.         NULL);
  1248.  
  1249.     // If window could not be created, return "failure"
  1250.     if (! g_hwndMain)
  1251.     {
  1252.         return(FALSE);
  1253.     }
  1254.  
  1255.     // Make the window visible; update its client area; and return "success"
  1256.     ShowWindow (g_hwndMain, nCmdShow); // Show the window
  1257.  
  1258.     return(TRUE);              // We succeeded...
  1259. }
  1260.  
  1261. //================================================================
  1262. //  WndProc - main window proc
  1263. //================================================================
  1264. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  1265. {
  1266.     switch(message)
  1267.     {
  1268.         case WM_CREATE:
  1269.             return DXView_OnCreate(hwnd);
  1270.  
  1271.         case WM_SIZE:
  1272.             DXView_OnSize(hwnd);
  1273.             break;
  1274.  
  1275.         case WM_LBUTTONDOWN:
  1276.             g_bSplitMove = TRUE;
  1277.             SetCapture(hwnd);
  1278.             break;
  1279.  
  1280.         case WM_LBUTTONUP:
  1281.             g_bSplitMove = FALSE;
  1282.             ReleaseCapture();
  1283.             break;
  1284.  
  1285.         case WM_MOUSEMOVE:
  1286.             if(g_bSplitMove)
  1287.             {
  1288.                 RECT    rect;
  1289.                 // change the value from unsigned to signed
  1290.                 int     x = (int)(short)LOWORD(lParam);
  1291.  
  1292.                 GetClientRect(hwnd, &rect);
  1293.                 if (rect.left > x)
  1294.                 {
  1295.                     x = rect.left;
  1296.                 }
  1297.                 else if (rect.right < x)
  1298.                 {
  1299.                     x = rect.right;
  1300.                 }
  1301.                 g_xPaneSplit = (x - g_xHalfSplitWidth);
  1302.                 DXView_OnSize(hwnd);
  1303.             }
  1304.             break;
  1305.  
  1306.         case WM_NOTIFY:
  1307.             if (((NMHDR*)lParam)->hwndFrom == g_hwndTV)
  1308.             {
  1309.                 if (((NMHDR*)lParam)->code == TVN_SELCHANGED)
  1310.                     DXView_OnTreeSelect(g_hwndTV, (NM_TREEVIEW*)lParam);
  1311.             }
  1312.  
  1313.             if (((NMHDR*)lParam)->hwndFrom == g_hwndLV)
  1314.             {
  1315.                 if (((NMHDR*)lParam)->code == NM_RDBLCLK)
  1316.                     DXView_OnListViewDblClick(g_hwndLV, (NM_LISTVIEW*)lParam);
  1317.             }
  1318.  
  1319.             break;
  1320.  
  1321.        case WM_TIMER:
  1322.             // refresh the session list
  1323.             EnumSessions( lpDP3A );
  1324.             break;
  1325.  
  1326.        case WM_COMMAND:  // message: command from application menu
  1327.             DXView_OnCommand(hwnd, wParam);
  1328.             break;
  1329.  
  1330.         case WM_CLOSE:
  1331.             DestroyWindow(hwnd);
  1332.             return 0;
  1333.  
  1334.         case WM_DESTROY:  // message: window being destroyed
  1335.             DXView_Cleanup();  // Free per item struct for all items
  1336.             PostQuitMessage(0);
  1337.             break;
  1338.     }
  1339.  
  1340.     return(DefWindowProc(hwnd, message, wParam, lParam));
  1341. }
  1342.  
  1343. //================================================================
  1344. //================================================================
  1345. BOOL DXView_OnCreate(HWND hwnd)
  1346. {
  1347.     HDC hDC;
  1348.     int PixelsPerInch;
  1349.     TEXTMETRIC tm;
  1350.     static TCHAR szBuf[MAX_PATH];
  1351.  
  1352.     hDC = GetDC(hwnd);
  1353.     PixelsPerInch = GetDeviceCaps(hDC, LOGPIXELSX);
  1354.     g_hFont = GetStockObject(ANSI_FIXED_FONT);
  1355.     SelectObject(hDC, g_hFont);
  1356.     GetTextMetrics(hDC, &tm);
  1357.     g_tmAveCharWidth = tm.tmAveCharWidth;
  1358.     ReleaseDC(hwnd, hDC);
  1359.  
  1360.     // Initialize global data
  1361.     g_dwViewState = IDM_VIEWAVAIL;
  1362.     g_xPaneSplit = PixelsPerInch * 12 / 4;
  1363.     g_xHalfSplitWidth = GetSystemMetrics(SM_CXSIZEFRAME) / 2;
  1364.  
  1365.     // Make sure that the common control library read to rock
  1366.     InitCommonControls();
  1367.  
  1368.     CheckMenuItem(GetMenu(hwnd), g_dwViewState, MF_BYCOMMAND | MF_CHECKED);
  1369.  
  1370.     // Create the list view window.
  1371.     g_hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "",
  1372.         WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT,
  1373.         0, 0, 0, 0, hwnd, (HMENU)IDC_LV, g_hInstance, NULL);
  1374.  
  1375.     // create the tree view window.
  1376.     g_hwndTV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
  1377.         WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES |
  1378.         TVS_HASBUTTONS | TVS_LINESATROOT,
  1379.         0, 0, 0, 0, hwnd, (HMENU)IDC_TV, g_hInstance, NULL);
  1380.  
  1381.     // create our image list.
  1382.     DXView_InitImageList();
  1383.  
  1384.     // Initialize the tree view
  1385.     DXView_FillTree(g_hwndTV);
  1386.  
  1387.     return(TRUE);
  1388. }
  1389.  
  1390. //================================================================
  1391. //================================================================
  1392. IDirectDraw * DDCreate(GUID *pid)
  1393. {
  1394.     if (lpDD && pid == ddid)
  1395.         return lpDD;
  1396.  
  1397.     if (lp3D)
  1398.     {
  1399.         IDirect3D2_Release(lp3D);
  1400.         lp3D = NULL;
  1401.     }
  1402.  
  1403.     if (lpDD)
  1404.     {
  1405.         IDirectDraw_Release(lpDD);
  1406.         lpDD = NULL;
  1407.     }
  1408.  
  1409.     // There is no need to create DirectDraw emulation-only just to get
  1410.     // the HEL caps.  In fact, this will fail if there is another DirectDraw
  1411.     // app running and using the hardware.
  1412.     if( pid == (GUID *)DDCREATE_EMULATIONONLY )
  1413.     {
  1414.         pid = NULL;
  1415.     }
  1416.     if (DirectDrawCreate(pid, &lpDD, NULL) == DD_OK)
  1417.     {
  1418.         IDirectDraw_QueryInterface(lpDD,&IID_IDirect3D2,&lp3D);
  1419.         ddid = pid;
  1420.         return lpDD;
  1421.     }
  1422.     if(!g_PrintToFile)
  1423.         MessageBox(g_hwndMain, "DirectDrawCreate failed.", g_szAppName, MB_OK);
  1424.     return NULL;
  1425. }
  1426.  
  1427. //================================================================
  1428. //================================================================
  1429. IDirectSound * DSCreate(GUID *pid)
  1430. {
  1431.     PFN_DSCREATE pfn_DSCreate;
  1432.  
  1433.     if (lpDS && pid == dsid)
  1434.         return lpDS;
  1435.  
  1436.     if (lpDS)
  1437.     {
  1438.         IDirectSound_Release(lpDS);
  1439.         lpDS = NULL;
  1440.     }
  1441.  
  1442.     // Call DirectSoundCreate.
  1443.     pfn_DSCreate = (PFN_DSCREATE)GetProcAddress(g_hDSoundLib, "DirectSoundCreate");
  1444.     if (pfn_DSCreate == NULL)
  1445.     {
  1446.         MessageBox(g_hwndMain, "DSOUND.DLL does not implement DirectSoundCreate()", g_szAppName, MB_OK);        
  1447.         return NULL;
  1448.     }
  1449.  
  1450.     if ((*pfn_DSCreate)(pid, &lpDS, NULL) == DD_OK)
  1451.     {
  1452.         dsid = pid;
  1453.         return lpDS;
  1454.     }
  1455.  
  1456.     if(!g_PrintToFile)
  1457.         MessageBox(g_hwndMain, "DirectSoundCreate failed.", g_szAppName, MB_OK);
  1458.     return NULL;
  1459. }
  1460.  
  1461. //================================================================
  1462. //================================================================
  1463. IDirectSoundCapture * DSCCreate(GUID *pid)
  1464. {
  1465.     PFN_DSCCREATE pfn_DSCCreate;
  1466.  
  1467.     if (lpDSC && pid == dsid)
  1468.         return lpDSC;
  1469.  
  1470.     if (lpDSC)
  1471.     {
  1472.         IDirectSoundCapture_Release(lpDSC);
  1473.         lpDSC = NULL;
  1474.     }
  1475.  
  1476.     pfn_DSCCreate = (PFN_DSCCREATE)GetProcAddress(g_hDSoundLib, "DirectSoundCaptureCreate");
  1477.     if (pfn_DSCCreate == NULL)
  1478.     {
  1479.         MessageBox(g_hwndMain, "DSOUND.DLL does not implement DirectSoundCaptureCreate()", g_szAppName, MB_OK);        
  1480.         return NULL;
  1481.     }
  1482.     
  1483.     if ((*pfn_DSCCreate)(pid, &lpDSC, NULL) == DD_OK)
  1484.     {
  1485.         dscid = pid;
  1486.         return lpDSC;
  1487.     }
  1488.  
  1489.     if(!g_PrintToFile)
  1490.         MessageBox(g_hwndMain, "DirectSoundCaptureCreate failed.", g_szAppName, MB_OK);
  1491.     return NULL;
  1492. }
  1493.  
  1494. //================================================================
  1495. //================================================================
  1496. IDirectPlay3 * DPCreate(GUID *pid)
  1497. {
  1498.     LPDIRECTPLAY    lpDP = NULL;
  1499.     HRESULT    hr;
  1500.  
  1501.     if (lpDP3A && pid == dpid)
  1502.         return lpDP3A;
  1503.  
  1504.     if (lpDP3A)
  1505.     {
  1506.         lpDP3A->lpVtbl->Release(lpDP3A);
  1507.         lpDP3A = NULL;
  1508.     }
  1509.  
  1510.     if (DirectPlayCreate(pid, &lpDP, NULL) == DD_OK)
  1511.     {
  1512.         hr = lpDP->lpVtbl->QueryInterface( lpDP, &IID_IDirectPlay3A, (LPVOID *) &lpDP3A );
  1513.         lpDP->lpVtbl->Release(lpDP);
  1514.         dpid = pid;
  1515.         return lpDP3A;
  1516.     }
  1517.     if(!g_PrintToFile)
  1518.         MessageBox(g_hwndMain, "DirectPlayCreate failed.", g_szAppName, MB_OK);
  1519.     return NULL;
  1520. }
  1521.  
  1522. //================================================================
  1523. //================================================================
  1524. void AddCapsToTV(HTREEITEM hRoot, CAPDEFS *pcds, LPARAM lParam1)
  1525. {
  1526.     HTREEITEM hTree;
  1527.     HTREEITEM hParent[20];
  1528.     char *name;
  1529.     int level=0;
  1530.     BOOL fRoot = TRUE; // the first one is always a root
  1531.  
  1532.     hParent[0] = hRoot;
  1533.  
  1534.     while (name = pcds->szName)
  1535.     {
  1536.         if (*name == '-')
  1537.         {
  1538.             level--;
  1539.             name++;
  1540.         }
  1541.  
  1542.         if (*name == '+')
  1543.         {
  1544.             fRoot = TRUE;
  1545.             name++;
  1546.         }
  1547.  
  1548.         if (*name)
  1549.         {
  1550.             hTree = TVAddNode(hParent[level], name, fRoot, IDI_CAPS,
  1551.                               pcds->Callback, lParam1,
  1552.                               pcds->lParam2, pcds->printCallback);
  1553.  
  1554.             if (fRoot)
  1555.             {
  1556.                 level++;
  1557.                 hParent[level] = hTree;
  1558.                 fRoot = FALSE;
  1559.             }
  1560.         }
  1561.  
  1562.         pcds++;  // Get next Cap bit definition
  1563.     }
  1564. }
  1565.  
  1566. //================================================================
  1567. //================================================================
  1568. char c_szYes[] = "Yes";
  1569. char c_szNo[] = "No";
  1570. char c_szCurrentMode[] = "Current Mode";
  1571.  
  1572. //================================================================
  1573. // AddMoreCapsToLV is like AddCapsToLV, except it doesn't add the
  1574. // column headers like AddCapsToLV does.
  1575. //================================================================
  1576. void AddMoreCapsToLV(CAPDEF *pcd, LPVOID pv)
  1577. {
  1578.     DWORD dwValue;
  1579.  
  1580.     while(pcd->szName && *pcd->szName)
  1581.     {
  1582.         dwValue = *(DWORD *)(((BYTE *)pv) + pcd->dwOffset);
  1583.  
  1584.         if (pcd->dwFlag == 0)
  1585.         {
  1586.             LVAddText(g_hwndLV, 0, "%s", pcd->szName);
  1587.             LVAddText(g_hwndLV, 1, "%d", dwValue);
  1588.         }
  1589.         else if (pcd->dwFlag == 0xFFFFFFFF)     // hex
  1590.         {
  1591.             LVAddText(g_hwndLV, 0, "%s", pcd->szName);
  1592.             LVAddText(g_hwndLV, 1, "0x%08X", dwValue);
  1593.         }
  1594.         else
  1595.         {
  1596.             if (pcd->dwFlag & dwValue)
  1597.             {
  1598.                 LVAddText(g_hwndLV, 0, pcd->szName);
  1599.                 LVAddText(g_hwndLV, 1, c_szYes);
  1600.             }
  1601.             else if (g_dwViewState == IDM_VIEWALL)
  1602.             {
  1603.                 LVAddText(g_hwndLV, 0, pcd->szName);
  1604.                 LVAddText(g_hwndLV, 1, c_szNo);
  1605.             }
  1606.         }
  1607.  
  1608.         pcd++;  // Get next Cap bit definition
  1609.     }
  1610. }
  1611.  
  1612.  
  1613. //================================================================
  1614. // AddColsToLV adds the column headers but no data.
  1615. //================================================================
  1616. void AddColsToLV(void)
  1617. {
  1618.     LVAddColumn(g_hwndLV, 0, "Name", 24);
  1619.     LVAddColumn(g_hwndLV, 1, "Value", 10);
  1620. }
  1621.  
  1622. //================================================================
  1623. //================================================================
  1624. void AddCapsToLV(CAPDEF *pcd, LPVOID pv)
  1625. {
  1626.     AddColsToLV();
  1627.     AddMoreCapsToLV(pcd, pv);
  1628. }
  1629.  
  1630. //================================================================
  1631. //================================================================
  1632. BOOL PrintCapsToDC(CAPDEF *pcd, LPVOID pv, PRINTCBINFO * lpInfo)
  1633. {
  1634.     DWORD dwValue;
  1635.     DWORD cchLen;
  1636.     int   xName, xVal, yLine;
  1637.  
  1638.     // Check Parameters
  1639.     if ((! pcd) || (!lpInfo))
  1640.         return FALSE;
  1641.  
  1642.     // Calculate Name and Value column x offsets
  1643.     xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  1644.     xVal    = xName + (32 * lpInfo->dwCharWidth);
  1645.  
  1646.     while (pcd->szName && *pcd->szName)
  1647.     {
  1648.         dwValue = *(DWORD *)(((BYTE *)pv) + pcd->dwOffset);
  1649.         yLine = lpInfo->dwCurrLine * lpInfo->dwLineHeight;
  1650.  
  1651.         if (pcd->dwFlag)
  1652.         {
  1653.             if (pcd->dwFlag & dwValue)
  1654.             {
  1655.                 // Print Name
  1656.                 cchLen = _tcslen (pcd->szName);
  1657.                 if (! PrintLine (xName, yLine, pcd->szName, cchLen, lpInfo))
  1658.                     return FALSE;
  1659.  
  1660.                 // Print Yes in value column
  1661.                 cchLen = _tcslen (c_szYes);
  1662.                 if (! PrintLine (xVal, yLine, c_szYes, cchLen, lpInfo))
  1663.                     return FALSE;
  1664.         
  1665.                 // Advance to next line on page
  1666.                 if (! PrintNextLine (lpInfo))
  1667.                     return FALSE;
  1668.             }
  1669.             else if (g_dwViewState == IDM_VIEWALL)
  1670.             {
  1671.                 // Print name
  1672.                 cchLen = _tcslen (pcd->szName);
  1673.                 if (! PrintLine (xName, yLine, pcd->szName, cchLen, lpInfo))
  1674.                     return FALSE;
  1675.  
  1676.                 // Print No in value column
  1677.                 cchLen = _tcslen (c_szNo);
  1678.                 if (! PrintLine (xVal, yLine, c_szNo, cchLen, lpInfo))
  1679.                     return FALSE;
  1680.  
  1681.                 // Advance to next line on page
  1682.                 if (! PrintNextLine (lpInfo))
  1683.                     return FALSE;
  1684.             }
  1685.         }
  1686.         else
  1687.         {
  1688.             char    szBuff[80];
  1689.  
  1690.             // Print name
  1691.             wsprintf (szBuff, pcd->szName, "test");
  1692.             cchLen = _tcslen (pcd->szName);
  1693.             if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  1694.                 return FALSE;
  1695.  
  1696.             // Print value
  1697.             wsprintf (szBuff, "%d", dwValue);
  1698.             cchLen = _tcslen (szBuff);
  1699.             if (! PrintLine (xVal, yLine, szBuff, cchLen, lpInfo))
  1700.                 return FALSE;
  1701.  
  1702.             // Advance to next line on page
  1703.             if (! PrintNextLine (lpInfo))
  1704.                 return FALSE;
  1705.         }
  1706.  
  1707.         pcd++;  // Get next Cap bit definition
  1708.     }
  1709.  
  1710.     // Success
  1711.     return TRUE;
  1712. } // End PrintCapsToDC
  1713.  
  1714.  
  1715. //================================================================
  1716. //================================================================
  1717. void DDAddCaps(LPARAM lParam1, LPARAM lParam2)
  1718. {
  1719.     // lParam1 is the GUID for the driver we should open
  1720.     // lParam2 is the CAPDEF table we should use
  1721.  
  1722.     if (DDCreate((GUID*)lParam1))
  1723.     {
  1724.         DDCAPS ddcaps;
  1725.  
  1726.         ddcaps.dwSize = sizeof(ddcaps);
  1727.  
  1728.         if (lParam1 == DDCREATE_EMULATIONONLY)
  1729.             IDirectDraw_GetCaps(lpDD, NULL, &ddcaps);
  1730.         else
  1731.             IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
  1732.  
  1733.         AddCapsToLV((CAPDEF *)lParam2, (LPVOID)&ddcaps);
  1734.     }
  1735. }
  1736.  
  1737.  
  1738. //================================================================
  1739. //================================================================
  1740. BOOL DDPrintCaps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  1741. {
  1742.     // lParam1 is the GUID for the driver we should open
  1743.     // lParam2 is the CAPDEF table we should use
  1744.  
  1745.     if (DDCreate((GUID*)lParam1))
  1746.     {
  1747.         DDCAPS ddcaps;
  1748.  
  1749.         ddcaps.dwSize = sizeof(ddcaps);
  1750.  
  1751.         if (lParam1 == DDCREATE_EMULATIONONLY)
  1752.             IDirectDraw_GetCaps(lpDD, NULL, &ddcaps);
  1753.         else
  1754.             IDirectDraw_GetCaps(lpDD, &ddcaps, NULL);
  1755.  
  1756.         // Print DirectDraw caps
  1757.         return PrintCapsToDC((CAPDEF *)lParam2, (LPVOID)&ddcaps, lpInfo);
  1758.     }
  1759.  
  1760.     // DDCreate failed but keep printing
  1761.     return TRUE;
  1762. }
  1763.  
  1764. //================================================================
  1765. //================================================================
  1766. void DSAddCaps(LPARAM lParam1, LPARAM lParam2)
  1767. {
  1768.     // lParam1 is the GUID for the driver we should open
  1769.     // lParam2 is the CAPDEF table we should use
  1770.  
  1771.     if (DSCreate((GUID*)lParam1))
  1772.     {
  1773.         DSCAPS dscaps;
  1774.  
  1775.         dscaps.dwSize = sizeof(dscaps);
  1776.  
  1777.         IDirectSound_GetCaps(lpDS, &dscaps);
  1778.  
  1779.         AddCapsToLV((CAPDEF *)lParam2, (LPVOID)&dscaps);
  1780.     }
  1781. }
  1782.  
  1783.  
  1784. //================================================================
  1785. //================================================================
  1786. BOOL DSPrintCaps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  1787. {
  1788.     // lParam1 is the GUID for the driver we should open
  1789.     // lParam2 is the CAPDEF table we should use
  1790.  
  1791.     if (DSCreate((GUID*)lParam1))
  1792.     {
  1793.         DSCAPS dscaps;
  1794.  
  1795.         dscaps.dwSize = sizeof(dscaps);
  1796.  
  1797.         IDirectSound_GetCaps(lpDS, &dscaps);
  1798.  
  1799.         // Print DirectSound Caps
  1800.         return PrintCapsToDC((CAPDEF *)lParam2, (LPVOID)&dscaps, lpInfo);
  1801.     }
  1802.  
  1803.     // DSCreate failed but keep printing
  1804.     return TRUE;
  1805. }
  1806.  
  1807.  
  1808. //================================================================
  1809. //================================================================
  1810. void DSCAddCaps(LPARAM lParam1, LPARAM lParam2)
  1811. {
  1812.     // lParam1 is the GUID for the driver we should open
  1813.     // lParam2 is the CAPDEF table we should use
  1814.  
  1815.     if (DSCCreate((GUID*)lParam1))
  1816.     {
  1817.         DSCCAPS dsccaps;
  1818.  
  1819.         dsccaps.dwSize = sizeof(dsccaps);
  1820.  
  1821.         IDirectSoundCapture_GetCaps(lpDSC, &dsccaps);
  1822.  
  1823.         AddCapsToLV((CAPDEF *)lParam2, (LPVOID)&dsccaps);
  1824.     }
  1825. }
  1826.  
  1827.  
  1828. //================================================================
  1829. //================================================================
  1830. BOOL DSCPrintCaps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  1831. {
  1832.     // lParam1 is the GUID for the driver we should open
  1833.     // lParam2 is the CAPDEF table we should use
  1834.  
  1835.     if (DSCCreate((GUID*)lParam1))
  1836.     {
  1837.         DSCCAPS dsccaps;
  1838.  
  1839.         dsccaps.dwSize = sizeof(dsccaps);
  1840.  
  1841.         IDirectSoundCapture_GetCaps(lpDSC, &dsccaps);
  1842.  
  1843.         // Print DirectSound Caps
  1844.         return PrintCapsToDC((CAPDEF *)lParam2, (LPVOID)&dsccaps, lpInfo);
  1845.     }
  1846.  
  1847.     // DSCCreate failed but keep printing
  1848.     return TRUE;
  1849. }
  1850.  
  1851.  
  1852. //================================================================
  1853. //================================================================
  1854. void DPAddCaps(LPARAM lParam1, LPARAM lParam2)
  1855. {
  1856.     // lParam1 is the GUID for the driver we should open
  1857.     // lParam2 is the CAPDEF table we should use
  1858.     HRESULT hr = DPERR_GENERIC;
  1859.  
  1860.     CAPDEF * pcd = (CAPDEF *) lParam2;
  1861.  
  1862.     if ( DPCreate( (GUID*) lParam1) )
  1863.     {
  1864.         DPCAPS    dpcaps,
  1865.                 dpcapsGuar;
  1866.         DWORD    dwValue,
  1867.                 dwValueGuar;
  1868.  
  1869.         memset(&dpcaps, 0, sizeof(DPCAPS));
  1870.         memset(&dpcapsGuar, 0, sizeof(DPCAPS));
  1871.  
  1872.         dpcaps.dwSize = sizeof(DPCAPS);
  1873.         dpcapsGuar.dwSize = sizeof(DPCAPS);
  1874.  
  1875.         hr = lpDP3A->lpVtbl->GetCaps(lpDP3A, &dpcapsGuar, DPGETCAPS_GUARANTEED);
  1876.  
  1877.         if (FAILED(hr))
  1878.         {
  1879.             return;
  1880.         }
  1881.  
  1882.         lpDP3A->lpVtbl->GetCaps(lpDP3A, &dpcaps, 0);
  1883.  
  1884.         if (FAILED(hr))
  1885.         {
  1886.             return;
  1887.         }
  1888.  
  1889.         LVAddColumn(g_hwndLV, 0, "Name", 24);
  1890.         LVAddColumn(g_hwndLV, 1, "Non-guaranteed", 16);
  1891.         LVAddColumn(g_hwndLV, 2, "Guaranteed", 16);
  1892.  
  1893.         while(pcd->szName && *pcd->szName)
  1894.         {
  1895.             dwValue = *((DWORD *)((BYTE *)&dpcaps + pcd->dwOffset));
  1896.             dwValueGuar = *((DWORD *)((BYTE *)&dpcapsGuar + pcd->dwOffset));
  1897.  
  1898.             LVAddText(g_hwndLV, 0, pcd->szName, "test");
  1899.             LVAddText(g_hwndLV, 1, "%d", dwValue);
  1900.             LVAddText(g_hwndLV, 2, "%d", dwValueGuar);
  1901.             pcd++;  // Get next Cap bit definition
  1902.         }
  1903.  
  1904.         LVAddText( g_hwndLV, 0, "Group Optimized" );
  1905.         LVAddText( g_hwndLV, 1, ( dpcaps.dwFlags & DPCAPS_GROUPOPTIMIZED ? c_szYes : c_szNo ) );
  1906.         LVAddText( g_hwndLV, 2, ( dpcapsGuar.dwFlags & DPCAPS_GROUPOPTIMIZED ? c_szYes : c_szNo ) );
  1907.  
  1908.         LVAddText( g_hwndLV, 0, "Guaranteed Optimized" );
  1909.         LVAddText( g_hwndLV, 1, ( dpcaps.dwFlags & DPCAPS_GUARANTEEDOPTIMIZED ? c_szYes : c_szNo ) );
  1910.         LVAddText( g_hwndLV, 2, ( dpcapsGuar.dwFlags & DPCAPS_GUARANTEEDOPTIMIZED ? c_szYes : c_szNo ) );
  1911.  
  1912.         LVAddText( g_hwndLV, 0, "Guaranteed Supported" );
  1913.         LVAddText( g_hwndLV, 1, ( dpcaps.dwFlags & DPCAPS_GUARANTEEDSUPPORTED ? c_szYes : c_szNo ) );
  1914.         LVAddText( g_hwndLV, 2, ( dpcapsGuar.dwFlags & DPCAPS_GUARANTEEDSUPPORTED ? c_szYes : c_szNo) );
  1915.  
  1916.         LVAddText( g_hwndLV, 0, "Keep Alive Optimized" );
  1917.         LVAddText( g_hwndLV, 1, ( dpcaps.dwFlags & DPCAPS_KEEPALIVEOPTIMIZED ? c_szYes : c_szNo ) );
  1918.         LVAddText( g_hwndLV, 2, ( dpcapsGuar.dwFlags & DPCAPS_KEEPALIVEOPTIMIZED ? c_szYes : c_szNo ) );
  1919.  
  1920.         lpDP3A->lpVtbl->Release(lpDP3A);
  1921.         lpDP3A = NULL;
  1922.  
  1923.     }
  1924. }
  1925.  
  1926. //================================================================
  1927. //================================================================
  1928. BOOL FAR PASCAL DPEnumLocalAppsCallback( LPCDPLAPPINFO lpAppInfo, LPVOID lpContext, DWORD dwFlags)
  1929. {
  1930.     LPLOCALAPP * lp = (LPLOCALAPP *) lpContext;
  1931.     LPLOCALAPP lpTemp = NULL;
  1932.     WCHAR wszBuffer[128];
  1933.  
  1934.  
  1935.     if (StringFromGUID2( &(lpAppInfo->guidApplication), wszBuffer, 128 ))
  1936.     {
  1937.         char szBuffer[128];
  1938.  
  1939.         wcstombs(szBuffer, wszBuffer, wcslen(wszBuffer)+1);
  1940.         if (g_hwndLV)
  1941.         {
  1942.             //when we are called the first time, 
  1943.             //the listview hasn't been created yet.
  1944.             LVAddText(g_hwndLV, 0, lpAppInfo->lpszAppNameA);
  1945.             LVAddText(g_hwndLV, 1, szBuffer);
  1946.         }
  1947.     }
  1948.  
  1949.     //Add to our local linked list of app names.
  1950.     //This list is used to provide the app names when we
  1951.     //enumerate sessions later.
  1952.     lpTemp = *lp;
  1953.     *lp = (LPLOCALAPP) LocalAlloc( LPTR, sizeof( LOCALAPP )+strlen(lpAppInfo->lpszAppNameA)+1 );
  1954.  
  1955.     if (*lp)
  1956.     {
  1957.         (*lp)->guidApplication = lpAppInfo->guidApplication;
  1958.         strcpy( (*lp)->szAppNameA, lpAppInfo->lpszAppNameA );
  1959.         (*lp)->lpNext = lpTemp;
  1960.     }
  1961.  
  1962.     return TRUE;
  1963. }
  1964.  
  1965.  
  1966. //================================================================
  1967. //================================================================
  1968. void DPAddLocalApps(LPARAM lParam1, LPARAM lParam2)
  1969. {
  1970.     // lParam1 is the GUID for the driver we should open
  1971.     // lParam2 is the CAPDEF table we should use
  1972.  
  1973.     LPDIRECTPLAYLOBBYA    lpDPLA    = NULL;
  1974.     HRESULT                hr        = DPERR_GENERIC;
  1975.     if (g_lpLocalApp)
  1976.     {
  1977.         FreeLocalAppList();
  1978.         g_lpLocalApp = NULL;
  1979.     }
  1980.  
  1981.     if ( g_hwndLV)
  1982.     {
  1983.         //When we are called the first time,
  1984.         //the list view has not been created yet.
  1985.         LVAddColumn(g_hwndLV, 0, "Name", 16);
  1986.         LVAddColumn(g_hwndLV, 1, "guidApplication", 48);
  1987.     }
  1988.  
  1989.     hr = DirectPlayLobbyCreateA(NULL, &lpDPLA, NULL, NULL, 0 );
  1990.  
  1991.     if (SUCCEEDED(hr))
  1992.     {
  1993.         lpDPLA->lpVtbl->EnumLocalApplications(lpDPLA, DPEnumLocalAppsCallback, &g_lpLocalApp, 0 );
  1994.         lpDPLA->lpVtbl->Release(lpDPLA);
  1995.     }
  1996.  
  1997. }
  1998.  
  1999.  
  2000. //================================================================
  2001. //================================================================
  2002. BOOL FAR PASCAL DPEnumLocalAppsPrintCallback( LPCDPLAPPINFO lpAppInfo, LPVOID lpContext, DWORD dwFlags)
  2003. {
  2004.     int        xName, 
  2005.             xGuid,
  2006.             yLine;
  2007.     PRINTCBINFO * lpInfo = (PRINTCBINFO *) lpContext;
  2008.     DWORD cchLen;
  2009.     WCHAR wszBuffer[128];
  2010.     char szBuffer[128];
  2011.  
  2012.     
  2013.     if (! lpInfo)
  2014.         return FALSE;
  2015.  
  2016.     if (dwFlags & DPESC_TIMEDOUT)
  2017.     {
  2018.         // We could reset lpdwTimeOut and return true to continue waiting
  2019.         // NOTE: This does not tell DirectPlay to query again for hosts.
  2020.         //       This just gives potentially slow hosts more time to respond
  2021.         //       to our initial query.
  2022.         return FALSE;  // Stop waiting for hosts
  2023.     }
  2024.  
  2025.     xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2026.     xGuid   = xName + (24 * lpInfo->dwCharWidth);
  2027.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2028.  
  2029.     // Print AppInfo information
  2030.  
  2031.     cchLen = strlen (lpAppInfo->lpszAppNameA);
  2032.     if (! PrintLine (xName, yLine, lpAppInfo->lpszAppNameA, cchLen, lpInfo))
  2033.         return FALSE;
  2034.  
  2035.     if (StringFromGUID2( &(lpAppInfo->guidApplication), wszBuffer, 128 ))
  2036.     {
  2037.         wcstombs(szBuffer, wszBuffer, wcslen(wszBuffer)+1);
  2038.  
  2039.         if (! PrintLine (xGuid, yLine, szBuffer, strlen(szBuffer), lpInfo))
  2040.             return FALSE;
  2041.  
  2042.         // Advance printer one line
  2043.         if (! PrintNextLine (lpInfo))
  2044.             return FALSE;
  2045.  
  2046.     }
  2047.  
  2048.     return TRUE;
  2049. }
  2050.  
  2051.  
  2052. //================================================================
  2053. //================================================================
  2054. BOOL DPPrintLocalApps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2055. {
  2056.     // lParam1 is the GUID for the driver we should open
  2057.     // lParam2 is the CAPDEF table we should use
  2058.  
  2059.     LPDIRECTPLAYLOBBYA    lpDPLA = NULL;
  2060.  
  2061.  
  2062.     DirectPlayLobbyCreateA(NULL, &lpDPLA, NULL, NULL, 0 );
  2063.  
  2064.     if (lpDPLA)
  2065.     {
  2066.         lpDPLA->lpVtbl->EnumLocalApplications(    lpDPLA, 
  2067.                                                 DPEnumLocalAppsPrintCallback, 
  2068.                                                 (LPVOID)lpInfo, 
  2069.                                                 0 );
  2070.         lpDPLA->lpVtbl->Release(lpDPLA);
  2071.     }
  2072.  
  2073.     // DPLobbyCreate failed but keep printing
  2074.     return TRUE;
  2075. }
  2076.  
  2077.  
  2078. //================================================================
  2079. //================================================================
  2080. BOOL DPPrintCaps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2081. {
  2082.     // lParam1 is the GUID for the driver we should open
  2083.     // lParam2 is the CAPDEF table we should use
  2084.  
  2085.     if (DPCreate((GUID*)lParam1))
  2086.     {
  2087.         DPCAPS dpcaps;
  2088.         BOOL    bKeepPrinting;
  2089.         HRESULT    hr = DPERR_GENERIC;
  2090.         int xName,
  2091.             xGuid,
  2092.             yLine;
  2093.  
  2094.         dpcaps.dwSize = sizeof(dpcaps);
  2095.         hr = lpDP3A->lpVtbl->GetCaps(lpDP3A, &dpcaps, 0);
  2096.  
  2097.         if (FAILED(hr))
  2098.         {
  2099.             // GetCaps failed but keep printing
  2100.             return TRUE;
  2101.         }
  2102.  
  2103.         // Advance printer one line
  2104.         if (! PrintNextLine (lpInfo))
  2105.             return FALSE;
  2106.  
  2107.         xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2108.         xGuid   = xName + (24 * lpInfo->dwCharWidth);
  2109.         yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2110.  
  2111.         if (! PrintLine (xName, yLine, "Non-guaranteed", 14, lpInfo))
  2112.             return FALSE;
  2113.  
  2114.         // Advance printer one line
  2115.         if (! PrintNextLine (lpInfo))
  2116.             return FALSE;
  2117.  
  2118.         // Advance printer one line
  2119.         if (! PrintNextLine (lpInfo))
  2120.             return FALSE;
  2121.  
  2122.         bKeepPrinting = PrintCapsToDC ((CAPDEF *)lParam2, (LPVOID)&dpcaps, lpInfo);
  2123.  
  2124.         // Advance printer one line
  2125.         if (! PrintNextLine (lpInfo))
  2126.             return FALSE;
  2127.         // Advance printer one line
  2128.         if (! PrintNextLine (lpInfo))
  2129.             return FALSE;
  2130.  
  2131.         if (bKeepPrinting)
  2132.         {
  2133.             hr = lpDP3A->lpVtbl->GetCaps(lpDP3A, &dpcaps, DPGETCAPS_GUARANTEED );
  2134.             if (FAILED(hr))
  2135.             {
  2136.                 // GetCaps failed but keep printing
  2137.                 return TRUE;
  2138.             }
  2139.  
  2140.             xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2141.             xGuid   = xName + (24 * lpInfo->dwCharWidth);
  2142.             yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2143.  
  2144.             if (! PrintLine (xName, yLine, "Guaranteed", 10, lpInfo))
  2145.                 return FALSE;
  2146.  
  2147.             // Advance printer one line
  2148.             if (! PrintNextLine (lpInfo))
  2149.                 return FALSE;
  2150.  
  2151.             // Advance printer one line
  2152.             if (! PrintNextLine (lpInfo))
  2153.                 return FALSE;
  2154.  
  2155.             // Print DirectPlay caps
  2156.             bKeepPrinting = PrintCapsToDC ((CAPDEF *)lParam2, (LPVOID)&dpcaps, lpInfo);
  2157.  
  2158.             // Advance printer one line
  2159.             if (! PrintNextLine (lpInfo))
  2160.                 return FALSE;
  2161.         }
  2162.         
  2163.         return bKeepPrinting;
  2164.     }
  2165.  
  2166.     // DPCreate failed but keep printing
  2167.     return TRUE;
  2168. }
  2169.  
  2170. //================================================================
  2171. //================================================================
  2172. void D3AddCaps(LPARAM lParam1, LPARAM lParam2)
  2173. {
  2174.     // lParam1 is the CAP3DDEVICEDESC Struct
  2175.     // lParam2 is the CAPDEF table we should use
  2176.  
  2177.     // Unlike other AddCaps function this info has been prethought for us
  2178.     // so just print it out.
  2179.     AddCapsToLV((CAPDEF *)lParam2, (LPVOID)lParam1);
  2180. }
  2181.  
  2182. //================================================================
  2183. //================================================================
  2184. void D3AddLineCaps(LPARAM lParam1, LPARAM lParam2)
  2185. {
  2186.     // lParam1 is the CAP3DDEVICEDESC Struct
  2187.     // lParam2 is the CAPDEF table we should use
  2188.  
  2189.     CAP3DDEVICEDESC *p = (CAP3DDEVICEDESC*)lParam1;
  2190.     D3DPRIMCAPS     save;
  2191.  
  2192.     // slam the line caps over the triangle caps so we can use the
  2193.     // same tables
  2194.     save = p->d3dDeviceDesc.dpcTriCaps;
  2195.     p->d3dDeviceDesc.dpcTriCaps = p->d3dDeviceDesc.dpcLineCaps;
  2196.     AddCapsToLV((CAPDEF *)lParam2, (LPVOID)lParam1);
  2197.     p->d3dDeviceDesc.dpcTriCaps = save;
  2198. }
  2199.  
  2200. //================================================================
  2201. //================================================================
  2202.  
  2203. int BitCount(DWORD dw)
  2204. {
  2205.     int i;
  2206.  
  2207.     for (i=0; dw; dw=dw>>1)
  2208.         i += (dw & 1);
  2209.  
  2210.     return i;
  2211. }
  2212.  
  2213. //================================================================
  2214. //================================================================
  2215. HRESULT CALLBACK EnumTextureCallback(DDSURFACEDESC *pddsd, LPVOID lParam)
  2216. {
  2217.     DDPIXELFORMAT ddpf = pddsd->ddpfPixelFormat;
  2218.     TCHAR ach[80];
  2219.  
  2220.     if (ddpf.dwRBitMask == 0 && ddpf.dwGBitMask == 0 && ddpf.dwBBitMask == 0)
  2221.         wsprintf(ach, "%d bit", ddpf.dwRGBBitCount);
  2222.     else if (BitCount(ddpf.dwRGBAlphaBitMask) == 0)
  2223.         wsprintf(ach, "%d bit %d%d%d",
  2224.             ddpf.dwRGBBitCount,
  2225.             BitCount(ddpf.dwRBitMask),
  2226.             BitCount(ddpf.dwGBitMask),
  2227.             BitCount(ddpf.dwBBitMask));
  2228.     else
  2229.         wsprintf(ach, "%d bit %d%d%d%d",
  2230.             ddpf.dwRGBBitCount,
  2231.             BitCount(ddpf.dwRBitMask),
  2232.             BitCount(ddpf.dwGBitMask),
  2233.             BitCount(ddpf.dwBBitMask),
  2234.             BitCount(ddpf.dwRGBAlphaBitMask));
  2235.  
  2236.     LVAddText(g_hwndLV, 0, ach);
  2237.  
  2238.     ach[0] = 0;
  2239.  
  2240.     if (ddpf.dwFlags & DDPF_RGB)
  2241.         lstrcat(ach,"RGB ");
  2242.     if (ddpf.dwFlags & DDPF_YUV)
  2243.         lstrcat(ach,"YUV ");
  2244.     if (ddpf.dwFlags & DDPF_PALETTEINDEXED8)
  2245.         lstrcat(ach,"PAL8 ");
  2246.     if (ddpf.dwFlags & DDPF_PALETTEINDEXED4)
  2247.         lstrcat(ach,"PAL4 ");
  2248.     if (ddpf.dwFlags & DDPF_ALPHA)
  2249.         lstrcat(ach,"ALPHA ");
  2250.     if (ddpf.dwFlags & DDPF_ALPHAPIXELS)
  2251.         lstrcat(ach,"ALPHAPIXELS ");
  2252.  
  2253.     LVAddText(g_hwndLV, 1, ach);
  2254.  
  2255.     return DDENUMRET_OK;
  2256. }
  2257.  
  2258. //================================================================
  2259. //================================================================
  2260.  
  2261. void D3AddTexF(LPARAM lParam1, LPARAM lParam2)
  2262. {
  2263.     // lParam1 is the CAP3DDEVICEDESC Struct
  2264.     // lParam2 is 0
  2265.  
  2266.     CAP3DDEVICEDESC *p = (CAP3DDEVICEDESC*)lParam1;
  2267.  
  2268.     //
  2269.     // this is going to be tricky
  2270.     // to enum the texture formats we are going to need
  2271.     // a Direct3DDevice, to get a device we need a surface
  2272.     // to get a surface we might need to chage the video mode!
  2273.     // also to create a device we will need a palette in 8 bpp modes!
  2274.     // mabey we should just use the primary surface?
  2275.     //
  2276.     if (DDCreate(p->device) && lp3D)
  2277.     {
  2278.         IDirectDrawSurface *Surface=NULL;
  2279.         IDirectDrawPalette *Palette=NULL;
  2280.         IDirect3DDevice2   *Device=NULL;
  2281.  
  2282.         DDSURFACEDESC ddsd;
  2283.         ZeroMemory(&ddsd, sizeof(ddsd));
  2284.  
  2285.         ddsd.dwSize = sizeof(ddsd);
  2286.         ddsd.dwFlags = DDSD_CAPS;
  2287.         ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; // | DDSCAPS_VIDEOMEMORY;
  2288.  
  2289.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NOWINDOWCHANGES);
  2290.         IDirectDraw_CreateSurface(lpDD, &ddsd, &Surface, NULL);
  2291.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_NORMAL);
  2292.  
  2293.         if (Surface)
  2294.         {
  2295.             //
  2296.             // before we can create a 3D device, we need to
  2297.             // attach a palette (8 bpp modes only)
  2298.             //
  2299.             IDirectDrawSurface_GetSurfaceDesc(Surface, &ddsd);
  2300.  
  2301.             if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8)
  2302.             {
  2303.                 HDC hdc;
  2304.                 PALETTEENTRY ape[256];
  2305.  
  2306.                 hdc = GetDC(NULL);
  2307.                 GetSystemPaletteEntries(hdc, 0, 256, ape);
  2308.                 ReleaseDC(NULL, hdc);
  2309.  
  2310.                 IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT, ape, &Palette, NULL);
  2311.  
  2312.                 if (Palette)
  2313.                 {
  2314.                     IDirectDrawSurface_SetPalette(Surface, Palette);
  2315.                 }
  2316.             }
  2317.         }
  2318.  
  2319.         if (Surface)
  2320.         {
  2321.             IDirect3D2_CreateDevice(lp3D, &p->driver, Surface, &Device);
  2322.  
  2323.             if (Device == NULL)
  2324.             {
  2325.                 IDirectDrawSurface_Release(Surface);
  2326.                 Surface = NULL;
  2327.  
  2328.                 //
  2329.                 // we cant create a 3d device for the primary, create a
  2330.                 // 555 offscreen surface and try that
  2331.                 //
  2332.                 ddsd.dwSize = sizeof(ddsd);
  2333.                 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH;
  2334.                 ddsd.dwWidth = 100;
  2335.                 ddsd.dwHeight = 100;
  2336.                 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
  2337.                 ddsd.ddpfPixelFormat.dwSize            = sizeof(DDPIXELFORMAT);
  2338.                 ddsd.ddpfPixelFormat.dwFlags           = DDPF_RGB;
  2339.                 ddsd.ddpfPixelFormat.dwFourCC          = 0;
  2340.                 ddsd.ddpfPixelFormat.dwRGBBitCount     = 16;
  2341.                 ddsd.ddpfPixelFormat.dwRBitMask        = 0x7C00; // 0xF800;
  2342.                 ddsd.ddpfPixelFormat.dwGBitMask        = 0x03E0; // 0x07E0;
  2343.                 ddsd.ddpfPixelFormat.dwBBitMask        = 0x001F; // 0x001F;
  2344.                 ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0x0000;
  2345.  
  2346.                 IDirectDraw_CreateSurface(lpDD, &ddsd, &Surface, NULL);
  2347.  
  2348.                 if (Surface != NULL)
  2349.                 {
  2350.                     IDirect3D2_CreateDevice(lp3D, &p->driver, Surface, &Device);
  2351.                 }
  2352.             }
  2353.  
  2354.             if (Device)
  2355.             {
  2356.                 LVAddColumn(g_hwndLV, 0, "Format", 24);
  2357.                 LVAddColumn(g_hwndLV, 1, "Flags", 24);
  2358.  
  2359.                 IDirect3DDevice2_EnumTextureFormats(Device, EnumTextureCallback, NULL);
  2360.                 IDirect3DDevice2_Release(Device);
  2361.             }
  2362.             else
  2363.             {
  2364.                 LVAddColumn(g_hwndLV, 0, "Message", 50);
  2365.                 LVAddText(g_hwndLV, 0, "Cant create D3D Device, change display mode.");
  2366.             }
  2367.  
  2368.             if (Surface)
  2369.             {
  2370.                 IDirectDrawSurface_Release(Surface);
  2371.             }
  2372.  
  2373.             if (Palette)
  2374.             {
  2375.                 IDirectDrawPalette_Release(Palette);
  2376.             }
  2377.         }
  2378.         else
  2379.         {
  2380.             LVAddColumn(g_hwndLV, 0, "Message", 50);
  2381.             LVAddText(g_hwndLV, 0, "Cant create surface.");
  2382.         }
  2383.     }
  2384. }
  2385.  
  2386. //================================================================
  2387. //================================================================
  2388. BOOL D3PrintCaps(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2389. {
  2390.     // lParam1 is the CAP3DDEVICEDESC Struct
  2391.     // lParam2 is the CAPDEF table we should use
  2392.  
  2393.     // Unlike other PrintCaps function this info has been prethought for us
  2394.     // so just print it out.
  2395.     return PrintCapsToDC ((CAPDEF *)lParam2, (LPVOID)lParam1, lpInfo);
  2396. }
  2397.  
  2398. //================================================================
  2399. // EnumSessionsCallback
  2400. //================================================================
  2401. BOOL PASCAL EnumSessionsCallback
  2402. (
  2403. LPCDPSESSIONDESC2 lpDesc,         // Pointer to Session Description Struct
  2404. LPDWORD lpdwTimeOut,          // Used to extend the timeout if hosts aren't responding quickly enough.
  2405. DWORD dwFlags,                 // Flags (used to notify us when we've timed out).
  2406. LPVOID    lpContext
  2407. )
  2408. {
  2409.     BOOL                    bDataAvailable;
  2410.     char                    szBuffer[128];
  2411.     DWORD                    dwSize            = 128;
  2412.     LPLV_INSTANCEGUIDSTRUCT    lpInstGuidStruct = NULL;
  2413.     LV_ITEM                    lvi;
  2414.  
  2415.     int                        i, count;
  2416.     BOOL                    bGuidNotFound;
  2417.  
  2418.     memset( &lvi, 0, sizeof( LV_ITEM ));
  2419.  
  2420.     if (dwFlags & DPESC_TIMEDOUT)
  2421.     {
  2422.         // We could reset lpdwTimeOut and return true to continue waiting
  2423.         // NOTE: This does not tell DirectPlay to query again for hosts.
  2424.         //       This just gives potentially slow hosts more time to respond
  2425.         //       to our initial query.
  2426.         return FALSE;  // Stop waiting for hosts
  2427.     }
  2428.  
  2429.     i = 0;
  2430.     count = ListView_GetItemCount( g_hwndLV );
  2431.     bGuidNotFound = TRUE;
  2432.  
  2433.     while ((bGuidNotFound) && ( i < count))
  2434.     {
  2435.         lvi.iItem = i;
  2436.         lvi.mask = LVIF_PARAM;
  2437.         lvi.lParam = 0;
  2438.  
  2439.         bDataAvailable =ListView_GetItem( g_hwndLV, &lvi );
  2440.         
  2441.         if (bDataAvailable)
  2442.         {
  2443.             lpInstGuidStruct = (LPLV_INSTANCEGUIDSTRUCT) lvi.lParam;
  2444.             
  2445.             if (lpInstGuidStruct)
  2446.             {
  2447.                 if ( IsEqualGUID(    &(lpDesc->guidInstance),
  2448.                                     &(lpInstGuidStruct->guidInstance) ) )
  2449.                 {
  2450.                     //This session is already in our list. Mark that it is active,
  2451.                     //so it doesn't get deleted when the next timer fires.
  2452.                     lpInstGuidStruct->dwRefresh = TRUE;
  2453.                     bGuidNotFound = FALSE;
  2454.                 }
  2455.             }
  2456.             else
  2457.             {
  2458.                 //This item has no pointer to a guidInstance, it must be invalid.
  2459.                 ListView_DeleteItem( g_hwndLV, i);
  2460.             }
  2461.         }
  2462.         else
  2463.         {
  2464.             //This item has no data, so it must be invalid.
  2465.             ListView_DeleteItem( g_hwndLV, i);
  2466.         }
  2467.  
  2468.         i++;
  2469.     }
  2470.  
  2471.     if (bGuidNotFound)
  2472.     {
  2473.         // This session was in our list view. 
  2474.         // Add new session information to table
  2475.         i = LVAddText(g_hwndLV, 0, ( lpDesc->lpszSessionNameA ? lpDesc->lpszSessionNameA : "<NO SESSION NAME>" ) );
  2476.  
  2477.         GetAppName(szBuffer, &(lpDesc->guidApplication), dwSize);
  2478.         LVAddText(g_hwndLV, 1, szBuffer);
  2479.  
  2480.         LVAddText(g_hwndLV, 2, "%d", lpDesc->dwMaxPlayers);
  2481.         LVAddText(g_hwndLV, 3, "%d", lpDesc->dwCurrentPlayers);
  2482.         LVAddText(g_hwndLV, 4, (lpDesc->dwFlags&DPSESSION_SECURESERVER ? c_szYes : c_szNo ) );
  2483.         LVAddText(g_hwndLV, 5, (lpDesc->dwFlags&DPSESSION_PASSWORDREQUIRED ? c_szYes : c_szNo ));
  2484.  
  2485.         //Keep track of our guidInstance so we'll recognize this session
  2486.         //when we enumerate later
  2487.         lpInstGuidStruct = (LPLV_INSTANCEGUIDSTRUCT) LocalAlloc( LPTR, sizeof(LV_INSTANCEGUIDSTRUCT));
  2488.  
  2489.         if (lpInstGuidStruct)
  2490.         {
  2491.             LV_ITEM    lvi;
  2492.             memset( &lvi, 0, sizeof( LV_ITEM));
  2493.             lpInstGuidStruct->guidInstance = lpDesc->guidInstance;
  2494.             lpInstGuidStruct->dwRefresh = TRUE;
  2495.  
  2496.             lvi.iItem = i;
  2497.             lvi.mask = LVIF_PARAM;
  2498.             lvi.lParam = (long) lpInstGuidStruct;
  2499.   
  2500.             ListView_SetItem( g_hwndLV, (LPARAM)&lvi, ); 
  2501.         }
  2502.     }
  2503.  
  2504.     //Keep enumerating until it times out on its own.
  2505.     return TRUE;
  2506. }
  2507.  
  2508.  
  2509. //================================================================
  2510. // EnumPrintSessionsCallback
  2511. //================================================================
  2512. BOOL PASCAL EnumPrintSessionsCallback 
  2513. (
  2514.     LPCDPSESSIONDESC2 lpDesc,         // Pointer to Session Description Struct
  2515.     LPDWORD         lpdwTimeOut,    // Used to extend the timeout if hosts aren't responding quickly enough.
  2516.     DWORD           dwFlags,         // Flags (used to notify us when we've timed out).
  2517.     LPVOID          lpContext         // User definable data passed in from EnumSessions() call.
  2518. )
  2519. {
  2520.     int xName,  yLine;
  2521.     PRINTCBINFO * lpInfo = (PRINTCBINFO *) lpContext;
  2522.     CHAR szBuff[256],
  2523.          szAppName[128];
  2524.     DWORD cchLen;
  2525.     
  2526.     if (! lpInfo)
  2527.         return FALSE;
  2528.  
  2529.     if (dwFlags & DPESC_TIMEDOUT)
  2530.     {
  2531.         // We could reset lpdwTimeOut and return true to continue waiting
  2532.         // NOTE: This does not tell DirectPlay to query again for hosts.
  2533.         //       This just gives potentially slow hosts more time to respond
  2534.         //       to our initial query.
  2535.         return FALSE;  // Stop waiting for hosts
  2536.     }
  2537.  
  2538.     xName   = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2539.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2540.  
  2541.     // Print session information
  2542.     wsprintf (szBuff, "Session Name   : %s", lpDesc->lpszSessionNameA);
  2543.     cchLen = strlen (szBuff);
  2544.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2545.         return FALSE;
  2546.     if (! PrintNextLine (lpInfo))
  2547.         return FALSE;
  2548.  
  2549.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2550.     GetAppName( szAppName, &(lpDesc->guidApplication), 128 );
  2551.     wsprintf (szBuff, "App Name/GUID  : %s", szAppName);
  2552.     cchLen = strlen (szBuff);
  2553.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2554.         return FALSE;
  2555.     if (! PrintNextLine (lpInfo))
  2556.         return FALSE;
  2557.  
  2558.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2559.     wsprintf (szBuff, "Max Players    : %d", lpDesc->dwMaxPlayers);
  2560.     cchLen = strlen (szBuff);
  2561.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2562.         return FALSE;
  2563.     if (! PrintNextLine (lpInfo))
  2564.         return FALSE;
  2565.  
  2566.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2567.     wsprintf (szBuff, "Cur Players    : %d", lpDesc->dwCurrentPlayers);
  2568.     cchLen = strlen (szBuff);
  2569.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2570.         return FALSE;
  2571.     if (! PrintNextLine (lpInfo))
  2572.         return FALSE;
  2573.  
  2574.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2575.      wsprintf (szBuff, "Secure Session : %s",(lpDesc->dwFlags&DPSESSION_SECURESERVER ? c_szYes : c_szNo ) ); 
  2576.     cchLen = strlen (szBuff);
  2577.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2578.         return FALSE;
  2579.     if (! PrintNextLine (lpInfo))
  2580.         return FALSE;
  2581.  
  2582.   
  2583.     yLine   = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2584.      wsprintf (szBuff, "Password Req'd : %s",(lpDesc->dwFlags&DPSESSION_PASSWORDREQUIRED  ? c_szYes : c_szNo ) ); 
  2585.     cchLen = strlen (szBuff);
  2586.     if (! PrintLine (xName, yLine, szBuff, cchLen, lpInfo))
  2587.         return FALSE;
  2588.     if (! PrintNextLine (lpInfo))
  2589.         return FALSE;
  2590.  
  2591.     // Advance printer one line
  2592.     if (! PrintNextLine (lpInfo))
  2593.         return FALSE;
  2594.  
  2595.     // Success
  2596.     return TRUE;
  2597. }
  2598.  
  2599. //================================================================
  2600. //================================================================
  2601. void DPAddSessions(LPARAM lParam1, LPARAM lParam2)
  2602. {
  2603.     // lParam1 is the GUID for the driver we should open
  2604.     // lParam2 is the CAPDEF table we should use
  2605.     HRESULT    hr = DPERR_GENERIC;
  2606.  
  2607.     if (DPCreate((GUID*)lParam1))
  2608.     {
  2609.         LVAddColumn(g_hwndLV, 0, "Session Name", 16);
  2610.         LVAddColumn(g_hwndLV, 1, "Application Name/GUID", 24);
  2611.         LVAddColumn(g_hwndLV, 2, "Max", 4);
  2612.         LVAddColumn(g_hwndLV, 3, "Cur", 4);
  2613.         LVAddColumn(g_hwndLV, 4, "Sec", 4);
  2614.         LVAddColumn(g_hwndLV, 5, "Pwd", 5);
  2615.  
  2616.         hr = EnumSessions(    lpDP3A );
  2617.         if (SUCCEEDED(hr))
  2618.         {
  2619.             g_idTimer = SetTimer(g_hwndMain, 1, TIMER_PERIOD, NULL);
  2620.         }
  2621.     }
  2622. }
  2623.  
  2624.  
  2625. //================================================================
  2626. //================================================================
  2627. BOOL DPPrintSessions(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2628. {
  2629.     // lParam1 is the GUID for the driver we should open
  2630.     // lParam2 is the CAPDEF table we should use
  2631.  
  2632.     DPSESSIONDESC2   dps;
  2633.     HCURSOR         hCur=NULL;
  2634.     HRESULT            hr = DPERR_GENERIC;
  2635.  
  2636.     memset(&dps, 0, sizeof(DPSESSIONDESC2));
  2637.     dps.dwSize = sizeof(DPSESSIONDESC2);
  2638.  
  2639.     hCur=SetCursor(LoadCursor(NULL, IDC_WAIT));
  2640.  
  2641.     if (DPCreate((GUID*)lParam1))
  2642.     {
  2643.         hr = lpDP3A->lpVtbl->EnumSessions (    lpDP3A, &dps, 0, EnumPrintSessionsCallback, 
  2644.                                         (LPVOID)lpInfo,             
  2645.                                         DPENUMSESSIONS_ALL|
  2646.                                         DPENUMSESSIONS_PASSWORDREQUIRED );
  2647.  
  2648.     }
  2649.  
  2650.     if (hCur)
  2651.         SetCursor(hCur);
  2652.  
  2653.     return TRUE;
  2654. }
  2655.  
  2656. //================================================================
  2657. //================================================================
  2658. typedef struct LLMode
  2659. {
  2660.     DWORD x,y,bpp;    
  2661.         BOOL IsModeX;
  2662.         struct LLMode *Next;
  2663. }LinkMode;    
  2664.  
  2665. static LinkMode *pModesHead = NULL; 
  2666.  
  2667. void DDFourCCFormat(LPARAM lParam1, LPARAM lParam2)
  2668. {
  2669.     HRESULT ddrval;
  2670.     int iNumOfCodes,iCount;
  2671.     DWORD *FourCC;
  2672.     char szText[5]={0,0,0,0,0};
  2673.  
  2674.     if(lpDD != NULL)
  2675.     {
  2676.         ddrval = IDirectDraw_GetFourCCCodes(lpDD,&iNumOfCodes, NULL);
  2677.         LVAddColumn(g_hwndLV, 0, "Codes", 24);
  2678.         LVAddColumn(g_hwndLV, 1, "", 24);
  2679.         if( ddrval == DD_OK)
  2680.         {
  2681.             FourCC = GlobalAlloc(GPTR,(sizeof(DWORD)*iNumOfCodes));
  2682.             if(FourCC)
  2683.             {
  2684.                 ddrval = IDirectDraw_GetFourCCCodes(lpDD,&iNumOfCodes, FourCC);
  2685.                 // Assume all FourCC values are ascii strings
  2686.                 for(iCount = 0;iCount < iNumOfCodes; iCount++)
  2687.                 {
  2688.                     memcpy(szText,&FourCC[iCount],4);
  2689.                     LVAddText(g_hwndLV, 0, "%s", szText);
  2690.                 }
  2691.             }
  2692.         }
  2693.     }
  2694. }
  2695.  
  2696.  
  2697. //================================================================
  2698. //================================================================
  2699. BOOL DDPrintFourCCFormat(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2700. {
  2701.     HRESULT ddrval;
  2702.     int iNumOfCodes,iCount;
  2703.     DWORD *FourCC;
  2704.     char szText[5]={0,0,0,0,0};
  2705.     int  xCode, yLine;
  2706.  
  2707.  
  2708.     if(lpDD != NULL)
  2709.     {
  2710.         ddrval = IDirectDraw_GetFourCCCodes(lpDD,&iNumOfCodes, NULL);
  2711.         if( ddrval == DD_OK)
  2712.         {
  2713.             FourCC = GlobalAlloc(GPTR,(sizeof(DWORD)*iNumOfCodes));
  2714.             if(FourCC)
  2715.             {
  2716.                 xCode  = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2717.                 ddrval = IDirectDraw_GetFourCCCodes(lpDD,&iNumOfCodes, FourCC);
  2718.                 if (ddrval == DD_OK)
  2719.                 {
  2720.                     // Assume all FourCC values are ascii strings
  2721.                     for(iCount = 0;iCount < iNumOfCodes; iCount++)
  2722.                     {
  2723.                         yLine  = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2724.     
  2725.                         memcpy(szText,&FourCC[iCount],4);
  2726.          
  2727.                         // Print Code
  2728.                         if (! PrintLine (xCode, yLine, szText, 4, lpInfo))
  2729.                             return FALSE;
  2730.  
  2731.                         if (! PrintNextLine (lpInfo))
  2732.                             return FALSE;
  2733.                     }
  2734.                 }
  2735.             }
  2736.         }
  2737.     }
  2738.  
  2739.     // Success
  2740.     return TRUE;
  2741. }
  2742.  
  2743.  
  2744. //================================================================
  2745. //================================================================
  2746.  
  2747. //================================================================
  2748. // DisplayEnumModes
  2749. //================================================================
  2750. HRESULT CALLBACK EnumDisplayModesCallback(LPDDSURFACEDESC pddsd, LPVOID Context)
  2751. {
  2752.     if(pddsd->ddsCaps.dwCaps & DDSCAPS_STANDARDVGAMODE)
  2753.     {
  2754.         LVAddText(g_hwndLV, 0, "%dx%dx%d (StandardVGA)", pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2755.     }else if(pddsd->ddsCaps.dwCaps & DDSCAPS_MODEX)
  2756.     {
  2757.         LVAddText(g_hwndLV, 0, "%dx%dx%d (ModeX)", pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2758.     }else
  2759.     {
  2760.         LVAddText(g_hwndLV, 0, "%dx%dx%d ", pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2761.     }
  2762.     return DDENUMRET_OK;
  2763. } /* EnumModesCallback */
  2764.  
  2765. HRESULT CALLBACK EnumDisplayModesCallbackPrint(LPDDSURFACEDESC pddsd, LPVOID Context)
  2766. {
  2767.     TCHAR szBuff[80];
  2768.     DWORD cchLen;
  2769.     PRINTCBINFO * lpInfo = Context;
  2770.     int xMode, yLine;
  2771.  
  2772.     if (! lpInfo)
  2773.         return FALSE;
  2774.  
  2775.     xMode = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
  2776.     yLine = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
  2777.  
  2778.     if(pddsd->ddsCaps.dwCaps & DDSCAPS_STANDARDVGAMODE)
  2779.     {
  2780.         wsprintf(szBuff, TEXT("%dx%dx%d (StandardVGA)"), pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2781.     }else if(pddsd->ddsCaps.dwCaps & DDSCAPS_MODEX)
  2782.     {
  2783.         wsprintf(szBuff, TEXT("%dx%dx%d (ModeX)"), pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2784.     }else
  2785.     {
  2786.         wsprintf(szBuff, TEXT("%dx%dx%d "), pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount);
  2787.     }
  2788.     // Print Mode Info
  2789.     cchLen = _tcslen (szBuff);
  2790.     if (! PrintLine (xMode, yLine, szBuff, cchLen, lpInfo))
  2791.         return DDENUMRET_CANCEL;
  2792.     // Advance to next line
  2793.     if (! PrintNextLine (lpInfo))
  2794.         return DDENUMRET_CANCEL;
  2795.  
  2796.     return DDENUMRET_OK;
  2797. } /* EnumModesCallback */
  2798.  
  2799. //================================================================
  2800. // PrintEnumModes
  2801. //================================================================
  2802. /*BOOL PrintEnumModes ()
  2803. {
  2804.     LinkMode *tmp= NULL;
  2805.  
  2806.  
  2807.     tmp = pModesHead;
  2808.     while (tmp != NULL) //cycle though all modes since unique modes don't always happen
  2809.     {
  2810.  
  2811.         if (tmp->IsModeX)
  2812.             wsprintf (szBuff, TEXT("%dx%dx%d (ModeX)"), tmp->x, tmp->y, tmp->bpp);
  2813.         else
  2814.             wsprintf (szBuff, TEXT("%dx%dx%d "), tmp->x, tmp->y, tmp->bpp);
  2815.  
  2816.  
  2817.         tmp = tmp->Next;
  2818.     }
  2819.  
  2820.     // Success
  2821.     return TRUE;
  2822. }*/ /* EnumModesCallback */
  2823.  
  2824. //================================================================
  2825. // Should we hourglass the cursor? this takes a while
  2826. //================================================================
  2827. void DDAddVideoModes(LPARAM lParam1, LPARAM lParam2)
  2828. {
  2829.     DWORD mode;
  2830.     DDSURFACEDESC ddsd;
  2831.  
  2832.     LVAddColumn(g_hwndLV, 0, "Mode", 24);
  2833.     LVAddColumn(g_hwndLV, 1, "", 24);
  2834.  
  2835.     // lParam1 is the GUID for the driver we should open
  2836.     // lParam2 is not used
  2837.  
  2838.     if (DDCreate((GUID*)lParam1))
  2839.     {
  2840.         // Get the current mode mode for this driver
  2841.         ddsd.dwSize = sizeof(DDSURFACEDESC);
  2842.         IDirectDraw_GetDisplayMode(lpDD, &ddsd);
  2843.  
  2844.         mode = MAKEMODE(ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount);
  2845.  
  2846.         // Find all mode for this driver and add them to the listview
  2847.         //Erase previous list
  2848.         {
  2849.             LinkMode *tmp, *tmp1;    
  2850.  
  2851.             tmp = pModesHead;
  2852.             while(tmp != NULL)
  2853.             {
  2854.                 tmp1 = tmp;
  2855.                 tmp = tmp->Next;
  2856.                 GlobalFree(tmp1);  //Note We will exit with a list in place
  2857.             }
  2858.             pModesHead = NULL;
  2859.         }
  2860.         //Get Modes
  2861.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWMODEX | DDSCL_NOWINDOWCHANGES);
  2862.         IDirectDraw_EnumDisplayModes(lpDD, DDEDM_STANDARDVGAMODES, NULL, (LPVOID)mode, EnumDisplayModesCallback);
  2863.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_NORMAL);
  2864.     }
  2865. }
  2866.  
  2867.  
  2868. //================================================================
  2869. // Should we hourglass the cursor? this takes a while
  2870. //================================================================
  2871. BOOL DDPrintVideoModes(LPARAM lParam1, LPARAM lParam2, PRINTCBINFO * lpInfo)
  2872. {
  2873.     BOOL  fResult = TRUE;   // Even if we can't enum modes, let's keep on printing other stuff
  2874.     DWORD mode;
  2875.     DDSURFACEDESC ddsd;
  2876.  
  2877.     LVAddColumn(g_hwndLV, 0, "Mode", 24);
  2878.     LVAddColumn(g_hwndLV, 1, "", 24);
  2879.  
  2880.     // lParam1 is the GUID for the driver we should open
  2881.     // lParam2 is not used
  2882.  
  2883.     if (DDCreate((GUID*)lParam1))
  2884.     {
  2885.         // Get the current mode mode for this driver
  2886.         ddsd.dwSize = sizeof(DDSURFACEDESC);
  2887.         IDirectDraw_GetDisplayMode(lpDD, &ddsd);
  2888.  
  2889.         mode = MAKEMODE(ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount);
  2890.  
  2891.         // Find all mode for this driver and add them to the listview
  2892.         //Erase previous list
  2893.         {
  2894.             LinkMode *tmp, *tmp1;    
  2895.  
  2896.             tmp = pModesHead;
  2897.             while(tmp != NULL)
  2898.             {
  2899.                 tmp1 = tmp;
  2900.                 tmp = tmp->Next;
  2901.                 GlobalFree(tmp1);  //Note We will exit with a list in place
  2902.             }
  2903.             pModesHead = NULL;
  2904.         }
  2905.  
  2906.         //Get Mode with ModeX
  2907.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWMODEX | DDSCL_NOWINDOWCHANGES);
  2908.         IDirectDraw_EnumDisplayModes(lpDD, DDEDM_STANDARDVGAMODES, NULL, (LPVOID)lpInfo, EnumDisplayModesCallbackPrint);
  2909.         IDirectDraw_SetCooperativeLevel(lpDD, g_hwndMain, DDSCL_NORMAL);
  2910.     }
  2911.  
  2912.     // Success
  2913.     return fResult;
  2914. } // End DDPrintVideoModes
  2915.  
  2916.  
  2917. //================================================================
  2918. //================================================================
  2919. void DXView_OnTreeSelect(HWND hwndTV, NM_TREEVIEW *ptv)
  2920. {
  2921.     NODEINFO *pni;
  2922.  
  2923.     SendMessage(g_hwndLV, WM_SETREDRAW, FALSE, 0);
  2924.     LVDeleteAllItems(g_hwndLV);
  2925.     LVAddColumn(g_hwndLV, 0, "", 0);
  2926.  
  2927.     if (ptv == NULL)
  2928.     {
  2929.         TV_ITEM tvi;
  2930.         // get lParam of current tree node
  2931.         tvi.hItem  = TreeView_GetSelection(g_hwndTV);
  2932.         tvi.mask   = TVIF_PARAM;
  2933.         tvi.lParam = 0;
  2934.         TreeView_GetItem(g_hwndTV, &tvi);
  2935.         pni = (NODEINFO*)tvi.lParam;
  2936.     }
  2937.     else
  2938.     {
  2939.         pni = (NODEINFO*)ptv->itemNew.lParam;
  2940.     }
  2941.  
  2942.     if (pni && pni->Callback)
  2943.     {
  2944.         pni->Callback(pni->lParam1, pni->lParam2);
  2945.     }
  2946.  
  2947.     SendMessage(g_hwndLV, WM_SETREDRAW, TRUE, 0);
  2948.     InvalidateRect(g_hwndLV, NULL, TRUE);
  2949. }
  2950.  
  2951. //================================================================
  2952. //================================================================
  2953. void DXView_OnListViewDblClick(HWND hwndLV, NM_LISTVIEW *plv)
  2954. {
  2955.     LV_ITEM lvi;
  2956.  
  2957.     lvi.mask   = LVIF_PARAM;
  2958.     lvi.lParam = 0;
  2959.     lvi.iItem  = plv->iItem;
  2960.     ListView_GetItem(hwndLV, &lvi);
  2961. }
  2962.  
  2963.  
  2964. //================================================================
  2965. //================================================================
  2966. void DXView_OnCommand(HWND hwnd, WPARAM wParam)
  2967. {
  2968.     HMENU hMenu;
  2969.     BOOL  fPrintAll;
  2970.  
  2971.     switch(LOWORD(wParam))
  2972.     {
  2973.         case IDM_VIEWAVAIL:
  2974.         case IDM_VIEWALL:
  2975.             hMenu = GetMenu(hwnd);
  2976.             CheckMenuItem(hMenu, g_dwViewState, MF_BYCOMMAND | MF_UNCHECKED);
  2977.             g_dwViewState = LOWORD(wParam);
  2978.             CheckMenuItem(hMenu, g_dwViewState, MF_BYCOMMAND | MF_CHECKED);
  2979.             DXView_OnTreeSelect(g_hwndTV, NULL);
  2980.             break;
  2981.  
  2982.         case IDM_PRINT:
  2983.         case IDM_PRINTALL:
  2984.             // Print all statistics or just current selection
  2985.             if (LOWORD(wParam) == IDM_PRINTALL)
  2986.                 fPrintAll = TRUE;
  2987.             else
  2988.                 fPrintAll = FALSE;
  2989.             // Print out statistics
  2990.             DXView_OnPrint (hwnd, g_hwndTV, fPrintAll);
  2991.             break;
  2992.  
  2993.         case IDM_PRINTTOFILE:
  2994.                 fPrintAll = TRUE;
  2995.                 g_PrintToFile = TRUE;
  2996.             // Print out statistics
  2997.             DXView_OnFile (hwnd, g_hwndTV, fPrintAll);
  2998.             break;
  2999.  
  3000.         case IDM_ABOUT:
  3001.             DialogBox(g_hInstance, "About", hwnd, (DLGPROC)About);
  3002.             break;
  3003.  
  3004.         case IDM_EXIT:
  3005.             PostMessage(hwnd, WM_CLOSE, 0, 0);
  3006.             break;
  3007.     }
  3008. }
  3009.  
  3010. //================================================================
  3011. //================================================================
  3012. void DXView_Cleanup()
  3013. {
  3014.     if (lp3D)
  3015.         IDirect3D2_Release(lp3D);
  3016.  
  3017.     if (lpDD)
  3018.         IDirectDraw_Release(lpDD);
  3019.  
  3020.     if (lpDS)
  3021.         IDirectSound_Release(lpDS);
  3022.  
  3023.     if (lpDSC)
  3024.         IDirectSoundCapture_Release(lpDSC);
  3025.  
  3026.     if (lpDP3A)
  3027.     {
  3028.         lpDP3A->lpVtbl->Release(lpDP3A);
  3029.         lpDP3A = NULL;
  3030.     }
  3031.  
  3032.     if(g_hImageList)
  3033.         ImageList_Destroy(g_hImageList);
  3034. }
  3035.  
  3036. //================================================================
  3037. //================================================================
  3038. BOOL DXView_InitImageList()
  3039. {
  3040.     int cxSmIcon;
  3041.     int cySmIcon;
  3042.     UINT Index;
  3043.     HICON hIcon;
  3044.  
  3045.     if (g_hImageList)
  3046.         return TRUE;
  3047.  
  3048.     cxSmIcon = GetSystemMetrics(SM_CXSMICON);
  3049.     cySmIcon = GetSystemMetrics(SM_CYSMICON);
  3050.  
  3051.     //  First, create the image list that is needed.
  3052.     if((g_hImageList = ImageList_Create(cxSmIcon, cySmIcon, TRUE, IDI_LASTIMAGE - IDI_FIRSTIMAGE, 10)) == NULL)
  3053.         return(FALSE);
  3054.  
  3055.     //
  3056.     //  Initialize the image list with all of the icons that we'll be using
  3057.     //  Once set, send its handle to all interested child windows.
  3058.     //
  3059.     for (Index = IDI_FIRSTIMAGE; Index <= IDI_LASTIMAGE; Index++)
  3060.     {
  3061.         hIcon = LoadImage(g_hInstance, MAKEINTRESOURCE(Index), IMAGE_ICON, cxSmIcon, cySmIcon, 0);
  3062.         ImageList_AddIcon(g_hImageList, hIcon);
  3063.         DestroyIcon(hIcon);
  3064.     }
  3065.  
  3066.     TreeView_SetImageList(g_hwndTV, g_hImageList, TVSIL_NORMAL);
  3067.  
  3068.     return(TRUE);
  3069. }
  3070.  
  3071. //================================================================
  3072. //================================================================
  3073. HRESULT CALLBACK DDEnumCallBack(GUID *pid, LPSTR lpDriverDesc, LPSTR lpDriverName, LPVOID lpContext)
  3074. {
  3075.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3076.     TCHAR szText[256];
  3077.  
  3078.     if (HIWORD(pid) != 0)
  3079.     {
  3080.         GUID temp = *pid;
  3081.         pid = (GUID *)LocalAlloc(LPTR, sizeof(GUID));
  3082.         *pid = temp;
  3083.     }
  3084.  
  3085.     // Add subnode to treeview
  3086.     if (lpDriverName && *lpDriverName)
  3087.         wsprintf(szText, "%s (%s)", lpDriverDesc, lpDriverName);
  3088.     else
  3089.         lstrcpy(szText, lpDriverDesc);
  3090.  
  3091.     DDCapDefs[0].szName = szText;
  3092.     AddCapsToTV(hParent, DDCapDefs, (LPARAM)pid);
  3093.  
  3094.     return(DDENUMRET_OK);
  3095. }
  3096.  
  3097. //================================================================
  3098. //================================================================
  3099. HRESULT CALLBACK DSEnumCallBack(const GUID *lpGUID, LPCSTR lpDriverDesc, LPCSTR lpDriverName, LPVOID lpContext)
  3100. {
  3101.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3102.     TCHAR     szText[256];
  3103.     LPGUID    lpTemp = NULL;
  3104.  
  3105.     if( lpGUID != NULL )
  3106.         {
  3107.         if(( lpTemp = LocalAlloc( LPTR, sizeof(GUID))) == NULL )
  3108.         return( TRUE );
  3109.  
  3110.         memcpy( lpTemp, lpGUID, sizeof(GUID));
  3111.     }
  3112.  
  3113.     // Add subnode to treeview
  3114.     if (lpDriverName && *lpDriverName)
  3115.         wsprintf(szText, "%s (%s)", lpDriverDesc, lpDriverName);
  3116.     else
  3117.         lstrcpy(szText, lpDriverDesc);
  3118.  
  3119.     DSCapDefs[0].szName = szText;
  3120.     AddCapsToTV(hParent, DSCapDefs, (LPARAM)lpTemp);
  3121.  
  3122.     return(DDENUMRET_OK);
  3123. }
  3124.  
  3125. //================================================================
  3126. //================================================================
  3127. HRESULT CALLBACK DSCEnumCallBack(const GUID *lpGUID, LPCSTR lpDriverDesc, LPCSTR lpDriverName, LPVOID lpContext)
  3128. {
  3129.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3130.     TCHAR     szText[256];
  3131.     LPGUID    lpTemp = NULL;
  3132.  
  3133.     if( lpGUID != NULL )
  3134.     {
  3135.         if(( lpTemp = LocalAlloc( LPTR, sizeof(GUID))) == NULL )
  3136.         return( TRUE );
  3137.  
  3138.         memcpy( lpTemp, lpGUID, sizeof(GUID));
  3139.     }
  3140.  
  3141.     // Add subnode to treeview
  3142.     if (lpDriverName && *lpDriverName)
  3143.         wsprintf(szText, "%s (%s)", lpDriverDesc, lpDriverName);
  3144.     else
  3145.         lstrcpy(szText, lpDriverDesc);
  3146.  
  3147.     DSCCapDefs[0].szName = szText;
  3148.     AddCapsToTV(hParent, DSCCapDefs, (LPARAM)lpTemp);
  3149.  
  3150.     return(DDENUMRET_OK);
  3151. }
  3152.  
  3153. //================================================================
  3154. //================================================================
  3155. BOOL CALLBACK DPEnumCallback(GUID *pid, LPSTR szName, DWORD major_ver, DWORD minor_ver, LPVOID lpContext)
  3156. {
  3157.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3158.     TCHAR szText[256];
  3159.  
  3160.     if (HIWORD(pid) != 0)
  3161.     {
  3162.         GUID temp = *pid;
  3163.         pid = (GUID *)LocalAlloc(LPTR, sizeof(GUID));
  3164.         *pid = temp;
  3165.     }
  3166.  
  3167.     wsprintf(szText, "%s %d.%d", szName, major_ver, minor_ver);
  3168.  
  3169.     DPCapDefs[0].szName = szText;
  3170.     AddCapsToTV(hParent, DPCapDefs, (LPARAM)pid);
  3171.  
  3172.     return TRUE;
  3173. }
  3174.  
  3175. //================================================================
  3176. //================================================================
  3177. HRESULT CALLBACK D3EnumCallback(
  3178.             LPGUID pid,
  3179.             LPSTR lpDriverDesc,
  3180.             LPSTR lpDriverName, 
  3181.             LPD3DDEVICEDESC lpD3DDeviceDesc1, 
  3182.             LPD3DDEVICEDESC lpD3DDeviceDesc2, 
  3183.             LPVOID lpContext)
  3184. {
  3185.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3186.     TCHAR szText[256];
  3187.  
  3188.     //Store this info now is much easier than recreating it later.
  3189.     CAP3DDEVICEDESC *temp;
  3190.     if(lpD3DDeviceDesc1->dwFlags != 0)
  3191.     {
  3192.         temp = LocalAlloc(LPTR, sizeof(CAP3DDEVICEDESC));
  3193.         memcpy(temp,lpD3DDeviceDesc1,sizeof(CAP3DDEVICEDESC));
  3194.     }else
  3195.     {
  3196.         temp = LocalAlloc(LPTR, sizeof(CAP3DDEVICEDESC));
  3197.         memcpy(temp,lpD3DDeviceDesc2,sizeof(CAP3DDEVICEDESC));
  3198.     }
  3199.     temp->device = ddid;
  3200.     memcpy(&temp->driver,pid,sizeof(GUID));
  3201.  
  3202.     // Add subnode to treeview
  3203.     if (lpDriverName && *lpDriverName)
  3204.         wsprintf(szText, "%s (%s)", lpDriverDesc, lpDriverName);
  3205.     else
  3206.         lstrcpy(szText, lpDriverDesc);
  3207.  
  3208.     D3CapDefs[0].szName = szText;
  3209.     AddCapsToTV(hParent, D3CapDefs, (LPARAM)temp);
  3210.  
  3211.     return(DDENUMRET_OK);
  3212. }
  3213.  
  3214. HRESULT CALLBACK DDEnumCallBack3D(GUID *pid, LPSTR lpDriverDesc, LPSTR lpDriverName, LPVOID lpContext)
  3215. {
  3216.     HTREEITEM hParent = (HTREEITEM)lpContext;
  3217.     HTREEITEM hTree;
  3218.     TCHAR szText[256];
  3219.  
  3220.     if (HIWORD(pid) != 0)
  3221.     {
  3222.         GUID temp = *pid;
  3223.         pid = (GUID *)LocalAlloc(LPTR, sizeof(GUID));
  3224.         *pid = temp;
  3225.     }
  3226.  
  3227.     // Add subnode to treeview
  3228.     if (lpDriverName && *lpDriverName)
  3229.         wsprintf(szText, "%s (%s)", lpDriverDesc, lpDriverName);
  3230.     else
  3231.         lstrcpy(szText, lpDriverDesc);
  3232.  
  3233.     hTree = TVAddNode(hParent,szText,TRUE,IDI_CAPS, NULL, 0, 0, NULL);
  3234.     
  3235.     if (DDCreate(pid) && lp3D)
  3236.     {
  3237.         IDirect3D2_EnumDevices(lp3D, D3EnumCallback, hTree);
  3238.     }
  3239.  
  3240.     return(DDENUMRET_OK);
  3241. }
  3242.  
  3243. //================================================================
  3244. //================================================================
  3245. void DXView_FillTree(HWND hwndTV)
  3246. {
  3247.     HTREEITEM   hTree, hTreeSubNode;
  3248.  
  3249.     PFN_DSENUMERATE pfn_DSEnumerate;
  3250.     PFN_DSCENUMERATE pfn_DSCEnumerate;
  3251.  
  3252.     // Add direct draw devices
  3253.  
  3254.     hTree = TVAddNode(TVI_ROOT, "DirectDraw Devices", TRUE,
  3255.                       IDI_DIRECTX, NULL, 0, 0, NULL);
  3256.  
  3257.     // Add Display Driver node(s) and capability nodes to treeview
  3258.     DirectDrawEnumerate(DDEnumCallBack, hTree);
  3259.  
  3260.     // Add Hardware Emulation Layer node to treeview
  3261.     DDEnumCallBack((GUID *)DDCREATE_EMULATIONONLY, "Hardware Emulation Layer", NULL, (LPVOID)hTree);
  3262.  
  3263.     TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3264.     TreeView_SelectItem(g_hwndTV, hTree);
  3265.  
  3266.     // Add direct 3D devices
  3267.     hTree = TVAddNode(TVI_ROOT, "Direct3D Devices", TRUE,
  3268.                       IDI_DIRECTX, NULL, 0, 0, NULL);
  3269.     DirectDrawEnumerate(DDEnumCallBack3D, hTree);
  3270.  
  3271.     TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3272.  
  3273.     pfn_DSEnumerate = (PFN_DSENUMERATE)GetProcAddress(g_hDSoundLib, "DirectSoundEnumerateA");
  3274.     if (pfn_DSEnumerate == NULL)
  3275.     {
  3276.         MessageBox(g_hwndMain, "DSOUND.DLL does not implement DirectSoundEnumerate()", g_szAppName, MB_OK);
  3277.     }
  3278.     else
  3279.     {
  3280.         // Add direct sound devices
  3281.         hTree = TVAddNode(TVI_ROOT, "DirectSound Devices", TRUE,
  3282.                                           IDI_DIRECTX, NULL, 0, 0, NULL);
  3283.  
  3284.         (*pfn_DSEnumerate)(DSEnumCallBack, hTree);
  3285.  
  3286.         TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3287.     }
  3288.  
  3289.  
  3290.     // Get a pointer to the DirectSoundCaptureEnumerate
  3291.     pfn_DSCEnumerate = (PFN_DSCENUMERATE)GetProcAddress(g_hDSoundLib, "DirectSoundCaptureEnumerateA");
  3292.     if (pfn_DSCEnumerate == NULL)
  3293.     {
  3294.         MessageBox(g_hwndMain, "DSOUND.DLL does not implement DirectSoundCaptureEnumerate(). The system may not have DirectX 5.0 installed.", g_szAppName, MB_OK);
  3295.     }
  3296.     else
  3297.     {
  3298.         // Add direct sound capture devices
  3299.         hTree = TVAddNode(TVI_ROOT, "DirectSoundCapture Devices", TRUE,
  3300.                                                     IDI_DIRECTX, NULL, 0, 0, NULL);
  3301.         (*pfn_DSCEnumerate)(DSCEnumCallBack, hTree);
  3302.         TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3303.     }
  3304.  
  3305.     // Add direct play devices
  3306.  
  3307.     hTree = TVAddNode(TVI_ROOT, "DirectPlay Devices", TRUE,
  3308.                       IDI_DIRECTX, NULL, 0, 0, NULL);
  3309.  
  3310.     hTreeSubNode = TVAddNode(hTree, "Connections", TRUE,
  3311.                       IDI_CAPS, NULL, 0, 0, NULL);
  3312.     TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3313.  
  3314.     DirectPlayEnumerate(DPEnumCallback, hTreeSubNode);
  3315.     TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3316.  
  3317.     AddCapsToTV(hTree, DPLocalAppsDef, 0);
  3318.     TreeView_Expand(g_hwndTV, hTree, TVE_EXPAND);
  3319.  
  3320.     //
  3321.     //  DirectInput goo is in dinput.c
  3322.     //
  3323.     DI_FillTree();
  3324. }
  3325.  
  3326. //================================================================
  3327. //  About - process about box
  3328. //================================================================
  3329. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  3330. {
  3331.     switch(message)
  3332.     {
  3333.         case WM_INITDIALOG:
  3334.             return(TRUE);
  3335.  
  3336.         case WM_COMMAND:                      // message: received a command
  3337.             if(LOWORD(wParam) == IDOK        // "OK" box selected?
  3338.             || LOWORD(wParam) == IDCANCEL) {  // System menu close command?
  3339.                 EndDialog(hDlg, TRUE);        // Exit the dialog
  3340.                 return(TRUE);
  3341.             }
  3342.             break;
  3343.     }
  3344.     return(FALSE); // Didn't process the message
  3345. }
  3346.  
  3347. //================================================================
  3348. //================================================================
  3349. //  DXView_OnSize
  3350. //
  3351. //  DESCRIPTION:
  3352. //     Called whenever the size of the app window has changed or the size
  3353. //     of its child controls should be adjusted.
  3354. //
  3355. //  PARAMETERS:
  3356. //     hWnd, handle of app window.
  3357. //
  3358. //================================================================
  3359. //================================================================
  3360. void DXView_OnSize(HWND hWnd)
  3361. {
  3362.     HDWP hDWP;
  3363.     RECT ClientRect;
  3364.     int Height;
  3365.     HWND hKeyTreeWnd;
  3366.     HWND hValueListWnd;
  3367.     int x;
  3368.     int dx;
  3369.  
  3370.     if (IsIconic(hWnd))
  3371.         return;
  3372.  
  3373.     if ((hDWP = BeginDeferWindowPos(2)) != NULL)
  3374.     {
  3375.         //  Data structure used when calling GetEffectiveClientRect (which takes into
  3376.         //  account space taken up by the toolbars/status bars).  First half of the
  3377.         //  pair is zero when at the end of the list, second half is the control id.
  3378.         int s_EffectiveClientRectData[] = {
  3379.             1, 0,                               //  For the menu bar, but is unused
  3380.             0, 0                                //  First zero marks end of data
  3381.         };
  3382.  
  3383.         GetEffectiveClientRect(hWnd, &ClientRect, s_EffectiveClientRectData);
  3384.         Height = ClientRect.bottom - ClientRect.top;
  3385.  
  3386.         hKeyTreeWnd = g_hwndTV;
  3387.  
  3388.         DeferWindowPos(hDWP, hKeyTreeWnd, NULL, 0, ClientRect.top, g_xPaneSplit,
  3389.             Height, SWP_NOZORDER | SWP_NOACTIVATE);
  3390.  
  3391.         x = g_xPaneSplit + GetSystemMetrics(SM_CXSIZEFRAME);
  3392.         dx = ClientRect.right - ClientRect.left - x;
  3393.  
  3394.         hValueListWnd = g_hwndLV;
  3395.  
  3396.         DeferWindowPos(hDWP, hValueListWnd, NULL, x, ClientRect.top, dx, Height,
  3397.             SWP_NOZORDER | SWP_NOACTIVATE);
  3398.  
  3399.         EndDeferWindowPos(hDWP);
  3400.     }
  3401. }
  3402. #ifdef _X86_
  3403. #pragma optimize("", off)
  3404. #endif
  3405. /*----------------------------------------------------------------------------*\
  3406. \*----------------------------------------------------------------------------*/
  3407.  
  3408. void LVAddColumn(HWND hwndLV, int i, char *name, int width)
  3409. {
  3410.     LV_COLUMN col;
  3411.  
  3412.     if (i == 0)
  3413.     {
  3414.         while(ListView_DeleteColumn(hwndLV, 0))
  3415.             ;
  3416.     }
  3417.  
  3418.     col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  3419.     col.fmt  = LVCFMT_LEFT;
  3420.     col.pszText = name;
  3421.     col.cchTextMax = 0;
  3422.     col.cx = width * g_tmAveCharWidth;
  3423.     col.iSubItem = 0;
  3424.     ListView_InsertColumn(hwndLV, i, &col);
  3425. }
  3426.  
  3427. /*----------------------------------------------------------------------------*\
  3428. \*----------------------------------------------------------------------------*/
  3429. int LVAddText(HWND hwndLV, int col, const char *sz, ...)
  3430. {
  3431.     LV_ITEM lvi;
  3432.     char    ach[80];
  3433.     va_list vl;
  3434.  
  3435.     va_start(vl, sz );
  3436.     wvsprintf(ach,sz, vl);
  3437.  
  3438.     lvi.mask        = LVIF_TEXT;
  3439.     lvi.iSubItem    = 0;
  3440.     lvi.state       = 0;
  3441.     lvi.stateMask   = 0;
  3442.     lvi.pszText     = ach;
  3443.     lvi.cchTextMax  = 0;
  3444.     lvi.iImage      = 0;
  3445.     lvi.lParam      = 0;
  3446.  
  3447.     if (col == 0)
  3448.     {
  3449.             lvi.iItem    = 0x7FFF;
  3450.             lvi.iSubItem = 0;
  3451.         return ListView_InsertItem(hwndLV, &lvi);
  3452.     }
  3453.     else
  3454.     {
  3455.         lvi.iItem    = ListView_GetItemCount(hwndLV)-1;
  3456.         lvi.iSubItem = col;
  3457.         return ListView_SetItem(hwndLV, &lvi);
  3458.     }
  3459.     va_end(vl);
  3460. }
  3461.  
  3462. /*----------------------------------------------------------------------------*\
  3463. \*----------------------------------------------------------------------------*/
  3464. void LVDeleteAllItems( HWND hwndLV )
  3465. {
  3466.  
  3467.     //Used by DPLay asynchronous enum sessions
  3468.     if (g_idTimer)
  3469.     {
  3470.  
  3471.         BOOL    bDataAvailable;
  3472.         LPLV_INSTANCEGUIDSTRUCT    lpInstGuidStruct = NULL;
  3473.         LV_ITEM    lvi;
  3474.         int        i, count;
  3475.  
  3476.         KillTimer(g_hwndMain, g_idTimer ); 
  3477.         g_idTimer = 0;
  3478.  
  3479.         memset( &lvi, 0, sizeof( LV_ITEM ));
  3480.  
  3481.         count    = ListView_GetItemCount( g_hwndLV );
  3482.  
  3483.         for ( i = 0; i < count; i++ )
  3484.         {
  3485.             lvi.iItem = i;
  3486.             lvi.mask = LVIF_PARAM;
  3487.             lvi.lParam = 0;
  3488.  
  3489.             bDataAvailable =ListView_GetItem( g_hwndLV, &lvi );
  3490.             
  3491.             if ((bDataAvailable) && (lvi.lParam))
  3492.                 LocalFree( (LPVOID) lvi.lParam );
  3493.  
  3494.         }
  3495.  
  3496.     }
  3497.  
  3498.     ListView_DeleteAllItems( hwndLV );
  3499. }
  3500.  
  3501. /*----------------------------------------------------------------------------*\
  3502. \*----------------------------------------------------------------------------*/
  3503. HTREEITEM TVAddNode(
  3504.     HTREEITEM       hParent, 
  3505.     LPSTR           szText, 
  3506.     BOOL            fKids, 
  3507.     int             iImage, 
  3508.     SELCALLBACK     Callback, 
  3509.     LPARAM          lParam1, 
  3510.     LPARAM          lParam2,
  3511.     PRINTCALLBACK   printCallback)
  3512. {
  3513.     TV_INSERTSTRUCT tvi;
  3514.     NODEINFO *pni;
  3515.  
  3516.     pni = (NODEINFO *)LocalAlloc(LPTR, sizeof(NODEINFO));
  3517.  
  3518.     if (pni == NULL)
  3519.         return NULL;
  3520.  
  3521.     pni->lParam1        = lParam1;
  3522.     pni->lParam2        = lParam2;
  3523.     pni->Callback       = Callback;
  3524.     pni->printCallback  = printCallback;
  3525.  
  3526.     // Add Node to treeview
  3527.     tvi.hParent             = hParent;
  3528.     tvi.hInsertAfter        = TVI_LAST;
  3529.     tvi.item.mask           = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_CHILDREN;
  3530.     tvi.item.iImage         = iImage - IDI_FIRSTIMAGE;
  3531.     tvi.item.iSelectedImage = iImage - IDI_FIRSTIMAGE;
  3532.     tvi.item.lParam         = (LPARAM)pni;
  3533.     tvi.item.cChildren      = fKids;
  3534.     tvi.item.pszText        = szText;
  3535.  
  3536.     return TreeView_InsertItem(g_hwndTV, &tvi);
  3537. }
  3538.  
  3539.  
  3540. /*----------------------------------------------------------------------------*\
  3541. \*----------------------------------------------------------------------------*/
  3542. HRESULT EnumSessions( LPDIRECTPLAY3A lpDP3A )
  3543. {
  3544.  
  3545.     DPSESSIONDESC2   dps;
  3546.     HRESULT            hr = DPERR_GENERIC;
  3547.  
  3548.  
  3549.     if (lpDP3A)
  3550.     {
  3551.         memset(&dps, 0, sizeof(dps));
  3552.         dps.dwSize = sizeof(dps);
  3553.  
  3554.         ResetListViewRefresh( g_hwndLV );
  3555.  
  3556.         hr = lpDP3A->lpVtbl->EnumSessions(    lpDP3A, &dps, 0, EnumSessionsCallback, 
  3557.                                             NULL, 
  3558.                                             DPENUMSESSIONS_ALL|
  3559.                                             DPENUMSESSIONS_PASSWORDREQUIRED|
  3560.                                             DPENUMSESSIONS_ASYNC);
  3561.         RemoveStaleSessions();
  3562.     }
  3563.  
  3564.     return hr;
  3565. }
  3566.  
  3567.  
  3568. /*----------------------------------------------------------------------------*\
  3569. \*----------------------------------------------------------------------------*/
  3570. void FreeLocalAppList()
  3571. {
  3572.     LOCALAPP * lpTemp;
  3573.  
  3574.     while( g_lpLocalApp )
  3575.     {
  3576.         lpTemp = (LPLOCALAPP) g_lpLocalApp->lpNext;
  3577.         LocalFree( g_lpLocalApp );
  3578.         g_lpLocalApp = lpTemp;
  3579.     }
  3580. }
  3581.  
  3582. /*----------------------------------------------------------------------------*\
  3583. \*----------------------------------------------------------------------------*/
  3584. void GetAppName(LPSTR szNameBuffer, LPCGUID lpguidApplication, DWORD dwBufferSize)
  3585. {
  3586.     LPLOCALAPP    lpTemp = g_lpLocalApp;
  3587.     WCHAR        wszBuffer[128];
  3588.  
  3589.     while (lpTemp)
  3590.     {
  3591.         if (IsEqualGUID( &(lpTemp->guidApplication), lpguidApplication ))
  3592.         {
  3593.             strncpy( szNameBuffer, lpTemp->szAppNameA, dwBufferSize ); 
  3594.             return;
  3595.         }
  3596.         else
  3597.         {
  3598.             lpTemp = (LPLOCALAPP)lpTemp->lpNext;
  3599.         }
  3600.     }
  3601.  
  3602.     //If we ended up here, the GUID doesn't match anything we have installed locally.
  3603.     if (StringFromGUID2( lpguidApplication, wszBuffer, 128 ))
  3604.     {
  3605.         wcstombs(szNameBuffer, wszBuffer, wcslen(wszBuffer)+1);
  3606.     }
  3607.  
  3608. }
  3609.  
  3610. /*----------------------------------------------------------------------------*\
  3611. \*----------------------------------------------------------------------------*/
  3612. void RemoveStaleSessions()
  3613. {
  3614.     BOOL bDataAvailable;
  3615.     int i        = 0,
  3616.         count    = ListView_GetItemCount( g_hwndLV );
  3617.  
  3618.     LPLV_INSTANCEGUIDSTRUCT    lpInstGuidStruct = NULL;
  3619.     LV_ITEM    lvi;
  3620.  
  3621.     memset( &lvi, 0, sizeof(LV_ITEM) );
  3622.  
  3623.     while( i < count)
  3624.     {
  3625.         lvi.iItem = i;
  3626.         lvi.mask = LVIF_PARAM;
  3627.         lvi.lParam = 0;
  3628.  
  3629.         bDataAvailable =ListView_GetItem( g_hwndLV, &lvi );
  3630.         
  3631.         if (bDataAvailable)
  3632.         {
  3633.             lpInstGuidStruct = (LPLV_INSTANCEGUIDSTRUCT) lvi.lParam;
  3634.             if (lpInstGuidStruct)
  3635.             {
  3636.                 if (FALSE == lpInstGuidStruct->dwRefresh)
  3637.                 {
  3638.                     LocalFree( lpInstGuidStruct );
  3639.                     ListView_DeleteItem( g_hwndLV, i);
  3640.                 }
  3641.             }
  3642.         }
  3643.         else
  3644.         {
  3645.             //This item has no data, so it must be invalid.
  3646.             ListView_DeleteItem( g_hwndLV, i);
  3647.         }
  3648.  
  3649.         i++;
  3650.     }
  3651.  
  3652. }
  3653.  
  3654. /*----------------------------------------------------------------------------*\
  3655. \*----------------------------------------------------------------------------*/
  3656. void ResetListViewRefresh( HWND hwndLV )
  3657. {
  3658.     BOOL bDataAvailable;
  3659.     int i        = 0,
  3660.         count    = ListView_GetItemCount( hwndLV );
  3661.  
  3662.     LPLV_INSTANCEGUIDSTRUCT    lpInstGuidStruct = NULL;
  3663.     LV_ITEM    lvi;
  3664.  
  3665.     memset( &lvi, 0, sizeof(LV_ITEM) );
  3666.  
  3667.     while( i < count)
  3668.     {
  3669.         lvi.iItem = i;
  3670.         lvi.mask = LVIF_PARAM;
  3671.         lvi.lParam = 0;
  3672.  
  3673.         bDataAvailable =ListView_GetItem( hwndLV, &lvi );
  3674.         
  3675.         if (bDataAvailable)
  3676.         {
  3677.             lpInstGuidStruct = (LPLV_INSTANCEGUIDSTRUCT) lvi.lParam;
  3678.             
  3679.             if (lpInstGuidStruct)
  3680.             {
  3681.                     //Mark this session to be deleted next time if it does not
  3682.                     //respond to this enum request.
  3683.                     lpInstGuidStruct->dwRefresh = FALSE;
  3684.             }
  3685.         }
  3686.         else
  3687.         {
  3688.             //This item has no data, so it must be invalid.
  3689.             ListView_DeleteItem( hwndLV, i);
  3690.         }
  3691.  
  3692.         i++;
  3693.     }
  3694.  
  3695. }
  3696.  
  3697.  
  3698. #ifdef _X86_
  3699. #pragma optimize("", on)
  3700. #endif
  3701.