How can i add a button to all windows explorer instances? - c#

I am trying to add a button to one of the existing tool bars in any windows explorer instance.
After much research i figured out that BHO (browser helper objects) are the best way to hook
to windows explorer.
My question is :
Is that the correct way to go about it ?
In the SetSite of the BHO i get the comObject that is the explorer window. What now ?
If i can get the hWnd of the explorer window can i use win API to add my button ?
Note i am developing in C# for XP.
Thanks.

1 In pre-XP you can add custom items in the default folder template because the folder window is actually a webpage. In XP and later that is no longer true. A Deskband is the supported way to extend the UI.
2 The site is the same. You can even sink DWebBrowserEvents2 to get notified when the folder view is ready.
3 using window functions on explorer is not supported. The supported way to customize the explorer is to create deskbands. it is theoretically possible if you have the resource to test your code against each and every version of Windows Explorer used by your client audience and continue to do compatibility testing when each new version (or new language) of explorer.exe is released.
BHO can not add deskband. If you want to start BHO and deskband programming, look at Paul DiLascia's article "My Band is Your Band" in the November 1999 issue of MSJ. There is another article "Building Browser Helper Objects with Visual Studio 2005" in MSDN for BHO. Basically you need to handle the DocumentComplete and BeforeNavigate events and be careful not to access the folder view when the document is not ready. You can use any communication method that you see fit between your BHO and your deskband, such as hidden window with special window class, static variable if the two are in the same dll, shared memory, named pipe, etc.
Microsoft does not support creating In-Process extensions in managed code until .Net 4.0

Related

How to get opened FileDialog references in WPF/Winforms/C#?

I'm trying to build an app that synchronizes a FileDialog to a specific path. I'm not opening the FileDialog myself, I need access to "all the currently opened FileDialogs", get a reference to the one I need and then change the currentworkingdirectory. Is there an API to get all opened filedialogs in Windows?
If you need a better explanation, here's a video of the feature I'm trying to implement: https://www.youtube.com/watch?v=9T9-OtRVeUw
Thanks!
“Is there an API to get all opened filedialogs in Windows?” No, because there is not just one in-box file dialog, and many applications use custom implementations (e.g.: Java, qt, Office 2016+).
The video you posted looks like they are hooking or subclassing the most common dialog and (probably) using automation (either COM or window messages) to set the folder.
Separately, I don’t quite understand the desired function. If you have the explorer window open, drag or copy/paste the desired file into the app or file dialog. No need for nonstandard hacks.

Custom search tab in Windows start menu search with C#

I am interested to know how can I do the same thing that the apllication listed below does:
Start Menu Calculator
I want to know how can I create an custom tab in Start Menu Search and then handle it with my WPF application. It should only be enabled until my application is running.( Just like what The calculator does )
I read something about windows API Code Pack and I downloaded it but I don't know how can I use it. I searched through it but I didn't find anything.( If you know how I could do this using with Windows API Code Pack, please write an example that explains how to do it in C#)
The main exe "Start Menu Calculator.exe" installs a windows hook (using SetWindowsHookEx) into explorer.exe. The hook is implemented as usual in SBLib.dll which is then injected into Windows Explorer's memory space.
This hook searches for window handles belonging to the search box. See a discussion around this here:
How do I get a "handle" on the Windows Search textbox? and probably sub classes the search box windows (if you kill the "Start Menu Calculator.exe" process abruptly, it crashes Windows Explorer too... which kinda confirms this)
It then reacts to key presses, and I suppose it butchers up the result window. In the hierarchies of Windows, I think it's a Window named "Desktop Search Open View", you can get to it with SPY++ under "Start Menu", aside the windows mentioned in the msdn forum above.
So, no nice API behind this nice application. Massive hacks instead :-)
I think however, some level of integration is possible, using documented behavior, with the search box. I have not dug further, but there is the notion of federated search in Windows (Windows 7 Federated Search). I don't see if this would be capable of reacting instantaneously to what the user types in though...
As a side note, if you're also looking for a way to run javascript code from C#, there is a question here on SO that says it all: parse and execute JS by C#
When making Start Menu Calculator I initially tried to use federated search and Managed (.NET) code however you can't integrate into the start menu, only the shell search (for web service based search which lets you return custom results based on a search string). The problem is that the federated search is structured such that all the search data is pre-indexed so for the calculator to work I would have had to pre index every possible calculation! The reason it all works this way is to make sure that clicking the start menu is always fast and responsive (you don't want a web service call everytime you press start in the shell).
I ended up hiring someone to write a native windows app that places a IE control into the Start menu search area and passes the searched text in with the source. All the visual stuff is just css made to look like the start menu rendering and the calculations handled in javascript.
So yes, a bit of a hack but it seems to work and I havent had/heard of any crashing issues so far.

What is the relation between dot Net web browser object and Internet Explorer present in the system?

I am developing a C# application for Windows 7 in which I want to load some flash content from a URL in a web browser object inside a form.
What I thought is the .Net web browser object is using the Internet Explorer installed in the system. So, if I remove IE from the system it should throw exception while instantiating the web browser object.
But what I observed is even if I remove IE from the system, my application can render the content in the form. But if I click any link in the content it is not opening any pop up IE window to show that content.
Can you throw some light on the relation between the default web browser object present in .Net and the IE present in the system...
Any pointers or links where I can explore this behaviour....? .
Trident (also known as MSHTML) is the name of the layout engine for the Microsoft Windows version of Internet Explorer.
Trident was designed as a software component to allow software developers to easily add web browsing functionality to their own applications. It presents a COM interface for accessing and editing web pages in any COM-supported environment, like C++ and .NET. ... Trident functionality becomes available by linking the file mshtml.dll to the software project.
copied from wiki. link is here
locations of mshtml.dll file on my system:
C:\Windows\winsxs\x86_microsoft-windows-ie-htmlrendering_31bf3856ad364e35_8.0.7600.16385_none_2dd3aff6fa7f090a
C:\Windows\System32
so my guess is even if you remove IE from your system, mshtml.dll is left untouched
Most ways of uninstalling Internet Explorer remove the IE executable but leave the rendering libraries in place, and they're used by lots of other tools in Windows. Probably that's why it's working for you, but won't pop up an independent IE window.
Unfortunately, I can't find any formal reference to this in anything but informal forum discussions, and none of them go into more depth than I have, so I can't offer any useful links for more information.

How to create an Explorer-like folder browser control?

Using C# and WinForms in VS2008, I want to create a file browser control that looks and acts like the left pane in Windows Explorer. To my astonishment, such a control does not ship with .NET by default.
Ideally, I would like its contents to be exactly the same as in Explorer. For example, on Windows 7, it should show the Favorites and Libraries pseudo-folders. Of course, I do not want to code specifically for each version of Windows if I can help it.
I have browsed around, and there are some examples of such controls, but they are all hand-rolled and therefore won't work 100% the same as the one in Explorer.
Is there any way I can simply reuse the Explorer control instead? Or, if not, to get access to a tree of the items that it would show?
Microsoft provides a walkthrough for creating a Windows Explorer style interface in C#.
There are also several examples on Code Project and other sites. Immediate examples are Explorer Tree, My Explorer, File Browser and Advanced File Explorer but there are others. Explorer Tree seems to look the best from the brief glance I took.
I used the search term windows explorer tree view C# in Google to find these links.
It's not as easy as it seems to implement a control like that. Explorer works with shell items, not filesystem items (ex: the control panel, the printers folder, and so on). If you need to implement it i suggest to have a look at the Windows shell functions at http://msdn.microsoft.com/en-us/library/bb776426(VS.85).aspx.
Take a look at Shell MegaPack control set. It provides Windows Explorer like folder/file browsing with most of the features and functionality like context menus, renaming, drag-drop, icons, overlay icons, thumbnails, etc

Hosting VisualStudio on a Winform and start it minimized

I'm trying to embed visual studio as a user control (to enable the user editing a generated source file). Basically most details can be found in a nice CodeProject entry Hosting EXE Applications in a WinForm project.
What bothers me is that after launching VS as a new process it takes some time before it settles down on the form. During this period I'd like it to be hidden, so I tried:
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
Also tried to turn on "CreateNoWindow" of ProcessStrartInfo with no successes.
(As a side question, I'm using process.WaitForInputIdle() to wait for VS before capturing its window handle, but on some machines the calls just returns immediatly).
Any clues? other suggestions? thanx in advance.
Robi
If you just want your user to be able to edit a source file inside your app, I'd recommend using a text edit control with syntax highlighting instead of embedding Visual Studio in your project. One option is ICSharpCode.TextEditor.
You can find more info about it in this CodeProject article.

Categories

Resources