2020-06-27 09:47:05 +03:00
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
// Name: dxview.cpp
2020-06-27 09:47:05 +03:00
//
2020-06-29 01:43:46 +03:00
// Desc: DirectX Capabilities Viewer (Main program)
2020-06-27 09:47:05 +03:00
//
2022-02-16 22:32:59 +03:00
// Copyright(c) Microsoft Corporation.
2020-07-28 22:53:20 +03:00
// Licensed under the MIT License.
//
// https://go.microsoft.com/fwlink/?linkid=2136896
2020-06-27 09:47:05 +03:00
//-----------------------------------------------------------------------------
# include "dxview.h"
2020-06-29 01:43:46 +03:00
2020-06-27 09:47:05 +03:00
# include <objbase.h>
# include <stdio.h>
# include <strsafe.h>
# include <shlwapi.h>
2020-06-29 01:43:46 +03:00
// These are from d3d8types.h
# define D3DSHADER_VERSION_MAJOR(_Version) (((_Version)>>8)&0xFF)
# define D3DSHADER_VERSION_MINOR(_Version) (((_Version)>>0)&0xFF)
2020-06-27 09:47:05 +03:00
2022-08-01 23:59:11 +03:00
constexpr size_t c_maxPasteBuffer = 200 ;
2022-08-02 00:38:02 +03:00
constexpr size_t c_maxPrintLine = 128 ;
constexpr int c_tabStop = 52 ;
2022-08-01 23:59:11 +03:00
2022-08-02 00:38:02 +03:00
static_assert ( c_tabStop > = c_DefNameLength , " print stop should be at least as long as the default name " ) ;
2022-08-01 23:59:11 +03:00
HINSTANCE g_hInstance = nullptr ;
HWND g_hwndMain = nullptr ;
2020-06-27 09:47:05 +03:00
CHAR g_strAppName [ ] = " DXView " ;
CHAR g_strClassName [ ] = " DXView " ;
CHAR g_strTitle [ ] = " DirectX Caps Viewer " ;
2020-06-29 01:43:46 +03:00
extern const char c_szYes [ ] = " Yes " ;
extern const char c_szNo [ ] = " No " ;
extern const char c_szCurrentMode [ ] = " Current Mode " ;
extern const char c_szNA [ ] = " n/a " ;
2022-08-01 23:59:11 +03:00
HWND g_hwndLV = nullptr ; // List view
HWND g_hwndTV = nullptr ; // Tree view
HIMAGELIST g_hImageList = nullptr ;
HFONT g_hFont = nullptr ;
2020-06-27 09:47:05 +03:00
int g_xPaneSplit ;
int g_xHalfSplitWidth ;
BOOL g_bSplitMove ;
DWORD g_dwViewState ;
2022-08-01 23:59:11 +03:00
DWORD g_dwView9Ex ;
2020-06-27 09:47:05 +03:00
DWORD g_tmAveCharWidth ;
extern BOOL g_PrintToFile ;
extern TCHAR g_PrintToFilePath [ MAX_PATH ] ;
2022-08-01 23:59:11 +03:00
CHAR g_szClip [ c_maxPasteBuffer ] ;
2020-06-29 01:43:46 +03:00
TCHAR g_helpPath [ MAX_PATH ] = { } ;
2020-06-27 09:47:05 +03:00
//-----------------------------------------------------------------------------
// Local function prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc ( HWND hwnd , UINT message , WPARAM wParam , LPARAM lParam ) ;
LRESULT CALLBACK About ( HWND hDlg , UINT message , WPARAM wParam , LPARAM lParam ) ;
BOOL DXView_OnCreate ( HWND hwnd ) ;
VOID DXView_OnCommand ( HWND hwnd , WPARAM wParam ) ;
VOID DXView_OnSize ( HWND hwnd ) ;
VOID DXView_OnTreeSelect ( HWND hwndTV , NM_TREEVIEW * ptv ) ;
VOID DXView_OnListViewDblClick ( HWND hwndLV , NM_LISTVIEW * plv ) ;
VOID DXView_Cleanup ( ) ;
BOOL DXView_InitImageList ( ) ;
BOOL DXView_OnPrint ( HWND hWindow , HWND hTreeView , BOOL bPrintAll ) ;
BOOL DXView_OnFile ( HWND hWindow , HWND hTreeWnd , BOOL bPrintAll ) ;
VOID CreateCopyMenu ( VOID ) ;
//-----------------------------------------------------------------------------
// External function prototypes
//-----------------------------------------------------------------------------
VOID DXGI_FillTree ( HWND hwndTV ) ;
VOID DXG_FillTree ( HWND hwndTV ) ;
VOID DD_FillTree ( HWND hwndTV ) ;
VOID DXGI_Init ( ) ;
VOID DXG_Init ( ) ;
VOID DD_Init ( ) ;
VOID DXGI_CleanUp ( ) ;
VOID DXG_CleanUp ( ) ;
VOID DD_CleanUp ( ) ;
BOOL DXG_Is9Ex ( ) ;
//-----------------------------------------------------------------------------
// Name: Int2Str()
// Desc: Get number as a string
//-----------------------------------------------------------------------------
HRESULT Int2Str ( _Out_z_cap_ ( nDestLen ) LPTSTR strDest , UINT nDestLen , DWORD i )
{
* strDest = 0 ;
2020-06-29 01:43:46 +03:00
char strDec [ 2 ] ;
2020-06-27 09:47:05 +03:00
GetLocaleInfo ( LOCALE_USER_DEFAULT , LOCALE_SDECIMAL , strDec , 2 ) ;
2020-06-29 01:43:46 +03:00
char strIn [ 32 ] ;
2020-06-27 09:47:05 +03:00
sprintf_s ( strIn , sizeof ( strIn ) , " %u " , i ) ;
2020-06-29 01:43:46 +03:00
char strOut [ 32 ] ;
if ( 0 = = GetNumberFormat ( LOCALE_USER_DEFAULT , 0 , strIn , nullptr , strOut , 32 ) )
2020-06-27 09:47:05 +03:00
{
strcpy_s ( strDest , nDestLen , strIn ) ;
return E_FAIL ;
}
2020-06-29 01:43:46 +03:00
char * pstrDec = strrchr ( strOut , strDec [ 0 ] ) ;
if ( pstrDec )
2020-06-27 09:47:05 +03:00
* pstrDec = ' \0 ' ;
2020-06-27 10:06:21 +03:00
if ( strcpy_s ( strDest , nDestLen , strOut ) ! = 0 )
2020-06-27 09:47:05 +03:00
{
* strDest = 0 ;
return E_FAIL ;
}
return S_OK ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
_Use_decl_annotations_
2020-06-27 09:47:05 +03:00
HRESULT PrintStringValueLine ( const char * szText , const char * szText2 , PRINTCBINFO * lpInfo )
{
// Calculate Name and Value column x offsets
2020-06-29 01:43:46 +03:00
int xName = ( lpInfo - > dwCurrIndent * DEF_TAB_SIZE * lpInfo - > dwCharWidth ) ;
2022-08-02 00:38:02 +03:00
int xVal = xName + ( c_tabStop * lpInfo - > dwCharWidth ) ;
2020-06-29 01:43:46 +03:00
int yLine = ( lpInfo - > dwCurrLine * lpInfo - > dwLineHeight ) ;
2020-06-27 09:47:05 +03:00
// Print name
2022-08-01 23:59:11 +03:00
char szBuff [ c_maxPrintLine ] ;
2020-06-27 09:47:05 +03:00
strcpy_s ( szBuff , sizeof ( szBuff ) , szText ) ;
2022-08-01 23:59:11 +03:00
szBuff [ c_maxPrintLine - 1 ] = ' \0 ' ;
2020-06-29 01:43:46 +03:00
auto cchLen = static_cast < DWORD > ( _tcslen ( szText ) ) ;
2020-06-27 09:47:05 +03:00
if ( FAILED ( PrintLine ( xName , yLine , szBuff , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value
strcpy_s ( szBuff , sizeof ( szBuff ) , szText2 ) ;
2022-08-01 23:59:11 +03:00
szBuff [ c_maxPrintLine - 1 ] = ' \0 ' ;
2020-06-29 01:43:46 +03:00
cchLen = static_cast < DWORD > ( _tcslen ( szText2 ) ) ;
2020-06-27 09:47:05 +03:00
if ( FAILED ( PrintLine ( xVal , yLine , szBuff , cchLen , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
return S_OK ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
_Use_decl_annotations_
2020-06-27 09:47:05 +03:00
HRESULT PrintValueLine ( const char * szText , DWORD dwValue , PRINTCBINFO * lpInfo )
{
2022-08-01 23:59:11 +03:00
char szBuff [ c_maxPrintLine ] ;
Int2Str ( szBuff , c_maxPrintLine , dwValue ) ;
2020-06-27 09:47:05 +03:00
return PrintStringValueLine ( szText , szBuff , lpInfo ) ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
_Use_decl_annotations_
2020-06-27 09:47:05 +03:00
HRESULT PrintHexValueLine ( const char * szText , DWORD dwValue , PRINTCBINFO * lpInfo )
{
2022-08-01 23:59:11 +03:00
char szBuff [ c_maxPrintLine ] ;
2020-06-27 09:47:05 +03:00
sprintf_s ( szBuff , sizeof ( szBuff ) , " 0x%08x " , dwValue ) ;
return PrintStringValueLine ( szText , szBuff , lpInfo ) ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
_Use_decl_annotations_
2020-06-27 09:47:05 +03:00
HRESULT PrintStringLine ( const char * szText , PRINTCBINFO * lpInfo )
{
// Calculate Name and Value column x offsets
2020-06-29 01:43:46 +03:00
int xName = ( lpInfo - > dwCurrIndent * DEF_TAB_SIZE * lpInfo - > dwCharWidth ) ;
int yLine = ( lpInfo - > dwCurrLine * lpInfo - > dwLineHeight ) ;
2020-06-27 09:47:05 +03:00
// Print name
2022-08-01 23:59:11 +03:00
char szBuff [ c_maxPrintLine ] ;
2020-06-27 09:47:05 +03:00
strcpy_s ( szBuff , sizeof ( szBuff ) , szText ) ;
2022-08-01 23:59:11 +03:00
szBuff [ c_maxPrintLine - 1 ] = ' \0 ' ;
2020-06-29 01:43:46 +03:00
auto cchLen = static_cast < DWORD > ( _tcslen ( szText ) ) ;
2020-06-27 09:47:05 +03:00
if ( FAILED ( PrintLine ( xName , yLine , szBuff , cchLen , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
return S_OK ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
// Name: WinMain
2020-06-27 09:47:05 +03:00
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
int WINAPI WinMain ( _In_ HINSTANCE hInstance , _In_opt_ HINSTANCE /*hPrevInstance*/ ,
_In_ LPSTR /*strCmdLine*/ , _In_ int /*nCmdShow*/ )
2020-06-27 09:47:05 +03:00
{
g_hInstance = hInstance ; // Store instance handle in our global variable
g_PrintToFilePath [ 0 ] = TEXT ( ' \0 ' ) ;
// Initialize COM
2020-06-29 01:43:46 +03:00
HRESULT hr = CoInitializeEx ( nullptr , COINITBASE_MULTITHREADED ) ;
if ( FAILED ( hr ) )
return 1 ;
2020-06-27 09:47:05 +03:00
// Init various DX components
DXGI_Init ( ) ;
DXG_Init ( ) ;
DD_Init ( ) ;
// Register window class
WNDCLASS wc ;
2020-06-29 01:43:46 +03:00
wc . style = CS_HREDRAW | CS_VREDRAW ; // Class style(s).
wc . lpfnWndProc = ( WNDPROC ) WndProc ; // Window Procedure
wc . cbClsExtra = 0 ; // No per-class extra data.
wc . cbWndExtra = 0 ; // No per-window extra data.
wc . hInstance = hInstance ; // Owner of this class
wc . hIcon = LoadIcon ( hInstance , MAKEINTRESOURCE ( IDI_DIRECTX ) ) ; // Icon name from .RC
wc . hCursor = LoadCursor ( hInstance , MAKEINTRESOURCE ( IDC_SPLIT ) ) ; // Cursor
wc . hbrBackground = ( HBRUSH ) ( COLOR_3DFACE + 1 ) ; // Default color
wc . lpszMenuName = " Menu " ; // Menu name from .RC
2020-06-27 09:47:05 +03:00
wc . lpszClassName = g_strClassName ; // Name to register as
2020-06-29 01:43:46 +03:00
RegisterClass ( & wc ) ;
2020-06-27 09:47:05 +03:00
// Create a main window for this application instance.
2020-06-29 01:43:46 +03:00
g_hwndMain = CreateWindowEx ( 0 , g_strClassName , g_strTitle , WS_OVERLAPPEDWINDOW ,
CW_USEDEFAULT , CW_USEDEFAULT , DXView_WIDTH , DXView_HEIGHT ,
nullptr , nullptr , hInstance , nullptr ) ;
2020-06-27 09:47:05 +03:00
// If window could not be created, return "failure"
2020-06-29 01:43:46 +03:00
if ( ! g_hwndMain )
2020-06-27 09:47:05 +03:00
{
CoUninitialize ( ) ;
return - 1 ;
}
TCHAR * pszCmdLine = GetCommandLine ( ) ;
// Skip past program name (first token in command line).
if ( * pszCmdLine = = TEXT ( ' " ' ) ) // Check for and handle quoted program name
{
pszCmdLine + + ;
// Scan, and skip over, subsequent characters until another
// double-quote or a null is encountered
while ( * pszCmdLine & & ( * pszCmdLine ! = TEXT ( ' " ' ) ) )
pszCmdLine + + ;
// If we stopped on a double-quote (usual case), skip over it.
2020-06-29 01:43:46 +03:00
if ( * pszCmdLine = = TEXT ( ' " ' ) )
pszCmdLine + + ;
2020-06-27 09:47:05 +03:00
}
else // First token wasn't a quote
{
while ( * pszCmdLine > TEXT ( ' ' ) )
pszCmdLine + + ;
}
// Skip past any white space preceeding the next token.
while ( * pszCmdLine & & ( * pszCmdLine < = TEXT ( ' ' ) ) )
pszCmdLine + + ;
// Treat the rest of the command line as a filename to save the whole tree to
TCHAR * pstrSave = g_PrintToFilePath ;
if ( * pszCmdLine = = TEXT ( ' " ' ) ) // Check for and handle quoted program name
{
pszCmdLine + + ;
// Scan, and copy, subsequent characters until another
// double-quote or a null is encountered
while ( * pszCmdLine & & ( * pszCmdLine ! = TEXT ( ' " ' ) ) )
* pstrSave + + = * pszCmdLine + + ;
// If we stopped on a double-quote (usual case), skip over it.
2020-06-29 01:43:46 +03:00
if ( * pszCmdLine = = TEXT ( ' " ' ) )
pszCmdLine + + ;
2020-06-27 09:47:05 +03:00
}
else // First token wasn't a quote
{
while ( * pszCmdLine > TEXT ( ' ' ) )
* pstrSave + + = * pszCmdLine + + ;
}
* pstrSave = TEXT ( ' \0 ' ) ;
2020-06-29 01:43:46 +03:00
if ( strlen ( g_PrintToFilePath ) > 0 )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
PostMessage ( g_hwndMain , WM_COMMAND , IDM_PRINTWHOLETREETOFILE , 0 ) ;
PostMessage ( g_hwndMain , WM_CLOSE , 0 , 0 ) ;
2020-06-27 09:47:05 +03:00
}
else
{
// Make the window visible; update its client area; and return "success"
2020-06-29 01:43:46 +03:00
ShowWindow ( g_hwndMain , SW_MAXIMIZE /*nCmdShow*/ ) ;
2020-06-27 09:47:05 +03:00
}
// Message pump
MSG msg ;
2020-06-29 01:43:46 +03:00
while ( GetMessage ( & msg , nullptr , 0 , 0 ) )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
2020-06-27 09:47:05 +03:00
}
CoUninitialize ( ) ;
return ( int ) msg . wParam ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
LRESULT CALLBACK WndProc ( HWND hWnd , UINT msg , WPARAM wParam , LPARAM lParam )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
switch ( msg )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
case WM_CREATE :
return DXView_OnCreate ( hWnd ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_SIZE :
DXView_OnSize ( hWnd ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_LBUTTONDOWN :
g_bSplitMove = TRUE ;
SetCapture ( hWnd ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_LBUTTONUP :
g_bSplitMove = FALSE ;
ReleaseCapture ( ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_MOUSEMOVE :
if ( g_bSplitMove )
{
RECT rect ;
// change the value from unsigned to signed
int x = ( int ) ( short ) LOWORD ( lParam ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
GetClientRect ( hWnd , & rect ) ;
if ( rect . left > x )
{
x = rect . left ;
2020-06-27 09:47:05 +03:00
}
2020-06-29 01:43:46 +03:00
else if ( rect . right < x )
{
x = rect . right ;
}
g_xPaneSplit = ( x - g_xHalfSplitWidth ) ;
DXView_OnSize ( hWnd ) ;
}
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_NOTIFY :
if ( ( ( NMHDR * ) lParam ) - > hwndFrom = = g_hwndTV )
{
if ( ( ( NMHDR * ) lParam ) - > code = = TVN_SELCHANGED )
DXView_OnTreeSelect ( g_hwndTV , ( NM_TREEVIEW * ) lParam ) ;
else if ( ( ( NMHDR * ) lParam ) - > code = = NM_RCLICK )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
NMHDR * pnmhdr = ( NMHDR * ) lParam ;
TVHITTESTINFO info ;
GetCursorPos ( & info . pt ) ;
ScreenToClient ( pnmhdr - > hwndFrom , & info . pt ) ;
TreeView_HitTest ( pnmhdr - > hwndFrom , & info ) ;
if ( info . flags & TVHT_ONITEMLABEL )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
TVITEM tvitem ;
tvitem . mask = TVIF_TEXT ;
tvitem . hItem = info . hItem ;
tvitem . pszText = g_szClip ;
2022-08-01 23:59:11 +03:00
tvitem . cchTextMax = c_maxPasteBuffer ;
2020-06-29 01:43:46 +03:00
TreeView_GetItem ( g_hwndTV , & tvitem ) ;
CreateCopyMenu ( ) ;
2020-06-27 09:47:05 +03:00
}
}
2020-06-29 01:43:46 +03:00
else if ( ( ( NMHDR * ) lParam ) - > code = = TVN_KEYDOWN )
{
NMTVKEYDOWN * ptvkd = ( LPNMTVKEYDOWN ) lParam ;
if ( ptvkd - > wVKey = = VK_TAB )
SetFocus ( g_hwndLV ) ;
}
}
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
if ( ( ( NMHDR * ) lParam ) - > hwndFrom = = g_hwndLV )
{
if ( ( ( NMHDR * ) lParam ) - > code = = NM_RDBLCLK )
DXView_OnListViewDblClick ( g_hwndLV , ( NM_LISTVIEW * ) lParam ) ;
else if ( ( ( NMHDR * ) lParam ) - > code = = NM_RCLICK )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
NMHDR * pnmhdr = ( NMHDR * ) lParam ;
LVHITTESTINFO info ;
GetCursorPos ( & info . pt ) ;
ScreenToClient ( pnmhdr - > hwndFrom , & info . pt ) ;
ListView_SubItemHitTest ( pnmhdr - > hwndFrom , & info ) ;
if ( info . iItem > = 0 )
2020-06-27 09:47:05 +03:00
{
2022-08-01 23:59:11 +03:00
ListView_GetItemText ( g_hwndLV , info . iItem , info . iSubItem , g_szClip , c_maxPasteBuffer ) ;
2020-06-29 01:43:46 +03:00
CreateCopyMenu ( ) ;
2020-06-27 09:47:05 +03:00
}
}
2020-06-29 01:43:46 +03:00
else if ( ( ( NMHDR * ) lParam ) - > code = = LVN_KEYDOWN )
{
NMLVKEYDOWN * plvkd = ( LPNMLVKEYDOWN ) lParam ;
if ( plvkd - > wVKey = = VK_TAB )
SetFocus ( g_hwndTV ) ;
}
}
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_SETFOCUS :
SetFocus ( g_hwndTV ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_COMMAND : // message: command from application menu
DXView_OnCommand ( hWnd , wParam ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_CLOSE :
DestroyWindow ( hWnd ) ;
return 0 ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_DESTROY : // message: window being destroyed
DXView_Cleanup ( ) ; // Free per item struct for all items
PostQuitMessage ( 0 ) ;
break ;
2020-06-27 09:47:05 +03:00
}
2020-06-29 01:43:46 +03:00
return DefWindowProc ( hWnd , msg , wParam , lParam ) ;
2020-06-27 09:47:05 +03:00
}
//-----------------------------------------------------------------------------
VOID CreateCopyMenu ( VOID )
{
2020-06-29 01:43:46 +03:00
HMENU hPopupMenu = LoadMenu ( nullptr , " POPUP " ) ;
if ( ! hPopupMenu )
2020-06-27 09:47:05 +03:00
return ;
2020-06-29 01:43:46 +03:00
HMENU hMenu = GetSubMenu ( hPopupMenu , 0 ) ;
if ( ! hMenu )
2020-06-27 09:47:05 +03:00
{
DestroyMenu ( hPopupMenu ) ;
return ;
}
2022-08-01 23:59:11 +03:00
TCHAR szMenu [ c_maxPasteBuffer ] ;
GetMenuString ( hMenu , IDM_COPY , szMenu , c_maxPasteBuffer , MF_BYCOMMAND ) ;
2020-06-29 01:43:46 +03:00
2022-08-01 23:59:11 +03:00
TCHAR szMenuNew [ c_maxPasteBuffer ] ;
2020-06-27 09:47:05 +03:00
sprintf_s ( szMenuNew , sizeof ( szMenuNew ) , szMenu , g_szClip ) ;
2020-06-29 01:43:46 +03:00
MENUITEMINFO mii = { } ;
2020-06-27 09:47:05 +03:00
mii . cbSize = sizeof ( mii ) ;
mii . fMask = MIIM_TYPE ;
mii . fType = MFT_STRING ;
mii . dwTypeData = szMenuNew ;
SetMenuItemInfo ( hMenu , IDM_COPY , FALSE , & mii ) ;
2020-06-29 01:43:46 +03:00
POINT pt ;
2020-06-27 09:47:05 +03:00
GetCursorPos ( & pt ) ;
2020-06-29 01:43:46 +03:00
TrackPopupMenu ( hMenu , TPM_RIGHTBUTTON , pt . x , pt . y , 0 , g_hwndMain , nullptr ) ;
2020-06-27 09:47:05 +03:00
}
2020-06-29 01:43:46 +03:00
2020-06-27 09:47:05 +03:00
//-----------------------------------------------------------------------------
BOOL DXView_OnCreate ( HWND hWnd )
{
2020-06-29 01:43:46 +03:00
HDC hDC = GetDC ( hWnd ) ;
int PixelsPerInch = GetDeviceCaps ( hDC , LOGPIXELSX ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
NONCLIENTMETRICS nmi = { } ;
2020-06-27 09:47:05 +03:00
nmi . cbSize = sizeof ( nmi ) ;
2020-06-29 01:43:46 +03:00
( void ) SystemParametersInfo ( SPI_GETNONCLIENTMETRICS , sizeof ( NONCLIENTMETRICS ) , & nmi , 0 ) ;
g_hFont = CreateFontIndirect ( & nmi . lfMessageFont ) ;
2020-06-27 09:47:05 +03:00
SelectObject ( hDC , g_hFont ) ;
2020-06-29 01:43:46 +03:00
TEXTMETRIC tm = { } ;
2020-06-27 09:47:05 +03:00
GetTextMetrics ( hDC , & tm ) ;
g_tmAveCharWidth = tm . tmAveCharWidth ;
ReleaseDC ( hWnd , hDC ) ;
// Initialize global data
g_dwViewState = IDM_VIEWALL ;
g_xPaneSplit = PixelsPerInch * 12 / 4 ;
g_xHalfSplitWidth = GetSystemMetrics ( SM_CXSIZEFRAME ) / 2 ;
2020-06-29 01:43:46 +03:00
g_dwView9Ex = DXG_Is9Ex ( ) ? 1 : 0 ;
CheckMenuItem ( GetMenu ( hWnd ) , IDM_VIEW9EX , MF_BYCOMMAND | ( g_dwView9Ex ? MF_CHECKED : MF_UNCHECKED ) ) ;
2020-06-27 09:47:05 +03:00
// Make sure that the common control library read to rock
InitCommonControls ( ) ;
CheckMenuItem ( GetMenu ( hWnd ) , g_dwViewState , MF_BYCOMMAND | MF_CHECKED ) ;
// Create the list view window.
g_hwndLV = CreateWindowEx ( WS_EX_CLIENTEDGE , WC_LISTVIEW , " " ,
WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL ,
2020-06-29 01:43:46 +03:00
0 , 0 , 0 , 0 , hWnd , ( HMENU ) IDC_LV , g_hInstance , nullptr ) ;
2020-06-27 09:47:05 +03:00
ListView_SetExtendedListViewStyleEx ( g_hwndLV , LVS_EX_FULLROWSELECT , LVS_EX_FULLROWSELECT ) ;
// create the tree view window.
g_hwndTV = CreateWindowEx ( WS_EX_CLIENTEDGE , WC_TREEVIEW , " " ,
WS_VISIBLE | WS_CHILD | TVS_HASLINES |
TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS ,
2020-06-29 01:43:46 +03:00
0 , 0 , 0 , 0 , hWnd , ( HMENU ) IDC_TV , g_hInstance , nullptr ) ;
2020-06-27 09:47:05 +03:00
// create our image list.
DXView_InitImageList ( ) ;
// Add DXStuff stuff to the tree
// view.
2020-06-29 01:43:46 +03:00
DXGI_FillTree ( g_hwndTV ) ;
DXG_FillTree ( g_hwndTV ) ;
DD_FillTree ( g_hwndTV ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
TreeView_SelectItem ( g_hwndTV , TreeView_GetRoot ( g_hwndTV ) ) ;
2020-06-27 09:47:05 +03:00
return ( TRUE ) ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
void AddCapsToTV ( HTREEITEM hRoot , CAPDEFS * pcds , LPARAM lParam1 )
2020-06-27 09:47:05 +03:00
{
BOOL bRoot = TRUE ; // the first one is always a root
2020-06-29 01:43:46 +03:00
HTREEITEM hParent [ 20 ] ;
2020-06-27 09:47:05 +03:00
hParent [ 0 ] = hRoot ;
2020-06-29 01:43:46 +03:00
int level = 0 ;
const char * name ;
while ( ( name = pcds - > strName ) ! = nullptr )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
if ( name [ 0 ] = = ' - ' )
2020-06-27 09:47:05 +03:00
{
level - - ;
2020-06-29 01:43:46 +03:00
if ( level < 0 )
2020-06-27 09:47:05 +03:00
level = 0 ;
name + + ;
}
2020-06-29 01:43:46 +03:00
if ( name [ 0 ] = = ' + ' )
2020-06-27 09:47:05 +03:00
{
bRoot = TRUE ;
name + + ;
}
2020-06-29 01:43:46 +03:00
if ( name [ 0 ] & & ( level > = 0 & & level < 20 ) )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
HTREEITEM hTree = TVAddNode ( hParent [ level ] , name , bRoot , IDI_CAPS ,
pcds - > fnDisplayCallback , lParam1 ,
pcds - > lParam2 ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
if ( bRoot )
2020-06-27 09:47:05 +03:00
{
level + + ;
2020-06-29 01:43:46 +03:00
if ( level > = 20 )
2020-06-27 09:47:05 +03:00
level = 19 ;
hParent [ level ] = hTree ;
bRoot = FALSE ;
}
}
pcds + + ; // Get next Cap bit definition
}
}
//-----------------------------------------------------------------------------
// AddMoreCapsToLV is like AddCapsToLV, except it doesn't add the
// column headers like AddCapsToLV does.
2020-06-29 01:43:46 +03:00
void AddMoreCapsToLV ( CAPDEF * pcd , LPVOID pv )
2020-06-27 09:47:05 +03:00
{
TCHAR szBuff [ 64 ] ;
2020-06-29 01:43:46 +03:00
while ( pcd - > strName & & * pcd - > strName )
2020-06-27 09:47:05 +03:00
{
if ( ! g_dwView9Ex & & ( pcd - > dwCapsFlags & DXV_9EXCAP ) )
{
pcd + + ; // Get next Cap bit definition
continue ;
}
2020-06-29 01:43:46 +03:00
auto dwValue = * reinterpret_cast < DWORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
2020-06-27 09:47:05 +03:00
switch ( pcd - > dwFlag )
{
2020-06-29 01:43:46 +03:00
case 0 :
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
Int2Str ( szBuff , 64 , dwValue ) ;
LVAddText ( g_hwndLV , 1 , " %s " , szBuff ) ;
break ;
case 0xFFFFFFFF : // Hex
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
LVAddText ( g_hwndLV , 1 , " 0x%08X " , dwValue ) ;
break ;
case 0xEFFFFFFF : // Shader Version
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
LVAddText ( g_hwndLV , 1 , " %d.%0d " , D3DSHADER_VERSION_MAJOR ( dwValue ) , D3DSHADER_VERSION_MINOR ( dwValue ) ) ;
break ;
case 0xBFFFFFFF : // FLOAT Support for new DX6 "D3DVALUE" values in D3DDeviceDesc
{
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
auto fValue = * reinterpret_cast < float * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
LVAddText ( g_hwndLV , 1 , " %G " , fValue ) ;
break ;
}
case 0x7FFFFFFF : // HEX Support for new DX6 "WORD" values in D3DDeviceDesc
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
dwValue = * reinterpret_cast < WORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
LVAddText ( g_hwndLV , 1 , " 0x%04X " , dwValue ) ;
break ;
case 0x3FFFFFFF : // VAL Support for new DX6 "WORD" values in D3DDeviceDesc
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
dwValue = * reinterpret_cast < WORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
Int2Str ( szBuff , 64 , dwValue ) ;
LVAddText ( g_hwndLV , 1 , " %s " , szBuff ) ;
break ;
case 0x1FFFFFFF : // "-1 == unlimited"
LVAddText ( g_hwndLV , 0 , " %s " , pcd - > strName ) ;
if ( dwValue = = 0xFFFFFFFF )
{
LVAddText ( g_hwndLV , 1 , " Unlimited " ) ;
}
else
{
Int2Str ( szBuff , 64 , dwValue ) ;
2020-06-27 09:47:05 +03:00
LVAddText ( g_hwndLV , 1 , " %s " , szBuff ) ;
2020-06-29 01:43:46 +03:00
}
break ;
case 0x0fffffff : // Mask with 0xffff
{
LVAddText ( g_hwndLV , 0 , pcd - > strName ) ;
dwValue = ( * reinterpret_cast < DWORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ) & 0xffff ;
Int2Str ( szBuff , 64 , dwValue ) ;
LVAddText ( g_hwndLV , 1 , " %s " , szBuff ) ;
}
break ;
default :
if ( pcd - > dwFlag & dwValue )
{
LVAddText ( g_hwndLV , 0 , pcd - > strName ) ;
LVAddText ( g_hwndLV , 1 , c_szYes ) ;
}
else if ( g_dwViewState = = IDM_VIEWALL )
{
LVAddText ( g_hwndLV , 0 , pcd - > strName ) ;
LVAddText ( g_hwndLV , 1 , c_szNo ) ;
}
break ;
2020-06-27 09:47:05 +03:00
}
pcd + + ; // Get next Cap bit definition
}
}
//-----------------------------------------------------------------------------
// AddColsToLV adds the column headers but no data.
void AddColsToLV ( void )
{
2022-08-01 23:59:11 +03:00
LVAddColumn ( g_hwndLV , 0 , " Name " , c_DefNameLength ) ;
2020-06-27 09:47:05 +03:00
LVAddColumn ( g_hwndLV , 1 , " Value " , 10 ) ;
}
//-----------------------------------------------------------------------------
VOID AddCapsToLV ( CAPDEF * pcd , LPVOID pv )
{
AddColsToLV ( ) ;
AddMoreCapsToLV ( pcd , pv ) ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
_Use_decl_annotations_
HRESULT PrintCapsToDC ( CAPDEF * pcd , LPVOID pv , PRINTCBINFO * lpInfo )
2020-06-27 09:47:05 +03:00
{
DWORD cchLen ;
TCHAR szValue [ 100 ] ;
// Check Parameters
2020-06-29 01:43:46 +03:00
if ( ( ! pcd ) | | ( ! lpInfo ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
// Calculate Name and Value column x offsets
2020-06-29 01:43:46 +03:00
int xName = ( lpInfo - > dwCurrIndent * DEF_TAB_SIZE * lpInfo - > dwCharWidth ) ;
2022-08-02 00:38:02 +03:00
int xVal = xName + ( c_tabStop * lpInfo - > dwCharWidth ) ;
2020-06-27 09:47:05 +03:00
while ( pcd - > strName & & * pcd - > strName )
{
if ( ! g_dwView9Ex & & ( pcd - > dwCapsFlags & DXV_9EXCAP ) )
{
pcd + + ; // Get next Cap bit definition
continue ;
}
2020-06-29 01:43:46 +03:00
auto dwValue = * reinterpret_cast < DWORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
int yLine = lpInfo - > dwCurrLine * lpInfo - > dwLineHeight ;
2020-06-27 09:47:05 +03:00
if ( pcd - > dwFlag )
{
switch ( pcd - > dwFlag )
{
2020-06-29 01:43:46 +03:00
case 0xFFFFFFFF : // Hex
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value in hex
sprintf_s ( szValue , sizeof ( szValue ) , " 0x%08X " , dwValue ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case 0xEFFFFFFF : // Shader Version
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print version
sprintf_s ( szValue , sizeof ( szValue ) , " %u.%0u " , D3DSHADER_VERSION_MAJOR ( dwValue ) , D3DSHADER_VERSION_MINOR ( dwValue ) ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case 0xBFFFFFFF : // FLOAT Support for new DX6 "D3DVALUE" values in D3DDeviceDesc
{
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value
auto fValue = * reinterpret_cast < float * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
sprintf_s ( szValue , sizeof ( szValue ) , " %G " , fValue ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
}
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case 0x7FFFFFFF : // HEX Support for new DX6 "WORD" values in D3DDeviceDesc
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value
dwValue = * reinterpret_cast < WORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
sprintf_s ( szValue , sizeof ( szValue ) , " 0x%04X " , dwValue ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case 0x3FFFFFFF : // VAL Support for new DX6 "WORD" values in D3DDeviceDesc
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value
dwValue = * reinterpret_cast < WORD * > ( static_cast < BYTE * > ( pv ) + pcd - > dwOffset ) ;
* szValue = 0 ;
Int2Str ( szValue , 100 , dwValue ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
case 0x1FFFFFFF : // "-1 == unlimited"
// Print name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
return E_FAIL ;
// Print value
* szValue = 0 ;
if ( dwValue = = 0xFFFFFFFF )
strcpy_s ( szValue , sizeof ( szValue ) , " Unlimited " ) ;
else
Int2Str ( szValue , 100 , dwValue ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szValue , strlen ( szValue ) , lpInfo ) ) )
return E_FAIL ;
// Advance to next line on page
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
return E_FAIL ;
break ;
default :
if ( pcd - > dwFlag & dwValue )
{
// Print Name
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
// Print Yes in value column
cchLen = static_cast < DWORD > ( _tcslen ( c_szYes ) ) ;
if ( FAILED ( PrintLine ( xVal , yLine , c_szYes , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
2020-06-27 09:47:05 +03:00
// Advance to next line on page
2020-06-29 01:43:46 +03:00
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
}
else if ( g_dwViewState = = IDM_VIEWALL )
{
2020-06-27 09:47:05 +03:00
// Print name
2020-06-29 01:43:46 +03:00
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , pcd - > strName , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
// Print No in value column
cchLen = static_cast < DWORD > ( _tcslen ( c_szNo ) ) ;
if ( FAILED ( PrintLine ( xVal , yLine , c_szNo , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
2020-06-27 09:47:05 +03:00
// Advance to next line on page
2020-06-29 01:43:46 +03:00
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
2020-06-29 01:43:46 +03:00
}
2020-06-27 09:47:05 +03:00
break ;
}
}
else
{
2022-08-01 23:59:11 +03:00
char szBuff [ c_maxPrintLine ] ;
2020-06-27 09:47:05 +03:00
// Print name
2020-06-29 01:43:46 +03:00
sprintf_s ( szBuff , sizeof ( szBuff ) , pcd - > strName , " test " ) ;
cchLen = static_cast < DWORD > ( _tcslen ( pcd - > strName ) ) ;
if ( FAILED ( PrintLine ( xName , yLine , szBuff , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
// Print value
2022-08-01 23:59:11 +03:00
Int2Str ( szBuff , c_maxPrintLine , dwValue ) ;
2020-06-29 01:43:46 +03:00
cchLen = static_cast < DWORD > ( _tcslen ( szBuff ) ) ;
if ( FAILED ( PrintLine ( xVal , yLine , szBuff , cchLen , lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
// Advance to next line on page
2020-06-29 01:43:46 +03:00
if ( FAILED ( PrintNextLine ( lpInfo ) ) )
2020-06-27 09:47:05 +03:00
return E_FAIL ;
}
pcd + + ; // Get next Cap bit definition
}
return S_OK ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
void DXView_OnTreeSelect ( HWND /*hwndTV*/ , NM_TREEVIEW * ptv )
2020-06-27 09:47:05 +03:00
{
SendMessage ( g_hwndLV , WM_SETREDRAW , FALSE , 0 ) ;
LVDeleteAllItems ( g_hwndLV ) ;
LVAddColumn ( g_hwndLV , 0 , " " , 0 ) ;
2020-06-29 01:43:46 +03:00
NODEINFO * pni = nullptr ;
if ( ! ptv )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
TV_ITEM tvi = { } ;
2020-06-27 09:47:05 +03:00
// get lParam of current tree node
2020-06-29 01:43:46 +03:00
tvi . hItem = TreeView_GetSelection ( g_hwndTV ) ;
tvi . mask = TVIF_PARAM ;
2020-06-27 09:47:05 +03:00
TreeView_GetItem ( g_hwndTV , & tvi ) ;
pni = ( NODEINFO * ) tvi . lParam ;
}
else
{
pni = ( NODEINFO * ) ptv - > itemNew . lParam ;
}
if ( pni & & pni - > fnDisplayCallback )
{
2020-06-29 01:43:46 +03:00
if ( pni - > bUseLParam3 )
( ( DISPLAYCALLBACKEX ) ( pni - > fnDisplayCallback ) ) ( pni - > lParam1 , pni - > lParam2 , pni - > lParam3 , nullptr ) ;
2020-06-27 09:47:05 +03:00
else
2020-06-29 01:43:46 +03:00
pni - > fnDisplayCallback ( pni - > lParam1 , pni - > lParam2 , nullptr ) ;
2020-06-27 09:47:05 +03:00
}
2020-06-29 01:43:46 +03:00
ListView_SetItemState ( g_hwndLV , 0 , LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED ) ;
2020-06-27 09:47:05 +03:00
SendMessage ( g_hwndLV , WM_SETREDRAW , TRUE , 0 ) ;
2020-06-29 01:43:46 +03:00
InvalidateRect ( g_hwndLV , nullptr , TRUE ) ;
2020-06-27 09:47:05 +03:00
}
//-----------------------------------------------------------------------------
void DXView_OnListViewDblClick ( HWND hwndLV , NM_LISTVIEW * plv )
{
2020-06-29 01:43:46 +03:00
LV_ITEM lvi = { } ;
2020-06-27 09:47:05 +03:00
lvi . mask = LVIF_PARAM ;
lvi . iItem = plv - > iItem ;
ListView_GetItem ( hwndLV , & lvi ) ;
}
//-----------------------------------------------------------------------------
void DXView_OnCommand ( HWND hWnd , WPARAM wParam )
{
HMENU hMenu ;
2020-06-29 01:43:46 +03:00
switch ( LOWORD ( wParam ) )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
case IDM_VIEWAVAIL :
case IDM_VIEWALL :
hMenu = GetMenu ( hWnd ) ;
CheckMenuItem ( hMenu , g_dwViewState , MF_BYCOMMAND | MF_UNCHECKED ) ;
g_dwViewState = LOWORD ( wParam ) ;
CheckMenuItem ( hMenu , g_dwViewState , MF_BYCOMMAND | MF_CHECKED ) ;
DXView_OnTreeSelect ( g_hwndTV , nullptr ) ;
break ;
case IDM_VIEW9EX :
hMenu = GetMenu ( hWnd ) ;
g_dwView9Ex = ! g_dwView9Ex ;
CheckMenuItem ( hMenu , IDM_VIEW9EX , MF_BYCOMMAND | ( g_dwView9Ex ? MF_CHECKED : MF_UNCHECKED ) ) ;
DXView_OnTreeSelect ( g_hwndTV , nullptr ) ;
break ;
case IDM_PRINTWHOLETREETOPRINTER :
g_PrintToFile = FALSE ;
DXView_OnPrint ( hWnd , g_hwndTV , TRUE ) ;
break ;
case IDM_PRINTSUBTREETOPRINTER :
g_PrintToFile = FALSE ;
DXView_OnPrint ( hWnd , g_hwndTV , FALSE ) ;
break ;
case IDM_PRINTWHOLETREETOFILE :
g_PrintToFile = TRUE ;
DXView_OnFile ( hWnd , g_hwndTV , TRUE ) ;
break ;
case IDM_PRINTSUBTREETOFILE :
g_PrintToFile = TRUE ;
DXView_OnFile ( hWnd , g_hwndTV , FALSE ) ;
break ;
case IDM_COPY :
{
// Put g_szClip into the clipboard
UINT GlobalSize = static_cast < UINT > ( strlen ( g_szClip ) + 1 ) ;
HGLOBAL hGlobal = GlobalAlloc ( GHND | GMEM_SHARE , GlobalSize ) ;
if ( hGlobal )
{
VOID * pGlobal = GlobalLock ( hGlobal ) ;
if ( pGlobal )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
strcpy_s ( ( CHAR * ) pGlobal , GlobalSize , g_szClip ) ;
GlobalUnlock ( hGlobal ) ;
OpenClipboard ( g_hwndMain ) ;
EmptyClipboard ( ) ;
SetClipboardData ( CF_TEXT , hGlobal ) ;
CloseClipboard ( ) ;
2020-06-27 09:47:05 +03:00
}
2020-06-29 01:43:46 +03:00
}
}
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case IDM_ABOUT :
DialogBox ( g_hInstance , " About " , hWnd , ( DLGPROC ) About ) ;
break ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case IDM_EXIT :
PostMessage ( hWnd , WM_CLOSE , 0 , 0 ) ;
break ;
2020-06-27 09:47:05 +03:00
}
}
//-----------------------------------------------------------------------------
void DXView_Cleanup ( )
{
2020-06-27 10:06:21 +03:00
DXGI_CleanUp ( ) ;
2020-06-27 09:47:05 +03:00
DXG_CleanUp ( ) ;
DD_CleanUp ( ) ;
2020-06-29 01:43:46 +03:00
if ( g_hImageList )
ImageList_Destroy ( g_hImageList ) ;
2020-06-27 09:47:05 +03:00
}
//-----------------------------------------------------------------------------
BOOL DXView_InitImageList ( )
{
if ( g_hImageList )
return TRUE ;
2020-06-29 01:43:46 +03:00
int cxSmIcon = GetSystemMetrics ( SM_CXSMICON ) ;
int cySmIcon = GetSystemMetrics ( SM_CYSMICON ) ;
2020-06-27 09:47:05 +03:00
// First, create the image list that is needed.
2020-06-29 01:43:46 +03:00
if ( ( g_hImageList = ImageList_Create ( cxSmIcon , cySmIcon , TRUE , IDI_LASTIMAGE - IDI_FIRSTIMAGE , 10 ) ) = = nullptr )
2020-06-27 09:47:05 +03:00
return ( FALSE ) ;
//
// Initialize the image list with all of the icons that we'll be using
// Once set, send its handle to all interested child windows.
//
2020-06-29 01:43:46 +03:00
for ( UINT Index = IDI_FIRSTIMAGE ; Index < = IDI_LASTIMAGE ; Index + + )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
auto hIcon = reinterpret_cast < HICON > ( LoadImage ( g_hInstance , MAKEINTRESOURCE ( Index ) , IMAGE_ICON , cxSmIcon , cySmIcon , 0 ) ) ;
if ( hIcon )
2020-06-27 09:47:05 +03:00
{
ImageList_AddIcon ( g_hImageList , hIcon ) ;
DestroyIcon ( hIcon ) ;
}
}
2020-06-29 01:43:46 +03:00
TreeView_SetImageList ( g_hwndTV , g_hImageList , TVSIL_NORMAL ) ;
2020-06-27 09:47:05 +03:00
return TRUE ;
}
//-----------------------------------------------------------------------------
// Name: About()
// Desc: Process about box
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
LRESULT CALLBACK About ( HWND hDlg , UINT msg , WPARAM wParam , LPARAM /*lParam*/ )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
switch ( msg )
{
case WM_INITDIALOG :
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
VS_FIXEDFILEINFO * pVersion = nullptr ;
TCHAR strFmt [ 500 ] ;
GetWindowText ( GetDlgItem ( hDlg , IDC_VERSION ) , strFmt , 500 ) ;
TCHAR szFile [ MAX_PATH ] ;
* szFile = 0 ;
GetModuleFileName ( nullptr , szFile , MAX_PATH ) ;
DWORD dwHandle ;
UINT cb = GetFileVersionInfoSize ( szFile , & dwHandle /*ignored*/ ) ;
if ( cb > 0 )
{
2020-06-27 09:47:05 +03:00
BYTE FileVersionBuffer [ 1024 ] ;
2020-06-29 01:43:46 +03:00
if ( cb > sizeof ( FileVersionBuffer ) )
cb = sizeof ( FileVersionBuffer ) ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
if ( GetFileVersionInfo ( szFile , 0 , cb , FileVersionBuffer ) )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
pVersion = nullptr ;
if ( VerQueryValue ( FileVersionBuffer , " \\ " , ( VOID * * ) & pVersion , & cb )
& & pVersion ! = nullptr )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
TCHAR strVersion [ 100 ] ;
sprintf_s ( strVersion , sizeof ( strVersion ) , " %u.%02u.%02u.%04u " ,
HIWORD ( pVersion - > dwFileVersionMS ) ,
LOWORD ( pVersion - > dwFileVersionMS ) ,
HIWORD ( pVersion - > dwFileVersionLS ) ,
LOWORD ( pVersion - > dwFileVersionLS ) ) ;
TCHAR str [ 500 ] ;
sprintf_s ( str , sizeof ( str ) , strFmt , strVersion ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_VERSION ) , str ) ;
2020-06-27 09:47:05 +03:00
}
}
2020-06-29 01:43:46 +03:00
}
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
// Note: The warning text is static, but it must be set via code,
// not in the .rc file, because it is > 256 characters (warning RC4206).
{
const TCHAR * pstrWarning = TEXT ( " Warning: This computer program is protected by copyright law and international treaties. Unauthorized reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under the law. " ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_WARNING ) , pstrWarning ) ;
}
return TRUE ;
}
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
case WM_COMMAND :
if ( LOWORD ( wParam ) = = IDOK | | LOWORD ( wParam ) = = IDCANCEL )
{
EndDialog ( hDlg , TRUE ) ; // Exit the dialog
return TRUE ;
}
break ;
2020-06-27 09:47:05 +03:00
}
return FALSE ;
}
//-----------------------------------------------------------------------------
// Name: DXView_OnSize()
// Desc: Called whenever the size of the app window has changed or the size
// of its child controls should be adjusted.
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
VOID DXView_OnSize ( HWND hWnd )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
if ( IsIconic ( hWnd ) )
2020-06-27 09:47:05 +03:00
return ;
2020-06-29 01:43:46 +03:00
HDWP hDWP ;
if ( ( hDWP = BeginDeferWindowPos ( 2 ) ) ! = nullptr )
2020-06-27 09:47:05 +03:00
{
// Data structure used when calling GetEffectiveClientRect (which takes into
// account space taken up by the toolbars/status bars). First half of the
// pair is zero when at the end of the list, second half is the control id.
int s_EffectiveClientRectData [ ] =
{
1 , 0 , // For the menu bar, but is unused
0 , 0 // First zero marks end of data
} ;
2020-06-29 01:43:46 +03:00
RECT ClientRect ;
2020-06-27 09:47:05 +03:00
GetEffectiveClientRect ( hWnd , & ClientRect , s_EffectiveClientRectData ) ;
2020-06-29 01:43:46 +03:00
int Height = ClientRect . bottom - ClientRect . top ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
HWND hKeyTreeWnd = g_hwndTV ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
DeferWindowPos ( hDWP , hKeyTreeWnd , nullptr , 0 , ClientRect . top , g_xPaneSplit ,
2020-06-27 09:47:05 +03:00
Height , SWP_NOZORDER | SWP_NOACTIVATE ) ;
2020-06-29 01:43:46 +03:00
int x = g_xPaneSplit + GetSystemMetrics ( SM_CXSIZEFRAME ) ;
int dx = ClientRect . right - ClientRect . left - x ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
HWND hValueListWnd = g_hwndLV ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
DeferWindowPos ( hDWP , hValueListWnd , nullptr , x , ClientRect . top , dx , Height ,
2020-06-27 09:47:05 +03:00
SWP_NOZORDER | SWP_NOACTIVATE ) ;
EndDeferWindowPos ( hDWP ) ;
}
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
void LVAddColumn ( HWND hwndLV , int i , const char * name , int width )
2020-06-27 09:47:05 +03:00
{
if ( i = = 0 )
{
2020-06-29 01:43:46 +03:00
while ( ListView_DeleteColumn ( hwndLV , 0 ) )
2020-06-27 09:47:05 +03:00
;
}
2020-06-29 01:43:46 +03:00
LV_COLUMN col = { } ;
2020-06-27 09:47:05 +03:00
col . mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
2020-06-29 01:43:46 +03:00
col . fmt = LVCFMT_LEFT ;
2020-06-27 09:47:05 +03:00
col . pszText = ( char * ) name ;
col . cx = width * g_tmAveCharWidth ;
ListView_InsertColumn ( hwndLV , i , & col ) ;
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
int LVAddText ( HWND hwndLV , int col , const char * sz , . . . )
2020-06-27 09:47:05 +03:00
{
va_list vl ;
2020-06-29 01:43:46 +03:00
va_start ( vl , sz ) ;
2020-06-27 09:47:05 +03:00
2022-08-01 23:59:11 +03:00
char ach [ c_maxPrintLine ] ;
2020-06-27 09:47:05 +03:00
vsprintf_s ( ach , sizeof ( ach ) , sz , vl ) ;
2022-08-01 23:59:11 +03:00
ach [ c_maxPrintLine - 1 ] = ' \0 ' ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
LV_ITEM lvi = { } ;
lvi . mask = LVIF_TEXT ;
lvi . pszText = ach ;
2020-06-27 09:47:05 +03:00
if ( col = = 0 )
{
2020-06-29 01:43:46 +03:00
lvi . iItem = 0x7FFF ;
2020-06-27 09:47:05 +03:00
lvi . iSubItem = 0 ;
va_end ( vl ) ;
return ListView_InsertItem ( hwndLV , & lvi ) ;
}
else
{
2020-06-29 01:43:46 +03:00
lvi . iItem = ListView_GetItemCount ( hwndLV ) - 1 ;
2020-06-27 09:47:05 +03:00
lvi . iSubItem = col ;
va_end ( vl ) ;
return ListView_SetItem ( hwndLV , & lvi ) ;
}
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
void LVDeleteAllItems ( HWND hwndLV )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
ListView_DeleteAllItems ( hwndLV ) ;
2020-06-27 09:47:05 +03:00
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
HTREEITEM TVAddNode ( HTREEITEM hParent , LPCSTR strText , BOOL fKids ,
int iImage , DISPLAYCALLBACK fnDisplayCallback , LPARAM lParam1 ,
LPARAM lParam2 )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
auto pni = reinterpret_cast < NODEINFO * > ( LocalAlloc ( LPTR , sizeof ( NODEINFO ) ) ) ;
if ( ! pni )
return nullptr ;
pni - > bUseLParam3 = FALSE ;
pni - > lParam1 = lParam1 ;
pni - > lParam2 = lParam2 ;
pni - > lParam3 = 0 ;
2020-06-27 09:47:05 +03:00
pni - > fnDisplayCallback = fnDisplayCallback ;
// Add Node to treeview
2020-06-29 01:43:46 +03:00
TV_INSERTSTRUCT tvi = { } ;
tvi . hParent = hParent ;
tvi . hInsertAfter = TVI_LAST ;
tvi . item . mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
TVIF_PARAM | TVIF_CHILDREN ;
tvi . item . iImage = iImage - IDI_FIRSTIMAGE ;
2020-06-27 09:47:05 +03:00
tvi . item . iSelectedImage = iImage - IDI_FIRSTIMAGE ;
2020-06-29 01:43:46 +03:00
tvi . item . lParam = ( LPARAM ) pni ;
tvi . item . cChildren = fKids ;
tvi . item . pszText = ( LPSTR ) strText ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
return TreeView_InsertItem ( g_hwndTV , & tvi ) ;
2020-06-27 09:47:05 +03:00
}
//-----------------------------------------------------------------------------
2020-06-29 01:43:46 +03:00
HTREEITEM TVAddNodeEx ( HTREEITEM hParent , LPCSTR strText , BOOL fKids ,
int iImage , DISPLAYCALLBACKEX fnDisplayCallback , LPARAM lParam1 ,
LPARAM lParam2 , LPARAM lParam3 )
2020-06-27 09:47:05 +03:00
{
2020-06-29 01:43:46 +03:00
auto pni = reinterpret_cast < NODEINFO * > ( LocalAlloc ( LPTR , sizeof ( NODEINFO ) ) ) ;
if ( ! pni )
return nullptr ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
pni - > bUseLParam3 = TRUE ;
pni - > lParam1 = lParam1 ;
pni - > lParam2 = lParam2 ;
pni - > lParam3 = lParam3 ;
pni - > fnDisplayCallback = reinterpret_cast < DISPLAYCALLBACK > ( fnDisplayCallback ) ;
2020-06-27 09:47:05 +03:00
// Add Node to treeview
2020-06-29 01:43:46 +03:00
TV_INSERTSTRUCT tvi = { } ;
tvi . hParent = hParent ;
tvi . hInsertAfter = TVI_LAST ;
tvi . item . mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
TVIF_PARAM | TVIF_CHILDREN ;
tvi . item . iImage = iImage - IDI_FIRSTIMAGE ;
2020-06-27 09:47:05 +03:00
tvi . item . iSelectedImage = iImage - IDI_FIRSTIMAGE ;
2020-06-29 01:43:46 +03:00
tvi . item . lParam = ( LPARAM ) pni ;
tvi . item . cChildren = fKids ;
tvi . item . pszText = ( LPSTR ) strText ;
2020-06-27 09:47:05 +03:00
2020-06-29 01:43:46 +03:00
return TreeView_InsertItem ( g_hwndTV , & tvi ) ;
2020-06-27 09:47:05 +03:00
}