-
Notifications
You must be signed in to change notification settings - Fork 20
/
dxview.cpp
1264 lines (1067 loc) · 41.8 KB
/
dxview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
// Name: dxview.cpp
//
// Desc: DirectX Capabilities Viewer (Main program)
//
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
//
// https://go.microsoft.com/fwlink/?linkid=2136896
//-----------------------------------------------------------------------------
#include "dxview.h"
#include <objbase.h>
#include <stdio.h>
#include <strsafe.h>
#include <shlwapi.h>
// These are from d3d8types.h
#define D3DSHADER_VERSION_MAJOR(_Version) (((_Version)>>8)&0xFF)
#define D3DSHADER_VERSION_MINOR(_Version) (((_Version)>>0)&0xFF)
constexpr size_t c_maxPasteBuffer = 200;
constexpr size_t c_maxPrintLine = 128;
constexpr int c_tabStop = 52;
static_assert(c_tabStop >= c_DefNameLength, "print stop should be at least as long as the default name");
HINSTANCE g_hInstance = nullptr;
HWND g_hwndMain = nullptr;
CHAR g_strAppName[] = "DXView";
CHAR g_strClassName[] = "DXView";
CHAR g_strTitle[] = "DirectX Caps Viewer";
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";
HWND g_hwndLV = nullptr; // List view
HWND g_hwndTV = nullptr; // Tree view
HIMAGELIST g_hImageList = nullptr;
HFONT g_hFont = nullptr;
int g_xPaneSplit;
int g_xHalfSplitWidth;
BOOL g_bSplitMove;
DWORD g_dwViewState;
DWORD g_dwView9Ex;
DWORD g_tmAveCharWidth;
extern BOOL g_PrintToFile;
extern TCHAR g_PrintToFilePath[MAX_PATH];
CHAR g_szClip[c_maxPasteBuffer];
TCHAR g_helpPath[MAX_PATH] = {};
//-----------------------------------------------------------------------------
// 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;
char strDec[2];
GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, strDec, 2 );
char strIn[32];
sprintf_s( strIn, sizeof(strIn), "%u",i );
char strOut[32];
if( 0 == GetNumberFormat( LOCALE_USER_DEFAULT, 0, strIn, nullptr, strOut, 32 ) )
{
strcpy_s( strDest, nDestLen, strIn );
return E_FAIL;
}
char * pstrDec = strrchr( strOut, strDec[0] );
if( pstrDec)
*pstrDec = '\0';
if( strcpy_s( strDest, nDestLen, strOut ) != 0)
{
*strDest = 0;
return E_FAIL;
}
return S_OK;
}
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintStringValueLine(const char * szText, const char * szText2, PRINTCBINFO *lpInfo)
{
// Calculate Name and Value column x offsets
int xName = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
int xVal = xName + (c_tabStop * lpInfo->dwCharWidth);
int yLine = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
// Print name
char szBuff[c_maxPrintLine];
strcpy_s(szBuff, sizeof(szBuff), szText);
szBuff[c_maxPrintLine - 1] = '\0';
auto cchLen = static_cast<DWORD>(_tcslen(szText));
if( FAILED( PrintLine (xName, yLine, szBuff, cchLen, lpInfo) ) )
return E_FAIL;
// Print value
strcpy_s(szBuff, sizeof(szBuff), szText2);
szBuff[c_maxPrintLine - 1] = '\0';
cchLen = static_cast<DWORD>(_tcslen(szText2));
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;
}
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintValueLine(const char * szText, DWORD dwValue, PRINTCBINFO *lpInfo)
{
char szBuff[c_maxPrintLine];
Int2Str(szBuff, c_maxPrintLine, dwValue);
return PrintStringValueLine( szText, szBuff, lpInfo );
}
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintHexValueLine(const char * szText, DWORD dwValue, PRINTCBINFO *lpInfo)
{
char szBuff[c_maxPrintLine];
sprintf_s( szBuff, sizeof(szBuff), "0x%08x", dwValue );
return PrintStringValueLine( szText, szBuff, lpInfo );
}
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintStringLine(const char * szText, PRINTCBINFO *lpInfo)
{
// Calculate Name and Value column x offsets
int xName = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
int yLine = (lpInfo->dwCurrLine * lpInfo->dwLineHeight);
// Print name
char szBuff[c_maxPrintLine];
strcpy_s(szBuff, sizeof(szBuff), szText);
szBuff[c_maxPrintLine - 1] = '\0';
auto cchLen = static_cast<DWORD>(_tcslen(szText));
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;
}
//-----------------------------------------------------------------------------
// Name: WinMain
//-----------------------------------------------------------------------------
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*/,
_In_ LPSTR /*strCmdLine*/, _In_ int /*nCmdShow*/)
{
g_hInstance = hInstance; // Store instance handle in our global variable
g_PrintToFilePath[0] = TEXT('\0');
// Initialize COM
HRESULT hr = CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);
if (FAILED(hr))
return 1;
// Init various DX components
DXGI_Init();
DXG_Init();
DD_Init();
// Register window class
WNDCLASS wc;
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(NULL, IDC_SIZEWE);// Cursor
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); // Default color
wc.lpszMenuName = "Menu"; // Menu name from .RC
wc.lpszClassName = g_strClassName; // Name to register as
RegisterClass(&wc);
// Create a main window for this application instance.
g_hwndMain = CreateWindowEx(0, g_strClassName, g_strTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, DXView_WIDTH, DXView_HEIGHT,
nullptr, nullptr, hInstance, nullptr);
// If window could not be created, return "failure"
if (!g_hwndMain)
{
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.
if (*pszCmdLine == TEXT('"'))
pszCmdLine++;
}
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.
if (*pszCmdLine == TEXT('"'))
pszCmdLine++;
}
else // First token wasn't a quote
{
while (*pszCmdLine > TEXT(' '))
*pstrSave++ = *pszCmdLine++;
}
*pstrSave = TEXT('\0');
if (strlen(g_PrintToFilePath) > 0)
{
PostMessage(g_hwndMain, WM_COMMAND, IDM_PRINTWHOLETREETOFILE, 0);
PostMessage(g_hwndMain, WM_CLOSE, 0, 0);
}
else
{
// Make the window visible; update its client area; and return "success"
ShowWindow(g_hwndMain, SW_MAXIMIZE /*nCmdShow*/);
}
// Message pump
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return (int)msg.wParam;
}
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
return DXView_OnCreate(hWnd);
case WM_SIZE:
DXView_OnSize(hWnd);
break;
case WM_LBUTTONDOWN:
g_bSplitMove = TRUE;
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
g_bSplitMove = FALSE;
ReleaseCapture();
break;
case WM_MOUSEMOVE:
if (g_bSplitMove)
{
RECT rect;
// change the value from unsigned to signed
int x = (int)(short)LOWORD(lParam);
GetClientRect(hWnd, &rect);
if (rect.left > x)
{
x = rect.left;
}
else if (rect.right < x)
{
x = rect.right;
}
g_xPaneSplit = (x - g_xHalfSplitWidth);
DXView_OnSize(hWnd);
}
break;
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)
{
NMHDR* pnmhdr = (NMHDR*)lParam;
TVHITTESTINFO info;
GetCursorPos(&info.pt);
ScreenToClient(pnmhdr->hwndFrom, &info.pt);
TreeView_HitTest(pnmhdr->hwndFrom, &info);
if (info.flags & TVHT_ONITEMLABEL)
{
TVITEM tvitem;
tvitem.mask = TVIF_TEXT;
tvitem.hItem = info.hItem;
tvitem.pszText = g_szClip;
tvitem.cchTextMax = c_maxPasteBuffer;
TreeView_GetItem(g_hwndTV, &tvitem);
CreateCopyMenu();
}
}
else if (((NMHDR*)lParam)->code == TVN_KEYDOWN)
{
NMTVKEYDOWN* ptvkd = (LPNMTVKEYDOWN)lParam;
if (ptvkd->wVKey == VK_TAB)
SetFocus(g_hwndLV);
}
}
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)
{
NMHDR* pnmhdr = (NMHDR*)lParam;
LVHITTESTINFO info;
GetCursorPos(&info.pt);
ScreenToClient(pnmhdr->hwndFrom, &info.pt);
ListView_SubItemHitTest(pnmhdr->hwndFrom, &info);
if (info.iItem >= 0)
{
ListView_GetItemText(g_hwndLV, info.iItem, info.iSubItem, g_szClip, c_maxPasteBuffer);
CreateCopyMenu();
}
}
else if (((NMHDR*)lParam)->code == LVN_KEYDOWN)
{
NMLVKEYDOWN* plvkd = (LPNMLVKEYDOWN)lParam;
if (plvkd->wVKey == VK_TAB)
SetFocus(g_hwndTV);
}
}
break;
case WM_SETFOCUS:
SetFocus(g_hwndTV);
break;
case WM_COMMAND: // message: command from application menu
DXView_OnCommand(hWnd, wParam);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
return 0;
case WM_DESTROY: // message: window being destroyed
DXView_Cleanup(); // Free per item struct for all items
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
VOID CreateCopyMenu(VOID)
{
HMENU hPopupMenu = LoadMenu(nullptr, "POPUP");
if (!hPopupMenu)
return;
HMENU hMenu = GetSubMenu(hPopupMenu, 0);
if (!hMenu)
{
DestroyMenu(hPopupMenu);
return;
}
TCHAR szMenu[c_maxPasteBuffer];
GetMenuString(hMenu, IDM_COPY, szMenu, c_maxPasteBuffer, MF_BYCOMMAND);
TCHAR szMenuNew[c_maxPasteBuffer];
sprintf_s(szMenuNew, sizeof(szMenuNew), szMenu, g_szClip);
MENUITEMINFO mii = {};
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE;
mii.fType = MFT_STRING;
mii.dwTypeData = szMenuNew;
SetMenuItemInfo(hMenu, IDM_COPY, FALSE, &mii);
POINT pt;
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, g_hwndMain, nullptr);
}
//-----------------------------------------------------------------------------
BOOL DXView_OnCreate(HWND hWnd)
{
HDC hDC = GetDC(hWnd);
int PixelsPerInch = GetDeviceCaps(hDC, LOGPIXELSX);
NONCLIENTMETRICS nmi = {};
nmi.cbSize = sizeof(nmi);
(void)SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nmi, 0);
g_hFont = CreateFontIndirect(&nmi.lfMessageFont);
SelectObject(hDC, g_hFont);
TEXTMETRIC tm = {};
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;
g_dwView9Ex = DXG_Is9Ex() ? 1 : 0;
CheckMenuItem(GetMenu(hWnd), IDM_VIEW9EX, MF_BYCOMMAND | (g_dwView9Ex ? MF_CHECKED : MF_UNCHECKED));
// 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,
0, 0, 0, 0, hWnd, (HMENU)IDC_LV, g_hInstance, nullptr);
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,
0, 0, 0, 0, hWnd, (HMENU)IDC_TV, g_hInstance, nullptr);
// create our image list.
DXView_InitImageList();
// Add DXStuff stuff to the tree
// view.
DXGI_FillTree(g_hwndTV);
DXG_FillTree(g_hwndTV);
DD_FillTree(g_hwndTV);
TreeView_SelectItem(g_hwndTV, TreeView_GetRoot(g_hwndTV));
return(TRUE);
}
//-----------------------------------------------------------------------------
void AddCapsToTV(HTREEITEM hRoot, CAPDEFS* pcds, LPARAM lParam1)
{
BOOL bRoot = TRUE; // the first one is always a root
HTREEITEM hParent[20];
hParent[0] = hRoot;
int level = 0;
const char* name;
while ((name = pcds->strName) != nullptr)
{
if (name[0] == '-')
{
level--;
if (level < 0)
level = 0;
name++;
}
if (name[0] == '+')
{
bRoot = TRUE;
name++;
}
if (name[0] && (level >= 0 && level < 20))
{
HTREEITEM hTree = TVAddNode(hParent[level], name, bRoot, IDI_CAPS,
pcds->fnDisplayCallback, lParam1,
pcds->lParam2);
if (bRoot)
{
level++;
if (level >= 20)
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.
void AddMoreCapsToLV(CAPDEF* pcd, LPVOID pv)
{
TCHAR szBuff[64];
while (pcd->strName && *pcd->strName)
{
if (!g_dwView9Ex && (pcd->dwCapsFlags & DXV_9EXCAP))
{
pcd++; // Get next Cap bit definition
continue;
}
auto dwValue = *reinterpret_cast<DWORD*>(static_cast<BYTE*>(pv) + pcd->dwOffset);
switch (pcd->dwFlag)
{
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);
LVAddText(g_hwndLV, 1, "%s", szBuff);
}
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;
}
pcd++; // Get next Cap bit definition
}
}
//-----------------------------------------------------------------------------
// AddColsToLV adds the column headers but no data.
void AddColsToLV(void)
{
LVAddColumn(g_hwndLV, 0, "Name", c_DefNameLength);
LVAddColumn(g_hwndLV, 1, "Value", 10);
}
//-----------------------------------------------------------------------------
VOID AddCapsToLV(CAPDEF *pcd, LPVOID pv)
{
AddColsToLV();
AddMoreCapsToLV(pcd, pv);
}
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintCapsToDC(CAPDEF* pcd, LPVOID pv, PRINTCBINFO* lpInfo)
{
DWORD cchLen;
TCHAR szValue[100];
// Check Parameters
if ((!pcd) || (!lpInfo))
return E_FAIL;
// Calculate Name and Value column x offsets
int xName = (lpInfo->dwCurrIndent * DEF_TAB_SIZE * lpInfo->dwCharWidth);
int xVal = xName + (c_tabStop * lpInfo->dwCharWidth);
while (pcd->strName && *pcd->strName)
{
if (!g_dwView9Ex && (pcd->dwCapsFlags & DXV_9EXCAP))
{
pcd++; // Get next Cap bit definition
continue;
}
auto dwValue = *reinterpret_cast<DWORD*>(static_cast<BYTE*>(pv) + pcd->dwOffset);
int yLine = lpInfo->dwCurrLine * lpInfo->dwLineHeight;
if (pcd->dwFlag)
{
switch (pcd->dwFlag)
{
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;
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;
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;
}
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;
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)))
return E_FAIL;
// Print Yes in value column
cchLen = static_cast<DWORD>(_tcslen(c_szYes));
if (FAILED(PrintLine(xVal, yLine, c_szYes, cchLen, lpInfo)))
return E_FAIL;
// Advance to next line on page
if (FAILED(PrintNextLine(lpInfo)))
return E_FAIL;
}
else if (g_dwViewState == IDM_VIEWALL)
{
// Print name
cchLen = static_cast<DWORD>(_tcslen(pcd->strName));
if (FAILED(PrintLine(xName, yLine, pcd->strName, cchLen, lpInfo)))
return E_FAIL;
// Print No in value column
cchLen = static_cast<DWORD>(_tcslen(c_szNo));
if (FAILED(PrintLine(xVal, yLine, c_szNo, cchLen, lpInfo)))
return E_FAIL;
// Advance to next line on page
if (FAILED(PrintNextLine(lpInfo)))
return E_FAIL;
}
break;
}
}
else
{
char szBuff[c_maxPrintLine];
// Print name
sprintf_s(szBuff, sizeof(szBuff), pcd->strName, "test");
cchLen = static_cast<DWORD>(_tcslen(pcd->strName));
if (FAILED(PrintLine(xName, yLine, szBuff, cchLen, lpInfo)))
return E_FAIL;
// Print value
Int2Str(szBuff, c_maxPrintLine, dwValue);
cchLen = static_cast<DWORD>(_tcslen(szBuff));
if (FAILED(PrintLine(xVal, yLine, szBuff, cchLen, lpInfo)))
return E_FAIL;
// Advance to next line on page
if (FAILED(PrintNextLine(lpInfo)))
return E_FAIL;
}
pcd++; // Get next Cap bit definition
}
return S_OK;
}
//-----------------------------------------------------------------------------
void DXView_OnTreeSelect(HWND /*hwndTV*/, NM_TREEVIEW* ptv)
{
SendMessage(g_hwndLV, WM_SETREDRAW, FALSE, 0);
LVDeleteAllItems(g_hwndLV);
LVAddColumn(g_hwndLV, 0, "", 0);
NODEINFO* pni = nullptr;
if (!ptv)
{
TV_ITEM tvi = {};
// get lParam of current tree node
tvi.hItem = TreeView_GetSelection(g_hwndTV);
tvi.mask = TVIF_PARAM;
TreeView_GetItem(g_hwndTV, &tvi);
pni = (NODEINFO*)tvi.lParam;
}
else
{
pni = (NODEINFO*)ptv->itemNew.lParam;
}
if (pni && pni->fnDisplayCallback)
{
if (pni->bUseLParam3)
((DISPLAYCALLBACKEX)(pni->fnDisplayCallback))(pni->lParam1, pni->lParam2, pni->lParam3, nullptr);
else
pni->fnDisplayCallback(pni->lParam1, pni->lParam2, nullptr);
}
ListView_SetItemState(g_hwndLV, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
SendMessage(g_hwndLV, WM_SETREDRAW, TRUE, 0);
InvalidateRect(g_hwndLV, nullptr, TRUE);
}
//-----------------------------------------------------------------------------
void DXView_OnListViewDblClick(HWND hwndLV, NM_LISTVIEW *plv)
{
LV_ITEM lvi = {};
lvi.mask = LVIF_PARAM;
lvi.iItem = plv->iItem;
ListView_GetItem(hwndLV, &lvi);
}
//-----------------------------------------------------------------------------
void DXView_OnCommand(HWND hWnd, WPARAM wParam)
{
HMENU hMenu;
switch (LOWORD(wParam))
{
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)
{
strcpy_s((CHAR*)pGlobal, GlobalSize, g_szClip);
GlobalUnlock(hGlobal);
OpenClipboard(g_hwndMain);
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
}
}
}
break;
case IDM_ABOUT:
DialogBox(g_hInstance, "About", hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
}
}
//-----------------------------------------------------------------------------
void DXView_Cleanup()
{
DXGI_CleanUp();
DXG_CleanUp();
DD_CleanUp();
if (g_hImageList)
ImageList_Destroy(g_hImageList);