|
Thank you.
Thanks
|
|
|
|
|
Right now the company I work for has three different Visual studio toolbox installation utilities to install the controls into each toolbox. I've taken it upon myself to, in my free time, combine these into a single utility. The obvious route (to me anyways, I could be wrong) is to use reflection and since I don't have much experience with using reflection I thought this would be a good time to learn.
The scenario is such: I'm developing this utility in VS2002 because it's the least common denominator.
For the VS2005 procedure I figured out how to instantiate the Solution2 part of the deal(I think):
<br />
DTE dte = (DTE)System.Activator.CreateInstance(System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0"),true);<br />
Console.WriteLine(dte.Version);<br />
string tmpFile = System.IO.Path.GetFileNameWithoutExtension(Path.GetTempFileName());<br />
string tmpDir = string.Format("{0}{1}", Path.GetTempPath(), tmpFile);<br />
Type t = assem.GetType("EnvDTE80.Solution2");<br />
MethodInfo mif = t.GetMethod("GetProjectTemplate",new Type[] {typeof(string),typeof(string)});<br />
object result = mif.Invoke(dte.Solution,new object[] {"WindowsApplication.zip","CSharp"});<br />
string templatePath = result.ToString();<br />
mif = t.GetMethod("AddFromTemplate",new Type[] {typeof(string),typeof(string),typeof(string),typeof(bool)});<br />
result = mif.Invoke(dte.Solution, new object[]{templatePath, tmpDir, tmpFile, false});<br />
is equivalent to:
<br />
Solution2 solution = DesignTimeEnvironment.Solution as Solution2;<br />
string templatePath = solution.GetProjectTemplate(projectTemplate, "CSharp");<br />
Project proj = solution.AddFromTemplate(templatePath, tmpDir, tmpFile, false);<br />
I know what the following code does, it grabs a handle to the toolbox of the designated instance of the DTE, you then use the property toolbox.toolboxtabs to search through the tabs a for a matching tab name and if it doesn't find it then create the tab name. It's the first two lines that I can't figure out.
EnvDTE.Window window = DesignTimeEnvironment.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);<br />
EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object;<br />
ToolBoxTab CurrentTab = null;<br />
foreach (ToolBoxTab tab in toolbox.ToolBoxTabs)<br />
{<br />
if (tab.Name == toolboxTabName)<br />
{<br />
CurrentTab = tab;<br />
break;<br />
}<br />
}<br />
if (CurrentTab == null)<br />
{<br />
CurrentTab = toolbox.ToolBoxTabs.Add(toolboxTabName);<br />
}<br />
EnvDTE.Window and EnvDTE.ToolBox are interfaces; I thought you couldn't instantiate an interface?
Also EnvDTE is not an instanced object per say but just the class, so how would I construct
similar code using reflection? I tried using a similar approach as I did above with getting the Solution2 but I've gotten nowhere with it. I just can't seem to wrap my head around how to get the handle to the toolbox and then utilize the toolboxtabs property.
I've a feeling this is deceptively simple and I'll be wearing the Code Project Dunce Hat later but I've been banging my head against this for a week or so now on and off and finally decided I need a more experienced person's input.
“I know that I am intelligent, because I know that I know nothing.” ~Socrates
|
|
|
|
|
I haven't worked with integrating into VS before, but I think I help explain some of the code. The first line:
EnvDTE.Window window = DesignTimeEnvironment.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
The class/interface DesignTimeEnvironment has a property called Windows (which I'm assuiming are the windows in the IDE). The type of the Windows property has a method called Item. This method takes a constant enumeration to determine which type of window to return.
Now the Item method is returning an interface (of EnvDTE.Window as you say). This doesn't mean the interface was instantiated. The IDE most likely has a class for the Toolbox window, but only exposes to external applications through the interface.
So to use reflection, you would need to get the Windows property (through GetProperty) then execute the Item method.
The same concept applies for the interface on the second line. Internally it's using a class, but only exposes it using the EnvDTE.ToolBox interface.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
OK this is getting frustrating. I've been experimenting with using triggers for a MSMQ project and thought I'd start with something simple. So I created a private queue on my machine, created a rule that would open an exe (calc.exe), applied it to a trigger on the queue and sent a message to it. Nothing. The message gets to the queue, but the trigger never fires. I've looked high and low for examples, found few, and tried to follow them, but the outcome is always the same, the trigger never seems to be fired.
Anyone have some experience with MSMQ Triggers? What is going wrong here?
only two letters away from being an asset
|
|
|
|
|
Do you have Triggering installed and started?
|
|
|
|
|
Wouldn't be able to add a trigger if not.
only two letters away from being an asset
|
|
|
|
|
Check your task manager. I suspect that Calc is being started up "invisible" under the Network Services user account.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You are correct, sir. Thanks. The examples, of course, didn't mention this possiblity.
Now to do something more useful.
only two letters away from being an asset
|
|
|
|
|
You're welcome. Those examples, they're really great aren't they?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello. I have this class that overloads the comparisson operator (== ). It is throwing me an overflow exception:
public class DataItem
{
private int _id;
...
public static bool operator== (DataItem item1, DataItem item2)
{
if (item1 != null && item2 != null)
return item1._id == item2._id;
else
return false;
}
public static bool operator!= (DataItem item1, DataItem item2)
{
return !(item1 == item2);
}
...
}
The problem is that in the operator== method, I validate that both items are not null, but (because of the comparisson of the object to null) it calls again the operator== method. So it seems that I cannot validate whether the objects are null or not. Anyone has an idea of what can I do about this?
Thanks in advance.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
|
Thanks!
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
i have a datagridview on a form the single operation i want is that when the data displayed on the gridview the gridview.enabled command must be false but i want the scroll bars to be active i have done the following code
datgridview1.enabled = false; but it also locks the scrollbars both vertical and horizontal i want that this must be active
sas
|
|
|
|
|
As you can see it doesn't work that way. What is it you are trying to accomplish?
only two letters away from being an asset
|
|
|
|
|
the problem i wanto solve is the datagridview must be locked but its vertical and horizontal scroll bars must be active
sas
|
|
|
|
|
What do you mean by locked? Don't allow the uses to edit it then.
only two letters away from being an asset
|
|
|
|
|
sir dont u understand my qestion its simple i have written the following code
datgridview1.enabled= false;
the problem is that the scroll bars are also disabled i want the scroll bars to be active
sas
|
|
|
|
|
sajid.salim.khan wrote: dont u understand my qestion
Apparently not.
Again, what is the desired outcome you are looking for? Do you want to display the datagrid to the user with the ability scroll, but without the ability to edit records?
If this isn't what you want, perhaps you need to take a few moments to think about it, and describe your problem better.
only two letters away from being an asset
|
|
|
|
|
I you want to display the datagrid to the user with the ability scroll, but without the ability to edit records
sas
|
|
|
|
|
Then don't put it in edit mode How much simpler can it be? What don't you understand?
only two letters away from being an asset
|
|
|
|
|
I look over some projects in CodeProject about creating FolderViev, FolderTreeView etc. in An "Explorer Style" and I see everywhere are used shell operations. Is that the only one way to do controls like this? Isn't there any simple method? Does C# and .Net provide owns classes and methods including shell instructions, or I have to write it always myself? And I have one mor questions: Is there any reason that everybody use shell to manage folders instead of using such C# classes like Directory[info], File[info] and others classes included in System.IO namespace?
|
|
|
|
|
Don't cross post in multiple forums.
Krecik_PL wrote: and I see everywhere are used shell operations. Is that the only one way to do controls like this?
What operations?? Perhaps you could point to an example?
Krecik_PL wrote: Isn't there any simple method? Does C# and .Net provide owns classes and methods including shell instructions,
Yes, everything under the System.IO namespace. But that also depends on what you mean by "shell instructions".
Krecik_PL wrote: Is there any reason that everybody use shell to manage folders
Because that "everyone" doesn't know what they're doing.
|
|
|
|
|
First of all I am sorry for crossing post. My mistake...
Dave Kreskowiak wrote: What operations??
For Exmaple Extracting icons from file system. I know there is System.Drawing.Icon.ExtractAssociatedIcon in .Net class but it takes icon only from file. What with folders and such virtual folders like "My Computer", "Desktop", disks, CD-ROM's etc? In article "C# File Browser" or "FilesListBox" autors use the shell to do this. Is there any other way?
Others samples are for expamle DragAndDrop support or System context menu used in Windows Explorer.
Dave Kreskowiak wrote: Because that "everyone" doesn't know what they're doing.
Saying "everyone" I don't mean all programers, but autors of some articles I look trough. Want you say that using the shell in C# is bad idea in some implements??
-- modified at 14:15 Monday 1st October, 2007
|
|
|
|
|
Krecik_PL wrote: For Exmaple Extracting icons from file system. I know there is System.Drawing.Icon.ExtractAssociatedIcon in .Net class but it takes icon only from file....Is there any other way?
The article you're talking about uses the Shell's API, not shelling out to another process, to grab the icons. No, there is no other way to do this.
Krecik_PL wrote: Dave Kreskowiak wrote:
Because that "everyone" doesn't know what they're doing.
Saying "everyone" I don't mean all programers, but autors of some articles I look trough. Want you say that using the shell in C# is bad idea in some implements??
I said this because I thought you were talking about shelling out to the command prompt to do things like rename files, copy files, doing whatever to files.
You didn't say anything about grabbing icons from anywhere.
|
|
|
|
|
You have right - I don't specify precisely my question - Shell's API is more adequate then shell instructions. I thought about more advenced operations provided by Shell's API to manage Windows namespaces.
Thanks for the answers...
|
|
|
|