1
1
// This file is part of QTTabBar, a shell extension for Microsoft
2
2
// Windows Explorer.
3
- // Copyright (C) 2002-2010 Pavel Zolnikov, Quizo, Paul Accisano
3
+ // Copyright (C) 2002-2022 Pavel Zolnikov, Quizo, Paul Accisano, indiff
4
4
//
5
5
// QTTabBar is free software: you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
20
20
using System . Drawing ;
21
21
using System . IO ;
22
22
using System . Runtime . InteropServices ;
23
+ using System . Text ;
24
+ using System . Threading ;
23
25
using System . Windows . Forms ;
24
26
using SHDocVw ;
25
27
26
28
27
29
namespace BandObjectLib {
28
- public class BandObject : UserControl , IDeskBand , IDockingWindow , IInputObject , IObjectWithSite , IOleWindow , IPersistStream {
30
+ public class BandObject :
31
+ UserControl ,
32
+ IDeskBand ,
33
+ IDockingWindow ,
34
+ IInputObject ,
35
+ IObjectWithSite ,
36
+ IOleWindow ,
37
+ IPersistStream ,
38
+ IDpiAwareObject
39
+ {
29
40
private Size _minSize = new Size ( - 1 , - 1 ) ;
30
41
protected IInputObjectSite BandObjectSite ;
31
42
protected WebBrowserClass Explorer ;
@@ -43,6 +54,9 @@ public class BandObject : UserControl, IDeskBand, IDockingWindow, IInputObject,
43
54
protected const int E_NOTIMPL = - 2147467263 ; // _HRESULT_TYPEDEF_(0x80004001L)
44
55
protected const int E_FAIL = - 2147467259 ; // _HRESULT_TYPEDEF_(0x80004005L)
45
56
57
+ // 判断是否启用日志,发布改为false, 调试启用. 默认是关闭的,在常规选项里面可以设置启用
58
+ // public static bool ENABLE_LOGGER = true;
59
+
46
60
// We must subclass the rebar in order to fix a certain bug in
47
61
// Windows 7.
48
62
internal sealed class RebarBreakFixer : NativeWindow {
@@ -58,6 +72,7 @@ public RebarBreakFixer(IntPtr hwnd, BandObject parent) {
58
72
}
59
73
60
74
protected override void WndProc ( ref Message m ) {
75
+ // bandLog("WndProc");
61
76
if ( ! Enabled ) {
62
77
base . WndProc ( ref m ) ;
63
78
return ;
@@ -67,9 +82,9 @@ protected override void WndProc(ref Message m) {
67
82
// RBBS_BREAK set. Catch RB_SETBANDINFO to fix this.
68
83
if ( m . Msg == RB . SETBANDINFO ) {
69
84
if ( MonitorSetInfo ) {
85
+ Util2 . bandLog ( "msg SETBANDINFO" ) ;
70
86
REBARBANDINFO pInfo = ( REBARBANDINFO ) Marshal . PtrToStructure ( m . LParam , typeof ( REBARBANDINFO ) ) ;
71
87
if ( pInfo . hwndChild == parent . Handle && ( pInfo . fMask & RBBIM . STYLE ) != 0 ) {
72
-
73
88
// Ask the bar if we actually want a break.
74
89
if ( parent . ShouldHaveBreak ( ) ) {
75
90
pInfo . fStyle |= RBBS . BREAK ;
@@ -84,6 +99,7 @@ protected override void WndProc(ref Message m) {
84
99
// Whenever a band is deleted, the RBBS_BREAKs come back!
85
100
// Catch RB_DELETEBAND to fix it.
86
101
else if ( m . Msg == RB . DELETEBAND ) {
102
+ Util2 . bandLog ( "msg DELETEBAND" ) ;
87
103
int del = ( int ) m . WParam ;
88
104
89
105
// Look for our band
@@ -140,10 +156,12 @@ protected bool BandHasBreak() {
140
156
}
141
157
142
158
public virtual void CloseDW ( uint dwReserved ) {
159
+ Util2 . bandLog ( "CloseDW" ) ;
143
160
fClosedDW = true ;
144
161
ShowDW ( false ) ;
145
162
Dispose ( true ) ;
146
163
if ( Explorer != null ) {
164
+ // Util2.bandLog("ReleaseComObject Explorer");
147
165
Marshal . ReleaseComObject ( Explorer ) ;
148
166
Explorer = null ;
149
167
}
@@ -188,6 +206,7 @@ public virtual void GetBandInfo(uint dwBandID, uint dwViewMode, ref DESKBANDINFO
188
206
}
189
207
190
208
private REBARBANDINFO GetRebarBand ( int idx , int fMask ) {
209
+ Util2 . bandLog ( "GetRebarBand" ) ;
191
210
REBARBANDINFO info = new REBARBANDINFO ( ) ;
192
211
info . cbSize = Marshal . SizeOf ( info ) ;
193
212
info . fMask = fMask ;
@@ -220,13 +239,15 @@ protected virtual void OnExplorerAttached() {
220
239
protected override void OnGotFocus ( EventArgs e ) {
221
240
base . OnGotFocus ( e ) ;
222
241
if ( ( ! fClosedDW && ( BandObjectSite != null ) ) && IsHandleCreated ) {
242
+ Util2 . bandLog ( "OnGotFocus" ) ;
223
243
BandObjectSite . OnFocusChangeIS ( this , 1 ) ;
224
244
}
225
245
}
226
246
227
247
protected override void OnLostFocus ( EventArgs e ) {
228
248
base . OnLostFocus ( e ) ;
229
249
if ( ( ! fClosedDW && ( BandObjectSite != null ) ) && ( ActiveControl == null ) ) {
250
+ Util2 . bandLog ( "OnLostFocus" ) ;
230
251
BandObjectSite . OnFocusChangeIS ( this , 0 ) ;
231
252
}
232
253
}
@@ -259,9 +280,8 @@ public virtual void SetSite(object pUnkSite) {
259
280
Explorer = ( WebBrowserClass ) Marshal . CreateWrapperOfType ( obj2 as IWebBrowser , typeof ( WebBrowserClass ) ) ;
260
281
OnExplorerAttached ( ) ;
261
282
}
262
- catch {
263
- // (COMException exception) { // exception
264
- // QTUtility2.MakeErrorLog(exception, "MSG:" + exception.Message);
283
+ catch ( COMException exception ) { // exception
284
+ Util2 . MakeErrorLog ( exception , "QueryService CreateWrapperOfType" ) ;
265
285
}
266
286
}
267
287
try {
@@ -270,8 +290,9 @@ public virtual void SetSite(object pUnkSite) {
270
290
window . GetWindow ( out ReBarHandle ) ;
271
291
}
272
292
}
273
- catch ( Exception ) // exc
293
+ catch ( Exception e ) // exc
274
294
{
295
+ Util2 . MakeErrorLog ( e , "BandObject SetSite" ) ;
275
296
// logger.Log(exc);
276
297
}
277
298
}
@@ -343,10 +364,136 @@ public virtual int GetSizeMax(out ulong pcbSize) {
343
364
pcbSize = 0 ;
344
365
return E_NOTIMPL ;
345
366
}
367
+
368
+ private void InitializeComponent ( )
369
+ {
370
+ this . SuspendLayout ( ) ;
371
+ //
372
+ // BandObject
373
+ //
374
+ this . ForeColor = System . Drawing . Color . Black ;
375
+ this . Name = "BandObject" ;
376
+ this . ResumeLayout ( false ) ;
377
+ }
378
+
379
+ public int Dpi { get ; private set ; }
380
+
381
+ public float Scaling
382
+ {
383
+ get
384
+ {
385
+ return ( float ) this . Dpi / 96f ;
386
+ }
387
+ }
388
+
389
+ public void NotifyDpiChanged ( int oldDpi , int dpiNew )
390
+ {
391
+ Util2 . bandLog ( "BandObject NotifyDpiChanged oldDpi " + oldDpi + " dpiNew " + dpiNew ) ;
392
+ this . Dpi = dpiNew ;
393
+ Action < Control > act = ( Action < Control > ) null ;
394
+ act = ( Action < Control > ) (
395
+ control =>
396
+ {
397
+ for ( var i = 0 ; i < control . Controls . Count ; i ++ )
398
+ {
399
+ var cc = ( Control ) control . Controls [ i ] ;
400
+
401
+ if ( cc is IDpiAwareObject )
402
+ ( ( IDpiAwareObject ) cc ) . NotifyDpiChanged ( oldDpi , dpiNew ) ;
403
+ act ( cc ) ;
404
+ }
405
+ }
406
+ /*.ForEach<Control>((Action<Control>)
407
+ (c =>
408
+ {
409
+ if (c is IDpiAwareObject )
410
+ ((IDpiAwareObject)c).NotifyDpiChanged(oldDpi, dpiNew);
411
+ act(c);
412
+ })*/
413
+ ) ;
414
+ act ( ( Control ) this ) ;
415
+ this . OnDpiChanged ( oldDpi , dpiNew ) ;
416
+ }
417
+
418
+
419
+ protected virtual void OnDpiChanged ( int oldDpi , int newDpi )
420
+ {
421
+ }
346
422
}
347
423
348
- /* internal class QTUtility2
424
+ internal class Util2
349
425
{
426
+ private const bool ENABLE_LOGGER = true ;
427
+
428
+
429
+ public static void bandLog ( string optional )
430
+ {
431
+ if ( ENABLE_LOGGER )
432
+ bandLog ( "bandLog" , optional ) ;
433
+ }
434
+
435
+
436
+
437
+ public static void err ( string optional )
438
+ {
439
+ if ( ENABLE_LOGGER )
440
+ bandLog ( "err" , optional ) ;
441
+
442
+ }
443
+
444
+ private static void writeStr ( string path , StringBuilder formatLogLine )
445
+ {
446
+ using ( StreamWriter writer = new StreamWriter ( path , true ) )
447
+ {
448
+ writer . WriteLine ( formatLogLine ) ;
449
+ }
450
+ }
451
+
452
+ public static void bandLog ( string level , string optional )
453
+ {
454
+ string appdata = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
455
+ string appdataQT = Path . Combine ( appdata , "QTTabBar" ) ;
456
+ if ( ! Directory . Exists ( appdataQT ) )
457
+ {
458
+ Directory . CreateDirectory ( appdataQT ) ;
459
+ }
460
+
461
+ Process process = Process . GetCurrentProcess ( ) ;
462
+ var cThreadId = Thread . CurrentThread . ManagedThreadId ;
463
+ var currentThreadId = AppDomain . GetCurrentThreadId ( ) ;
464
+
465
+ string path = Path . Combine ( appdataQT , "bandLog.log" ) ;
466
+ var formatLogLine = new StringBuilder ( ) ;
467
+ formatLogLine
468
+ . Append ( "[" )
469
+ . Append ( level )
470
+ . Append ( "]" ) ;
471
+ if ( process != null )
472
+ {
473
+ formatLogLine
474
+ . Append ( " PID:" )
475
+ . Append ( process . Id ) ;
476
+ }
477
+ if ( cThreadId != null )
478
+ {
479
+ formatLogLine
480
+ . Append ( " TID:" )
481
+ . Append ( cThreadId ) ;
482
+ }
483
+ else if ( currentThreadId != null )
484
+ {
485
+ formatLogLine
486
+ . Append ( " TID:" )
487
+ . Append ( currentThreadId ) ;
488
+ }
489
+ formatLogLine
490
+ . Append ( " " )
491
+ . Append ( DateTime . Now . ToString ( ) )
492
+ . Append ( " " )
493
+ . Append ( optional ) ;
494
+ writeStr ( path , formatLogLine ) ;
495
+ }
496
+
350
497
internal static void MakeErrorLog ( Exception ex , string optional = null )
351
498
{
352
499
try
@@ -357,7 +504,8 @@ internal static void MakeErrorLog(Exception ex, string optional = null)
357
504
{
358
505
Directory . CreateDirectory ( appdataQT ) ;
359
506
}
360
- string path = Path.Combine(appdataQT, "QTTabBarException.log");
507
+ // string path = Path.Combine(appdataQT, "QTTabBarBandObject.bandLog");
508
+ string path = Path . Combine ( appdataQT , "QTTabBarBandObjectException.log" ) ;
361
509
using ( StreamWriter writer = new StreamWriter ( path , true ) )
362
510
{
363
511
writer . WriteLine ( DateTime . Now . ToString ( ) ) ;
@@ -398,5 +546,5 @@ internal static void MakeErrorLog(Exception ex, string optional = null)
398
546
{
399
547
}
400
548
}
401
- }*/
549
+ }
402
550
}
0 commit comments