📄 bandobject.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using SHDocVw;
using Microsoft.Win32;
namespace IEBand
{
/// <summary>
/// BandObject 的摘要说明。
/// </summary>
///
[Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
public class BandObject : System.Windows.Forms.UserControl, IInputObject, IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.LinkLabel llblHubdog;
private System.Windows.Forms.LinkLabel llblMagazine;
protected IInputObjectSite BandObjectSite;
public BandObject()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.llblHubdog = new System.Windows.Forms.LinkLabel();
this.llblMagazine = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// llblHubdog
//
this.llblHubdog.Dock = System.Windows.Forms.DockStyle.Top;
this.llblHubdog.Location = new System.Drawing.Point(0, 0);
this.llblHubdog.Name = "llblHubdog";
this.llblHubdog.Size = new System.Drawing.Size(176, 23);
this.llblHubdog.TabIndex = 0;
this.llblHubdog.TabStop = true;
this.llblHubdog.Text = "哈巴狗的小窝";
this.llblHubdog.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llblHubdog_LinkClicked);
//
// llblMagazine
//
this.llblMagazine.Dock = System.Windows.Forms.DockStyle.Top;
this.llblMagazine.Location = new System.Drawing.Point(0, 23);
this.llblMagazine.Name = "llblMagazine";
this.llblMagazine.Size = new System.Drawing.Size(176, 23);
this.llblMagazine.TabIndex = 1;
this.llblMagazine.TabStop = true;
this.llblMagazine.Text = "Sina";
this.llblMagazine.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llblMagazine_LinkClicked);
//
// BandObject
//
this.Controls.Add(this.llblMagazine);
this.Controls.Add(this.llblHubdog);
this.Name = "BandObject";
this.Size = new System.Drawing.Size(176, 216);
this.ResumeLayout(false);
}
#endregion
#region IInputObject 成员
public virtual void UIActivateIO(Int32 fActivate, ref MSG Msg)
{
if( fActivate != 0 )
{
Control ctrl = GetNextControl(this,true);//first
if( ModifierKeys == Keys.Shift )
ctrl = GetNextControl(ctrl,false );//last
if( ctrl != null ) ctrl.Select();
this.Focus();
}
}
public virtual Int32 HasFocusIO()
{
return this.ContainsFocus ? 0 : 1; //S_OK : S_FALSE;
}
public virtual Int32 TranslateAcceleratorIO(ref MSG msg)
{
if( msg.message == 0x100 )//WM_KEYDOWN
if( msg.wParam == (uint)Keys.Tab)//keys used by explorer to navigate from control to control
if( SelectNextControl(
ActiveControl, true, true, true, false ))
return 0;//S_OK
return 1;//S_FALSE
}
#endregion
#region IObjectWithSite 成员
protected WebBrowserClass Explorer;
public void SetSite(Object pUnkSite)
{
if( BandObjectSite != null )
Marshal.ReleaseComObject( BandObjectSite );
if( Explorer != null )
{
Marshal.ReleaseComObject( Explorer );
Explorer = null;
}
BandObjectSite = (IInputObjectSite)pUnkSite;
if( BandObjectSite != null )
{
//获取浏览器接口
_IServiceProvider sp = BandObjectSite as _IServiceProvider;
Guid guid = ExplorerGUIDs.IID_IWebBrowserApp;
Guid riid = ExplorerGUIDs.IID_IUnknown;
try
{
object w;
sp.QueryService( ref guid, ref riid, out w );
//一旦获得COM接口,就可以创建RCW以便使用
Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType(
w as IWebBrowser, typeof(WebBrowserClass));
}
catch( COMException )
{
}
}
}
public void GetSite(ref Guid riid, out Object ppvSite)
{
ppvSite = BandObjectSite; ;
}
#endregion
#region IDeskBand 成员
public void GetWindow(out IntPtr phwnd)
{
phwnd = Handle;
}
public void ContextSensitiveHelp(bool fEnterMode)
{
}
public virtual void ShowDW(bool fShow)
{
if( fShow )
Show();
else
Hide();
}
public virtual void CloseDW(UInt32 dwReserved)
{
Dispose( true );
}
public void ResizeBorderDW(IntPtr prcBorder, Object punkToolbarSite, bool fReserved)
{
}
public void GetBandInfo(UInt32 dwBandID, UInt32 dwViewMode, ref DESKBANDINFO pdbi)
{
pdbi.wszTitle = ".Net面板组件";
pdbi.ptActual.X = this.Width;
pdbi.ptActual.Y = this.Height;
//最大尺寸无限制
pdbi.ptMaxSize.X = -1;
pdbi.ptMaxSize.Y = -1;
//对于最小尺寸来说,窗体的最小宽度是窗体设计时的宽度
//因为当前是一个垂直面板,因此对高度不作限制
pdbi.ptMinSize.X = this.Width;
pdbi.ptMinSize.Y = -1;
//大小改变幅度都为1
pdbi.ptIntegral.X = 1;
pdbi.ptIntegral.Y = 1;
pdbi.dwModeFlags = DBIM.TITLE | DBIM.ACTUAL | DBIM.MAXSIZE | DBIM.MINSIZE | DBIM.INTEGRAL;
}
protected override void OnGotFocus(System.EventArgs e)
{
base.OnGotFocus(e);
BandObjectSite.OnFocusChangeIS(this, 1);
}
/// <summary>
/// Notifies explorer of focus change.
/// </summary>
protected override void OnLostFocus(System.EventArgs e)
{
base.OnLostFocus(e);
if( ActiveControl == null )
BandObjectSite.OnFocusChangeIS(this, 0);
}
#endregion
#region 组件注册与注销
[ComRegisterFunctionAttribute]
public static void Register(Type t)
{
string guid = t.GUID.ToString("B");
RegistryKey rkClass = Registry.ClassesRoot.CreateSubKey(@"CLSID\"+guid );
RegistryKey rkCat = rkClass.CreateSubKey("Implemented Categories");
string name = "IEBand";
string help = "IEBand";
rkClass.SetValue(null, name );
rkClass.SetValue("MenuText", name );
rkClass.SetValue("HelpText", help );
rkCat.CreateSubKey("{00021493-0000-0000-C000-000000000046}");
}
[ComUnregisterFunctionAttribute]
public static void Unregister(Type t)
{
string guid = t.GUID.ToString("B");
Registry.ClassesRoot.CreateSubKey(@"CLSID").DeleteSubKeyTree(guid);
}
#endregion
private void llblHubdog_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
object Flags=null;
object TargetFrameName=null;
object PostData=null;
object Headers=null;
Explorer.Navigate("http://hubdog.csdn.net",ref Flags, ref TargetFrameName,ref PostData,ref Headers);
}
private void llblMagazine_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
object Flags=null;
object TargetFrameName=null;
object PostData=null;
object Headers=null;
Explorer.Navigate("http://news.sina.com.cn",ref Flags, ref TargetFrameName,ref PostData,ref Headers);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -