Skip to content

Commit

Permalink
release 1.5.5.beta.9
Browse files Browse the repository at this point in the history
修复微信、qq、钉钉打开选中文件,文件预览正确编码
  • Loading branch information
indiff committed Feb 14, 2023
1 parent cd38630 commit 47af9b5
Show file tree
Hide file tree
Showing 223 changed files with 59,172 additions and 1,109 deletions.
280 changes: 250 additions & 30 deletions BandObjectLib/BandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,33 @@


namespace BandObjectLib {
/// <summary>
/// https://docs.microsoft.com/en-us/windows/win32/shell/band-objects
/// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144099(v=vs.85)?redirectedfrom=MSDN
/// https://docs.microsoft.com/zh-cn/cpp/mfc/rebar-controls-and-bands?view=msvc-160
/// </summary>
public class BandObject :
UserControl,
IDeskBand,
IDockingWindow,
IInputObject,
IObjectWithSite,
IOleWindow,
IPersistStream,
IDpiAwareObject
IPersistStream
// , IDpiAwareObject
{
private Size _minSize = new Size(-1, -1);
/***
*
*
* // 垂直资源管理器栏 CATID_InfoBand
// 水平资源管理器栏 CATID_CommBand
// 桌带 CATID_DeskBand
*
*
*/
private Size minSize = new Size(16, 26);
private Size maxSize = new Size(-1, -1);

protected IInputObjectSite BandObjectSite;
protected WebBrowserClass Explorer;
protected bool fClosedDW;
Expand All @@ -54,6 +70,10 @@ public class BandObject :
protected const int E_NOTIMPL = -2147467263; // _HRESULT_TYPEDEF_(0x80004001L)
protected const int E_FAIL = -2147467259; // _HRESULT_TYPEDEF_(0x80004005L)

public static string ProcessName = Process.GetCurrentProcess().ProcessName;

internal static bool HostedNotByExplorer = (ProcessName != "explorer");

// 判断是否启用日志,发布改为false, 调试启用. 默认是关闭的,在常规选项里面可以设置启用
// public static bool ENABLE_LOGGER = true;

Expand Down Expand Up @@ -154,7 +174,7 @@ protected bool BandHasBreak() {
}
return true;
}

// virtual 关键字用于修改方法、属性、索引器或事件声明,并使它们可以在派生类中被重写。
public virtual void CloseDW(uint dwReserved) {
Util2.bandLog("CloseDW");
fClosedDW = true;
Expand All @@ -178,7 +198,126 @@ public virtual void CloseDW(uint dwReserved) {
public virtual void ContextSensitiveHelp(bool fEnterMode) {
}




private int bandID;
private bool fVertical;

public int BandID
{
get
{
return this.bandID;
}
}

/// <summary>
///
/// </summary>
/// <param name="dwBandID">容器分配的带的标识符。 如果需要,带区对象可以保留此值。</param>
/// <param name="dwViewMode">带对象的视图模式。 以下值之一:</param>
/// DBIF_VIEWMODE_NORMAL
/// 带状对象正在水平带中显示。
///
/// DBIF_VIEWMODE_VERTICAL
/// 带状对象显示在垂直带中。
///
/// DBIF_VIEWMODE_FLOATING
/// 带状对象正在浮动带中显示。
///
/// DBIF_VIEWMODE_TRANSPARENT
/// 带状对象正在透明带中显示。
/// <param name="pdbi">带对象的信息</param>
/// ptMinSize
///
/// 类型: POINTL
///
/// 接收带对象的最小大小的 POINTL 结构。 最小宽度在 POINTL 结构的 x 成员中给出,最小高度在 y 成员中给出。
///
/// ptMaxSize
///
/// 类型: POINTL
///
/// 一个 POINTL 结构,它接收带对象的最大大小。 POINTL 结构的 y 成员中提供了最大高度,x 成员将被忽略。 如果带对象对其最大高度没有限制,应使用 (LONG) -1。
///
/// ptIntegral
///
/// 类型: POINTL
///
/// 一个 POINTL 结构,它接收大小调整步骤值 (递增) ,其中调整了带对象的大小。 垂直步骤值在 POINTL 结构的 y 成员中 给出,x 成员将被忽略。
///
/// dwModeFlags 成员必须包含 DBIMF_VARIABLEHEIGHT 标志;否则,将忽略 ptIntegral。
///
/// ptActual
///
/// 类型: POINTL
///
/// 接收带对象的理想大小的 POINTL 结构。 理想宽度在 POINTL 结构的 x 成员中给出,理想高度在 y 成员中给出。 带容器尝试使用这些值,但无法保证波段大小为此大小。
///
/// wszTitle[256]
///
/// 类型: WCHAR[256]
///
/// 接收带标题的 WCHAR 缓冲区。
///
/// dwModeFlags
///
/// 类型:DWORD
///
/// 一个 值,该值接收一组指定 band 对象的操作模式的标志。 以下一个或多个值:
///
/// DBIMF_NORMAL
/// 带使用默认属性。 其他模式标志修改此标志。
///
/// DBIMF_FIXED
/// Windows XP 及更高版本: 带对象的大小和位置固定。 使用此标志时,不会在带对象上显示大小调整手柄。
///
/// DBIMF_FIXEDBMP
/// Windows XP 及更高版本: band 对象使用固定位图 (.bmp) 文件作为其背景。 请注意,并非所有情况下都支持背景,因此即使设置了此标志,也可能无法看到位图。
///
/// DBIMF_VARIABLEHEIGHT
/// 可以更改带对象的高度。 ptIntegral 成员定义可重设带对象大小的步骤值。
///
/// DBIMF_UNDELETEABLE
/// Windows XP 及更高版本: 无法从乐队容器中删除 band 对象。
///
/// DBIMF_DEBOSSED
/// 带对象以凹陷的外观显示。
///
/// DBIMF_BKCOLOR
/// 使用 crBkgnd 中指定的背景色显示带。
///
/// DBIMF_USECHEVRON
/// Windows XP 及更高版本: 如果无法显示 (即,带对象小于 ptActual,则会显示 V 形,以指示有更多的可用选项。 单击 V 形时会显示这些选项。
///
/// DBIMF_BREAK
/// Windows XP 及更高版本: 乐队对象显示在带容器中的新行中。
///
/// DBIMF_ADDTOFRONT
/// Windows XP 及更高版本: band 对象是乐队容器中的第一个对象。
///
/// DBIMF_TOPALIGN
/// Windows XP 及更高版本: band 对象显示在乐队容器的顶部行中。
///
/// DBIMF_NOGRIPPER
/// Windows Vista 及更高版本: 不会显示大小调整手柄,以允许用户移动或调整带对象的大小。
///
/// DBIMF_ALWAYSGRIPPER
/// Windows Vista 及更高版本: 始终显示允许用户移动乐队对象或调整其大小的大小手柄,即使该带对象是容器中唯一的一个。
///
/// DBIMF_NOMARGINS
/// Windows Vista 及更高版本: 带对象不应显示边距。
///
/// crBkgnd
///
/// 类型: COLORREF
///
/// 接收带的背景色的 COLORREF 结构。 dwModeFlags 成员必须包含 DBIMF_BKCOLOR 标志;否则,将忽略 crBkgnd。
public virtual void GetBandInfo(uint dwBandID, uint dwViewMode, ref DESKBANDINFO pdbi) {
this.bandID = (int) dwBandID;
this.fVertical = dwViewMode == 1U;

if((pdbi.dwMask & DBIM.ACTUAL) != 0) {
pdbi.ptActual.X = Size.Width;
pdbi.ptActual.Y = Size.Height;
Expand Down Expand Up @@ -218,11 +357,30 @@ private REBARBANDINFO GetRebarBand(int idx, int fMask) {
return info;
}

public virtual void GetSite(ref Guid riid, out object ppvSite) {
ppvSite = BandObjectSite;
public virtual int GetSite(ref Guid riid, out object ppvSite) {
try
{
if (this.BandObjectSite != null)
{
ppvSite = BandObjectSite;
// ppvSite = Marshal.GetIUnknownForObject((object)this.BandObjectSite);
return 0;
}
}
catch
{
}
// ppvSite = IntPtr.Zero;
ppvSite = null;
return -2147467259;
}

public virtual void GetWindow(out IntPtr phwnd) {
if (BandObject.HostedNotByExplorer)
{
phwnd = IntPtr.Zero;
return ;
}
phwnd = Handle;
}

Expand All @@ -234,6 +392,7 @@ public virtual int HasFocusIO() {
}

protected virtual void OnExplorerAttached() {
Util2.bandLog("BandObject");
}

protected override void OnGotFocus(EventArgs e) {
Expand All @@ -252,6 +411,12 @@ protected override void OnLostFocus(EventArgs e) {
}
}

/// <summary>
/// 通知停靠窗口对象框架的边框空间已更改。为了响应此方法,IDockingWindow 实现必须调用 SetBorderSpaceDW,即使不需要边框空间或不需要更改。
/// </summary>
/// <param name="prcBorder"></param>
/// <param name="punkToolbarSite"></param>
/// <param name="fReserved"></param>
public virtual void ResizeBorderDW(IntPtr prcBorder, object punkToolbarSite, bool fReserved) {
}

Expand All @@ -261,24 +426,42 @@ protected virtual bool ShouldHaveBreak() {
return true;
}

public virtual void SetSite(object pUnkSite) {
if(Process.GetCurrentProcess().ProcessName == "iexplore") {
public virtual int SetSite(object pUnkSite)
{
/*if(Process.GetCurrentProcess().ProcessName == "iexplore") {
Marshal.ThrowExceptionForHR(E_FAIL);
}
if(BandObjectSite != null) {
Marshal.ReleaseComObject(BandObjectSite);
}
if(Explorer != null) {
Marshal.ReleaseComObject(Explorer);
Explorer = null;
}
BandObjectSite = pUnkSite as IInputObjectSite;
if(BandObjectSite != null) {
Util2.bandLog("Marshal.ThrowExceptionForHR");
}*/

if (pUnkSite == null)
{
if (BandObjectSite != null )
{
Marshal.ReleaseComObject(BandObjectSite);
Util2.bandLog("Marshal.ReleaseComObject BandObjectSite");
this.BandObjectSite = null;
}
if (Explorer != null)
{
Marshal.ReleaseComObject(Explorer);
Explorer = null;
Util2.bandLog("Marshal.ReleaseComObject Explorer");
}
} else if (pUnkSite != null)
{
BandObjectSite = pUnkSite as IInputObjectSite;
try {
object obj2;
((_IServiceProvider)BandObjectSite).QueryService(ExplorerGUIDs.IID_IWebBrowserApp, ExplorerGUIDs.IID_IUnknown, out obj2);
((_IServiceProvider)BandObjectSite).QueryService(
ExplorerGUIDs.IID_IWebBrowserApp,
ExplorerGUIDs.IID_IUnknown,
out obj2);
Util2.bandLog("BandObjectSite.QueryService");
Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType(obj2 as IWebBrowser, typeof(WebBrowserClass));
Util2.bandLog("Marshal.CreateWrapperOfType");
OnExplorerAttached();
Util2.bandLog("OnExplorerAttached");
}
catch (COMException exception) { // exception
Util2.MakeErrorLog(exception, "QueryService CreateWrapperOfType");
Expand All @@ -295,6 +478,7 @@ public virtual void SetSite(object pUnkSite) {
Util2.MakeErrorLog(e, "BandObject SetSite");
// logger.Log(exc);
}
return 0;
}

public virtual void ShowDW(bool fShow) {
Expand Down Expand Up @@ -338,10 +522,22 @@ private void UnsetInfo() {

public Size MinSize {
get {
return _minSize;
return minSize;
}
set {
_minSize = value;
minSize = value;
}
}

protected Size MaxSize
{
get
{
return this.maxSize;
}
set
{
this.maxSize = value;
}
}

Expand Down Expand Up @@ -386,6 +582,7 @@ public float Scaling
}
}

/*
public void NotifyDpiChanged(int oldDpi, int dpiNew)
{
Util2.bandLog("BandObject NotifyDpiChanged oldDpi " + oldDpi + " dpiNew " + dpiNew);
Expand All @@ -403,27 +600,50 @@ public void NotifyDpiChanged(int oldDpi, int dpiNew)
act(cc);
}
}
/*.ForEach<Control>((Action<Control>)
(c =>
{
if (c is IDpiAwareObject )
((IDpiAwareObject)c).NotifyDpiChanged(oldDpi, dpiNew);
act(c);
})*/
);
act((Control) this);
this.OnDpiChanged(oldDpi, dpiNew);
}
}*/


protected virtual void OnDpiChanged(int oldDpi, int newDpi)
{
}

/*#region 新增区域 by indiff
public void RefreshRebarBand()
{
// REBARBANDINFO* lParam = stackalloc REBARBANDINFO[1];
REBARBANDINFO lParam = new REBARBANDINFO();
// lParam.cbSize = sizeof(REBARBANDINFO);
lParam.cbSize = Marshal.SizeOf(lParam);
lParam.fMask = 32;
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(lParam));
Marshal.StructureToPtr(lParam, ptr, false);
int wParam = (int)PInvoke.SendMessage(this.ReBarHandle, 1040, this.BandID, 0);
if (wParam == -1)
return;
// PInvoke.SendMessage(this.ReBarHandle, 1052, (IntPtr)wParam, ptr);
SendMessage(ReBarHandle, 1052, (IntPtr)wParam, ptr);
// PInvoke.SendMessage(this.Handle, RB.SETBANDINFOW, (void*)wParam, ref structure);
lParam.cyChild = this.fVertical ? this.Width : this.Height;
lParam.cyMinChild = this.fVertical ? this.Width : this.Height;
PInvoke.SendMessage(this.ReBarHandle, 1035, (IntPtr)wParam, ptr);
lParam = (REBARBANDINFO)Marshal.PtrToStructure(ptr, typeof(REBARBANDINFO));
Marshal.FreeHGlobal(ptr);
}
#endregion*/

/*protected override void OnPaintBackground(PaintEventArgs e)
{
}*/
}

internal class Util2
{
private const bool ENABLE_LOGGER = true;
private const bool ENABLE_LOGGER = false;


public static void bandLog(string optional)
Expand Down
Loading

0 comments on commit 47af9b5

Please sign in to comment.