Toolbox for controlling Virsual Studio .NET 2003 with an automated interface

xiaoxiao2021-03-06  78

Made a custom control of ASP.NET, I want to add these controls to the toolbox of Virsual Studio .Net 2003, I have seen MSDN, I have tried it my code, it is not good. It took a long time, I checked N multi-information, I know that the BUG of Virsual Studio .NET 2003, it was finally solved. The following is the source code, send it to avoid everyone to encounter the same problem is a waste time.

There are several lines of code in the middle, you will feel unnecessary, but if you don't, you will find it is not easy, experience, I hope to help everyone!

The main unit of the console program:

Using system;

Using envdte;

Namespace SupertoolboxCs

{

///

/// ClassMain's summary description.

///

Class Classmain

{

///

/// The main entry point for the application.

///

[Stathread]

Static void main (string [] args)

{

TYPE LATESTDTE = Type.gettypeFromProgId ("Visualstudio.dte");

Envdte.dte DTE = Activator.createInstance (LateStdte) as envdte.dte;

Messagefilter.register ();

IF (DTE! = null)

Installer.AddToolboxtab (DTE);

Messagefilter.revoke ();

}

}

Sealed Class Installer

{

Public static void addtoolboxtab (envdte.dte DTE)

{

IF (DTE == Null)

Return;

WINDOW WIN = DTE.Windows.Item (envdte.constants.vswindowkindtoolbox);

Toolbox Box = Win.Object As Toolbox;

IF (Box == Null)

Return;

Toolboxtabs Tabs = Box.Toolboxtabs;

IF (tabs == null)

Return;

Foreach (ToolboxTab T IN Tabs)

{

IF (t.name == tabname)

t.delete ();

}

Toolboxtab tab = tabs.add (tabname);

IF (tab == null)

Return;

DTE.ExecuteCommand ("View.PropertiesWindow", "")

Tab.activate ();

Tab.ToolboxItems.Item (1) .select ();

String fullpath = lookupsuperServerObjectFileName ();

IF (fullpath == "")

Return;

Tab.ToolboxItems.Add (@ "unused?", fullpath, vstoolboxItemFormat.vstoolboxItemFormator,;

System.Console.write ("Superlib Web Form Toolbox creates success!");

}

Private static string lookupsuperServerObjectFileName () {

String keyname = "";

Microsoft.win32.registryKey rk = microsoft.win32.registry.localmachine;

RK = rk.opensubKey (Keyname, FALSE);

IF (rk == null)

{

""; "

}

String fullpath = (string) rk.getValue (null);

FullPath = @ "/ superlib.serverObject.dll";

IF (! system.io.file.exism (fullpath))

{

""; "

}

Return Fullpath;

}

Private const string tabname = @ "superlib web form";

Private const string keyname = @ "Software / Microsoft / Visualstudio / 7.1 / askFOLDERS / SuperLibv2.4.2003";

}

}

MessageFilter class

Using system;

Using system.Runtime.InteropServices;

Namespace SupertoolboxCs

{

///

/// MessageFilter's summary description.

///

Public Class MessageFilter: IOleMessageFilter

{

Public static void register ()

{

IOleMessageFilter newfilter = new messagefilter ();

IoleMessageFilter oldfilter = null;

CoregisterMessageFilter (NewFilter, OUT FILTER);

}

Public static void revoke ()

{

IoleMessageFilter oldfilter = null;

CoregisterMessageFilter (Null, OUT FILTER);

}

//

// ioleMessageFilter IMPL

INT IOleMessageFilter.HandleIncomingCall (int dwcalltype, system.intptr htaskcaller, int dwtickcount, system.intptr lpinterfaceInfo)

{

System.Diagnostics.debug.writeline ("IOleMessageFilter :: HandleInCall");

Return 0; // servercall_ishandled

}

INT IOleMessageFilter.RetryrejectedCall (System.intptr Htaskcallee, int dwtickcount, int dwrejecttype)

{

System.Diagnostics.debug.writeline ("IOleMessageFilter :: Retryrejectagefill");

IF (dwrejecttype == 2) // servercall_retrylater

{

System.Diagnostics.debug.writeline ("Retry Call Later"); Return 99; // Retry Immediately if Return> = 0 & <100

}

Return -1; // Cancel Call

}

INT IOLMESSAGEFILTER.MESSAGEPENDING (System.intptr Htaskcallee, int dwtickcount, int dwpendingtype)

{

System.Diagnostics.debug.writeline ("IOleMessageFilter :: messagepending);

Return 2; // pendingmsg_waitdefprocess

}

//

// Implementation

[DLLIMPORT ("ole32.dll")]]]]]]]

Private Static Extern Int CoregisterMessageFilter (IOleMessagefilter Newfilter, Out IoleMessageFilter Oldfilter);

}

[ComImport (), GUID ("00 00 00 00 6 6 000000046"),

InterfacePeattribute (CominterFaceType.Interfaceisiunknown)]

Interface IoleMessageFilter // Delibelely Renamed to Avoid Confusion W / System.Windows.Forms.IMESSAGEFILTER

{

[Preservesig]

INT HandleIncomingCall

INT dwcalltype,

INTPTR HTASKCALLER,

INT dwtickcount,

INTPTR LPINTERFACEINFO);

[Preservesig]

int RETREJECTEDCALL

INTPTR HTASKCALLEE,

INT dwtickcount,

INT dwrejectType);

[Preservesig]

INT messagepending

INTPTR HTASKCALLEE,

INT dwtickcount,

INT dwpendingtype);

}

}

Also have the realization of VB.NET versions, not posted.

Need to send a message.

QQ: 12150367

Email: haozidong@126.com

http://www.playicq.com/dispdocnew.php?id=21417

Reference Blog:

Http://weblogs.asp.net/savanness/archive/2003/04/24/6012.aspx

http://weblogs.asp.net/savanness/archive/2003/04/15/5701.aspx

http://weblogs.asp.net/savanness/archive/2003/04/10/5352.aspx

http://weblogs.asp.net/savanness/archive/2003/03/18/4019.aspx

转载请注明原文地址:https://www.9cbs.com/read-108138.html

New Post(0)