-
Notifications
You must be signed in to change notification settings - Fork 1
/
uvcview.c
2153 lines (1727 loc) · 52.8 KB
/
uvcview.c
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
/*++
Copyright (c) 1997-2011 Microsoft Corporation
Module Name:
USBVIEW.C
Abstract:
This is the GUI goop for the USBVIEW application.
Environment:
user mode
Revision History:
04-25-97 : created
11-20-02 : minor changes to support more reporting options
04/13/2005 : major bug fixing
07/01/2008 : add UVC 1.1 support and move to Dev branch
--*/
/*****************************************************************************
I N C L U D E S
*****************************************************************************/
#include "resource.h"
#include "uvcview.h"
#include "h264.h"
#include "xmlhelper.h"
#include <commdlg.h>
/*****************************************************************************
D E F I N E S
*****************************************************************************/
// window control defines
//
#define SIZEBAR 0
#define WINDOWSCALEFACTOR 15
/*****************************************************************************
L O C A L T Y P E D E F S
*****************************************************************************/
typedef struct _TREEITEMINFO
{
struct _TREEITEMINFO *Next;
USHORT Depth;
PCHAR Name;
} TREEITEMINFO, *PTREEITEMINFO;
/*****************************************************************************
L O C A L E N U M S
*****************************************************************************/
typedef enum _USBVIEW_SAVE_FILE_TYPE
{
UsbViewNone = 0,
UsbViewXmlFile,
UsbViewTxtFile
} USBVIEW_SAVE_FILE_TYPE;
/*****************************************************************************
L O C A L F U N C T I O N P R O T O T Y P E S
*****************************************************************************/
int WINAPI
WinMain (
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpszCmdLine,
_In_ int nCmdShow
);
BOOL
CreateMainWindow (
int nCmdShow
);
VOID
ResizeWindows (
BOOL bSizeBar,
int BarLocation
);
LRESULT CALLBACK
MainDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
BOOL
USBView_OnInitDialog (
HWND hWnd,
HWND hWndFocus,
LPARAM lParam
);
VOID
USBView_OnClose (
HWND hWnd
);
VOID
USBView_OnCommand (
HWND hWnd,
int id,
HWND hwndCtl,
UINT codeNotify
);
VOID
USBView_OnLButtonDown (
HWND hWnd,
BOOL fDoubleClick,
int x,
int y,
UINT keyFlags
);
VOID
USBView_OnLButtonUp (
HWND hWnd,
int x,
int y,
UINT keyFlags
);
VOID
USBView_OnMouseMove (
HWND hWnd,
int x,
int y,
UINT keyFlags
);
VOID
USBView_OnSize (
HWND hWnd,
UINT state,
int cx,
int cy
);
LRESULT
USBView_OnNotify (
HWND hWnd,
int DlgItem,
LPNMHDR lpNMHdr
);
BOOL
USBView_OnDeviceChange (
HWND hwnd,
UINT uEvent,
DWORD dwEventData
);
VOID DestroyTree (VOID);
VOID RefreshTree (VOID);
LRESULT CALLBACK
AboutDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
VOID
WalkTree (
_In_ HTREEITEM hTreeItem,
_In_ LPFNTREECALLBACK lpfnTreeCallback,
_In_opt_ PVOID pContext
);
VOID
ExpandItem (
HWND hTreeWnd,
HTREEITEM hTreeItem,
PVOID pContext
);
VOID
AddItemInformationToFile(
HWND hTreeWnd,
HTREEITEM hTreeItem,
PVOID pContext
);
DWORD
DisplayLastError(
_Inout_updates_bytes_(count) char *szString,
int count);
VOID AddItemInformationToXmlView(
HWND hTreeWnd,
HTREEITEM hTreeItem,
PVOID pContext
);
HRESULT InitializeConsole();
VOID UnInitializeConsole();
BOOL IsStdOutFile();
VOID DisplayMessage(DWORD dwMsgId, ...);
VOID PrintString(LPTSTR lpszString);
LPTSTR WStringToAnsiString(LPWSTR lpwszString);
VOID WaitForKeyPress();
BOOL ProcessCommandLine();
HRESULT ProcessCommandSaveFile(LPTSTR szFileName, DWORD dwCreationDisposition, USBVIEW_SAVE_FILE_TYPE fileType);
HRESULT SaveAllInformationAsText(LPTSTR lpstrTextFileName, DWORD dwCreationDisposition);
HRESULT SaveAllInformationAsXml(LPTSTR lpstrTextFileName , DWORD dwCreationDisposition);
/*****************************************************************************
G L O B A L S
*****************************************************************************/
BOOL gDoConfigDesc = TRUE;
BOOL gDoAnnotation = TRUE;
BOOL gLogDebug = FALSE;
int TotalHubs = 0;
extern DEVICE_GUID_LIST gHubList;
extern DEVICE_GUID_LIST gDeviceList;
/*****************************************************************************
G L O B A L S P R I V A T E T O T H I S F I L E
*****************************************************************************/
HINSTANCE ghInstance = NULL;
HWND ghMainWnd = NULL;
HWND ghTreeWnd = NULL;
HWND ghEditWnd = NULL;
HWND ghStatusWnd = NULL;
HMENU ghMainMenu = NULL;
HTREEITEM ghTreeRoot = NULL;
HCURSOR ghSplitCursor = NULL;
HDEVNOTIFY gNotifyDevHandle = NULL;
HDEVNOTIFY gNotifyHubHandle = NULL;
HANDLE ghStdOut = NULL;
BOOL gbConsoleFile = FALSE;
BOOL gbConsoleInitialized = FALSE;
BOOL gbButtonDown = FALSE;
BOOL gDoAutoRefresh = TRUE;
int gBarLocation = 0;
int giGoodDevice = 0;
int giBadDevice = 0;
int giComputer = 0;
int giHub = 0;
int giNoDevice = 0;
int giGoodSsDevice = 0;
int giNoSsDevice = 0;
/*****************************************************************************
WinMain()
*****************************************************************************/
int WINAPI
WinMain (
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpszCmdLine,
_In_ int nCmdShow
)
{
MSG msg;
HACCEL hAccel;
int retStatus = 0;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpszCmdLine);
InitXmlHelper();
ghInstance = hInstance;
ghSplitCursor = LoadCursor(ghInstance,
MAKEINTRESOURCE(IDC_SPLIT));
if (!ghSplitCursor)
{
OOPS();
return retStatus;
}
hAccel = LoadAccelerators(ghInstance,
MAKEINTRESOURCE(IDACCEL));
if (!hAccel)
{
OOPS();
return retStatus;
}
if (!CreateTextBuffer())
{
return retStatus;
}
if (!ProcessCommandLine())
{
// There were no command line flags, open GUI
if (CreateMainWindow(nCmdShow))
{
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(ghMainWnd,
hAccel,
&msg) &&
!IsDialogMessage(ghMainWnd,
&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
retStatus = 1;
}
}
DestroyTextBuffer();
ReleaseXmlWriter();
CHECKFORLEAKS();
return retStatus;
}
/*****************************************************************************
ProcessCommandLine()
Parses the command line and takes appropriate actions. Returns FALSE If there is no action to
perform
*****************************************************************************/
BOOL ProcessCommandLine()
{
LPWSTR *szArgList = NULL;
LPTSTR szArg = NULL;
LPTSTR szAnsiArg= NULL;
BOOL quietMode = FALSE;
HRESULT hr = S_OK;
DWORD dwCreationDisposition = CREATE_NEW;
USBVIEW_SAVE_FILE_TYPE fileType = UsbViewNone;
int nArgs = 0;
int i = 0;
BOOL bStatus = FALSE;
BOOL bStopArgProcessing = FALSE;
szArgList = CommandLineToArgvW(GetCommandLineW(), &nArgs);
// If there are no arguments we return false
bStatus = (nArgs > 1)? TRUE:FALSE;
if (NULL != szArgList)
{
if (nArgs > 1)
{
// If there are arguments, initialize console for ouput
InitializeConsole();
}
for (i = 1; (i < nArgs) && (bStopArgProcessing == FALSE); i++)
{
// Convert argument to ANSI string for futher processing
szAnsiArg = WStringToAnsiString(szArgList[i]);
if(NULL == szAnsiArg)
{
DisplayMessage(IDS_USBVIEW_INVALIDARG, szAnsiArg);
DisplayMessage(IDS_USBVIEW_USAGE);
break;
}
if (0 == _stricmp(szAnsiArg, "/?"))
{
DisplayMessage(IDS_USBVIEW_USAGE);
break;
}
else if (NULL != StrStrI(szAnsiArg, "/saveall:"))
{
fileType = UsbViewTxtFile;
}
else if (NULL != StrStrI(szAnsiArg, "/savexml:"))
{
fileType = UsbViewXmlFile;
}
else if (0 == _stricmp(szAnsiArg, "/f"))
{
dwCreationDisposition = CREATE_ALWAYS;
}
else if (0 == _stricmp(szAnsiArg, "/q"))
{
quietMode = TRUE;
}
else
{
DisplayMessage(IDS_USBVIEW_INVALIDARG, szAnsiArg);
DisplayMessage(IDS_USBVIEW_USAGE);
bStopArgProcessing = TRUE;
}
if (fileType != UsbViewNone)
{
// Save view information as to file
szArg = strchr(szAnsiArg, ':');
if (NULL == szArg || strlen(szArg) == 1)
{
// No ':' or just a ':'
DisplayMessage(IDS_USBVIEW_INVALID_FILENAME, szAnsiArg);
DisplayMessage(IDS_USBVIEW_USAGE);
bStopArgProcessing = TRUE;
}
else
{
hr = ProcessCommandSaveFile(szArg + 1, dwCreationDisposition, fileType);
if (FAILED(hr))
{
// No more processing
bStopArgProcessing = TRUE;
}
fileType = UsbViewNone;
}
}
if (NULL != szAnsiArg)
{
LocalFree(szAnsiArg);
}
}
if(!quietMode)
{
WaitForKeyPress();
}
if (gbConsoleInitialized)
{
UnInitializeConsole();
}
LocalFree(szArgList);
}
return bStatus;
}
/*****************************************************************************
ProcessCommandSaveFile()
Process the save file command line
*****************************************************************************/
HRESULT ProcessCommandSaveFile(LPTSTR szFileName, DWORD dwCreationDisposition, USBVIEW_SAVE_FILE_TYPE fileType)
{
HRESULT hr = S_OK;
LPTSTR szErrorBuffer = NULL;
if (UsbViewNone == fileType || NULL == szFileName)
{
hr = E_INVALIDARG;
// Invalid arguments, return
return (hr);
}
// The UI is not created yet, open the UI, but HIDE it
CreateMainWindow(SW_HIDE);
if (UsbViewXmlFile == fileType)
{
hr = SaveAllInformationAsXml(szFileName, dwCreationDisposition);
}
if (UsbViewTxtFile == fileType)
{
hr = SaveAllInformationAsText(szFileName, dwCreationDisposition);
}
if (FAILED(hr))
{
if (GetLastError() == ERROR_FILE_EXISTS || hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS))
{
// The operation failed because the file we tried to write to already existed and '/f' option
// was not present. Display error message to user describing '/f' option
switch(fileType)
{
case UsbViewXmlFile:
DisplayMessage(IDS_USBVIEW_FILE_EXISTS_XML, szFileName);
break;
case UsbViewTxtFile:
DisplayMessage(IDS_USBVIEW_FILE_EXISTS_TXT, szFileName);
break;
default:
DisplayMessage(IDS_USBVIEW_INTERNAL_ERROR);
break;
}
}
else
{
// Try to obtain system error message
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &szErrorBuffer, // FormatMessage expects this buffer to be cast as LPTSTR
0,
NULL);
PrintString("Unable to save file.\n");
PrintString(szErrorBuffer);
LocalFree(szErrorBuffer);
}
}
else
{
// Display file saved to message in console
DisplayMessage(IDS_USBVIEW_SAVED_TO, szFileName);
}
return (hr);
}
/*****************************************************************************
InitializeConsole()
Initializes the std output in console
*****************************************************************************/
HRESULT InitializeConsole()
{
HRESULT hr = S_OK;
SetLastError(0);
// Find if STD_OUTPUT is a console or has been redirected to a File
gbConsoleFile = IsStdOutFile();
if (!gbConsoleFile)
{
// Output is not redirected and GUI application do not have console by default, create a console
if(AllocConsole())
{
#pragma warning(disable:4996) // We don' need the FILE * returned by freopen
// Reopen STDOUT , STDIN and STDERR
if((freopen("conout$", "w", stdout) != NULL) &&
(freopen("conin$", "r", stdin) != NULL) &&
(freopen("conout$","w", stderr) != NULL))
{
gbConsoleInitialized = TRUE;
ghStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
}
#pragma warning(default:4996)
}
}
if (INVALID_HANDLE_VALUE == ghStdOut || FALSE == gbConsoleInitialized)
{
hr = HRESULT_FROM_WIN32(GetLastError());
OOPS();
}
return hr;
}
/*****************************************************************************
UnInitializeConsole()
UnInitializes the console
*****************************************************************************/
VOID UnInitializeConsole()
{
gbConsoleInitialized = FALSE;
FreeConsole();
}
/*****************************************************************************
IsStdOutFile()
Finds if the STD_OUTPUT has been redirected to a file
*****************************************************************************/
BOOL IsStdOutFile()
{
unsigned htype;
HANDLE hFile;
// 1 = STDOUT
hFile = (HANDLE) _get_osfhandle(1);
htype = GetFileType(hFile);
htype &= ~FILE_TYPE_REMOTE;
// Check if file type is character file
if (FILE_TYPE_DISK == htype)
{
return TRUE;
}
return FALSE;
}
/*****************************************************************************
DisplayMessage()
Displays a message to standard output
*****************************************************************************/
VOID DisplayMessage(DWORD dwResId, ...)
{
CHAR szFormat[4096];
HRESULT hr = S_OK;
LPTSTR lpszMessage = NULL;
DWORD dwLen = 0;
va_list ap;
va_start(ap, dwResId);
// Initialize console if needed
if (!gbConsoleInitialized)
{
hr = InitializeConsole();
if (FAILED(hr))
{
OOPS();
return;
}
}
// Load the string resource
dwLen = LoadString(GetModuleHandle(NULL),
dwResId,
szFormat,
ARRAYSIZE(szFormat)
);
if(0 == dwLen)
{
PrintString("Unable to find message for given resource ID");
// Return if resource ID could not be found
return;
}
dwLen = FormatMessage(
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
szFormat,
dwResId,
0,
(LPTSTR) &lpszMessage,
ARRAYSIZE(szFormat),
&ap);
if (dwLen > 0)
{
PrintString(lpszMessage);
LocalFree(lpszMessage);
}
else
{
PrintString("Unable to find message for given ID");
}
va_end(ap);
return;
}
/*****************************************************************************
WStringToAnsiString()
Converts the Wide char string to ANSI string and returns the allocated ANSI string.
*****************************************************************************/
LPTSTR WStringToAnsiString(LPWSTR lpwszString)
{
int strLen = 0;
LPTSTR szAnsiBuffer = NULL;
szAnsiBuffer = LocalAlloc(LPTR, (MAX_PATH + 1) * sizeof(CHAR));
// Convert string from from WCHAR to ANSI
if (NULL != szAnsiBuffer)
{
strLen = WideCharToMultiByte(
CP_ACP,
0,
lpwszString,
-1,
szAnsiBuffer,
MAX_PATH + 1,
NULL,
NULL);
if (strLen > 0)
{
return szAnsiBuffer;
}
}
return NULL;
}
/*****************************************************************************
PrintString()
Displays a string to standard output
*****************************************************************************/
VOID PrintString(LPTSTR lpszString)
{
DWORD dwBytesWritten = 0;
size_t Len = 0;
LPSTR lpOemString = NULL;
if (INVALID_HANDLE_VALUE == ghStdOut || NULL == lpszString)
{
OOPS();
// Return if invalid inputs
return;
}
if (FAILED(StringCchLength(lpszString, OUTPUT_MESSAGE_MAX_LENGTH, &Len)))
{
OOPS();
// Return if string is too long
return;
}
if (gbConsoleFile)
{
// Console has been redirected to a file, ex: `usbview /savexml:xx > test.txt`. We need to use WriteFile instead of
// WriteConsole for text output.
lpOemString = (LPSTR) LocalAlloc(LPTR, (Len + 1) * sizeof(CHAR));
if (lpOemString != NULL)
{
if (CharToOemBuff(lpszString, lpOemString, (DWORD) Len))
{
WriteFile(ghStdOut, (LPVOID) lpOemString, (DWORD) Len, &dwBytesWritten, NULL);
}
else
{
OOPS();
}
}
}
else
{
// Write to std out in console
WriteConsole(ghStdOut, (LPVOID) lpszString, (DWORD) Len, &dwBytesWritten, NULL);
}
return;
}
/*****************************************************************************
WaitForKeyPress()
Waits for key press in case of console
*****************************************************************************/
VOID WaitForKeyPress()
{
// Wait for key press if console
if (!gbConsoleFile && gbConsoleInitialized)
{
DisplayMessage(IDS_USBVIEW_PRESSKEY);
(VOID) _getch();
}
return;
}
/*****************************************************************************
CreateMainWindow()
*****************************************************************************/
BOOL
CreateMainWindow (
int nCmdShow
)
{
RECT rc;
InitCommonControls();
ghMainWnd = CreateDialog(ghInstance,
MAKEINTRESOURCE(IDD_MAINDIALOG),
NULL,
(DLGPROC) MainDlgProc);
if (ghMainWnd == NULL)
{
OOPS();
return FALSE;
}
GetWindowRect(ghMainWnd, &rc);
gBarLocation = (rc.right - rc.left) / 3;
ResizeWindows(FALSE, 0);
ShowWindow(ghMainWnd, nCmdShow);
UpdateWindow(ghMainWnd);
return TRUE;
}
/*****************************************************************************
ResizeWindows()
Handles resizing the two child windows of the main window. If
bSizeBar is true, then the sizing is happening because the user is
moving the bar. If bSizeBar is false, the sizing is happening
because of the WM_SIZE or something like that.
*****************************************************************************/
VOID
ResizeWindows (
BOOL bSizeBar,
int BarLocation
)
{
RECT MainClientRect;
RECT MainWindowRect;
RECT TreeWindowRect;
RECT StatusWindowRect;
int right;
// Is the user moving the bar?
//
if (!bSizeBar)
{
BarLocation = gBarLocation;
}
GetClientRect(ghMainWnd, &MainClientRect);
GetWindowRect(ghStatusWnd, &StatusWindowRect);
// Make sure the bar is in a OK location
//
if (bSizeBar)
{
if (BarLocation <
GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
{
return;
}
if ((MainClientRect.right - BarLocation) <
GetSystemMetrics(SM_CXSCREEN)/WINDOWSCALEFACTOR)
{
return;
}
}
// Save the bar location
//
gBarLocation = BarLocation;
// Move the tree window
//
MoveWindow(ghTreeWnd,
0,
0,
BarLocation,
MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
TRUE);
// Get the size of the window (in case move window failed
//
GetWindowRect(ghTreeWnd, &TreeWindowRect);
GetWindowRect(ghMainWnd, &MainWindowRect);
right = TreeWindowRect.right - MainWindowRect.left;
// Move the edit window with respect to the tree window
//
MoveWindow(ghEditWnd,
right+SIZEBAR,
0,
MainClientRect.right-(right+SIZEBAR),
MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
TRUE);
// Move the Status window with respect to the tree window
//
MoveWindow(ghStatusWnd,
0,
MainClientRect.bottom - StatusWindowRect.bottom + StatusWindowRect.top,
MainClientRect.right,
StatusWindowRect.bottom - StatusWindowRect.top,
TRUE);
}
/*****************************************************************************
MainWndProc()
*****************************************************************************/
LRESULT CALLBACK
MainDlgProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, USBView_OnInitDialog);
HANDLE_MSG(hWnd, WM_CLOSE, USBView_OnClose);
HANDLE_MSG(hWnd, WM_COMMAND, USBView_OnCommand);
HANDLE_MSG(hWnd, WM_LBUTTONDOWN, USBView_OnLButtonDown);
HANDLE_MSG(hWnd, WM_LBUTTONUP, USBView_OnLButtonUp);
HANDLE_MSG(hWnd, WM_MOUSEMOVE, USBView_OnMouseMove);
HANDLE_MSG(hWnd, WM_SIZE, USBView_OnSize);
HANDLE_MSG(hWnd, WM_NOTIFY, USBView_OnNotify);
HANDLE_MSG(hWnd, WM_DEVICECHANGE, USBView_OnDeviceChange);
}
return 0;
}
/*****************************************************************************
USBView_OnInitDialog()
*****************************************************************************/
BOOL
USBView_OnInitDialog (
HWND hWnd,
HWND hWndFocus,
LPARAM lParam
)
{
HFONT hFont;
HIMAGELIST himl;
HICON hicon;
DEV_BROADCAST_DEVICEINTERFACE broadcastInterface;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(hWndFocus);
// Register to receive notification when a USB device is plugged in.
broadcastInterface.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
broadcastInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
memcpy( &(broadcastInterface.dbcc_classguid),
&(GUID_DEVINTERFACE_USB_DEVICE),
sizeof(struct _GUID));
gNotifyDevHandle = RegisterDeviceNotification(hWnd,
&broadcastInterface,
DEVICE_NOTIFY_WINDOW_HANDLE);
// Now register for Hub notifications.
memcpy( &(broadcastInterface.dbcc_classguid),
&(GUID_CLASS_USBHUB),
sizeof(struct _GUID));
gNotifyHubHandle = RegisterDeviceNotification(hWnd,
&broadcastInterface,
DEVICE_NOTIFY_WINDOW_HANDLE);
gHubList.DeviceInfo = INVALID_HANDLE_VALUE;