Background: I've decided to teach myself C# through WPF, and I'm writing a small application that needs to get a list of Start Menu shortcuts and their targets and store them. Basically, I'm trying to take all the shortcuts and put their target applications' paths into memory. However, I've run into a problem trying to read Windows Installer shortcuts (the ones that point to something like C:\Windows\Installer\{90120000-0030-0000-0000-0000000FF1CE}\wordicon.exe -- Microsoft Office is a good example of this). I did some research and it seems that Windows uses some behind-the-scenes magic involving the Registry to find the actual location of the file.
Question: How can I get the actual target of these Windows Installer shortcuts in C#? A lot of sources I've found point me to the IShellLink interface, but I don't know how to use it with C#. I'd prefer to use Windows API calls (or, even better, a .NET library) instead of manually looking through the Registry, but I'll take any guidance on the issue.
After doing more research, I found an easy answer here. It's basically using a combination of the MsiGetShortcutTarget and MsiGetComponentPath functions of msi.dll.
I'm afraid IShellLink IS the Windows API for using shell links! The Shell API is heavily COM-based.
But the good news is that COM interop works very well in .NET. This site is usually a very good resource:
http://www.pinvoke.net/default.aspx/Interfaces/IShellLinkA.html
Related
Recently I’ve been working on a windows wallpaper manager. It will scan multiple directories for images and have a settings window to customize. In addition, I want to bypass the built-in wallpaper and instead use a windows form based off the ideas discussed here: Setting a Windows form to be bottommost to allow for greater control over image placement. I have built the file operations to find the wallpapers, and various other support operations.
However, I am stumped on how to implement a windows form properly. Not just the one in the Stack Overflow post above. So far none of my CompSci classes (7 so far) have discussed GUIs, and thus I have no knowledge to work from. I turned to the internet to learn how to work with GUIs. While I learned plenty to start a thread, or show a form, I was never able to find anything that described the proper way to engineer an application with a GUI. All I have learned in respect to engineering the application is to limit the number of threads, and try to separate the GUI from the non-GUI related code (if that makes sense).
Like I have said, I have no clue what I am doing. If someone would be willing to give me pointers or even a link to something on this subject, that would be amazing!
EDIT: I have been using this as a learning exercise, and I have mostly been learning from trial and error, probably mostly error
To draw on the true desktop, you need to get a handle to it: GetDesktopWindow is the function to use. But to change the wallpaper you do not draw on the desktop, but instead you use the dedicated API for handling the desktop wallpaper: SystemParametersInfo(SPI_SETDESKWALLPAPER, ...). There is also the legacy COM Shell interface, IActiveDesktop and IActiveDesktop::SetWallpaper.
As you can see, none of the APIs to manipulate the desktop and the wallpaper are managed (C#, .Net) so you will have to jump through some hoops to get this working from C#. If your goal is to learn C# style UI, I would recommend to stick to the 'blessed' way of doing this (winforms, WPF etc) and do not try to jump straight to p-Invoke and COM interop. Perhaps you can pick another project, eg. display the images/pictures in a carousel in a form.
If you're curious still, Google for C# and SystemParametersInfo or IActiveDesktop and you'll find examples of how to do this from managed C#, many examples right here on StackOverflow.
Bonus: of course Raymond Chen has a blog on this topic: How do I put a different wallpaper on each monitor?.
I'm trying to embed Windows-Sidebar-Widgets into my own .Net Application (WPF and C#), but I dont't realy know where to start. I googled a bit but only found SDK and tutorials for widget-development. I found that there is a small service in Windows, running the widgets. My thought was that I could perhaps fake this service and provide his functions whithin my programm, so that I can run and show the widgets.
Does anyone have some tips on how to do this? Or some experience in doing so? Perhaps there is even some kind of libary for that kind of stuff?
If this is not possible it is also an option to switch to an OpenSource widged-manager to use this widgeds, but this is only an emergency solution and the windows-gadgeds would be very appreciated.
Some information about my system:
I've written some kind of small windowmanager for childwindows in my application. And on the top of this I want to show the widgets in some kind of HostWindow.
Any hint will be appreciated.
P.S.: I would be willing to share the results if I (or we) get this working :-)
I've never seen a library for hosting gadgets, but since they are basically just websites you could use the MSHTML component to host any arbitrary gadget in theory.
This isn't to say it will be easy.
You'll need to extract a gadget to some temporary directory, spin up something hosting MSHTML (in WinForms WebBrowser would be convenient), navigate to the appropriate file in that temp directory (discovered by parsing gadget.xml), and shove something resembling the System object into the gadget.
As a starting point, inject some script that sets System = window.external; onload and WebBrowerser.ObjectForScripting = new FakeGadgetSystem().
FakeGadgetSystem will need [ComVisible(true)] and to implement a decent amount of stuff. I'd advise grabbing a widget or two to test with that mildly exercise the Gadget API, and then slowly implement the calls they make. It'll be a long haul for 100% compatibility with the official gadget hosting service.
I'm rebuilding an Embedded application:
Prebuild application Specifications:
Use : For dispaying the captured images/video from microscope image capturing device on windows based PC or Laptops.
Sepcifications: Prebuild on .NET plateform using VC++
Flaws : Lacks some specified features.
Current Requirement:
Want to rebuild that entire application using C# and add some additional client features.
My Questions:
Is it feasible to develop such application in C#.net?
If yeh,What kind of resources available in C# to develop desktop embedded application?
Any references which show any of such kind of application?
Your suggestions on building this kind of application.
P.S. It is essential to buid it on .NET platform.
I think by "Prebuild" you mean "Existing". Why do you want to rewrite the complete application? As you have stated that the application is written in C++.Net. You can easily add all the new functions in C# and use that code from your existing C++.Net code.
Note: I'm making this answer CW because the question is hard on the limit towards some close reasons. Everyone feel free to edit and extend it.
Is it feasible to develop such application in C#.net?
That's a tough one...from the top of my head I'd argue that it doesn't matter. If you know C#, then build it in C#, if the client wants it in C#, then build it in C#. You'll most likely have to use COM-Components or API-Invokes anyway to accomplish this.
If it is a TWAIN device, you might be better of to stick with VC++, I found TWAIN on .NET a real pain in the a** and have given up on such features. Same goes for WIA, but that might just be me.
If yes, what kind of resources available in C# to develop desktop embedded application?
I guess you mean a Widget? In that case I have no idea, I never really looked at that (at least not on Windows). But as far as I know widgets on Windows consist of a data-backend and a HTML/JavaScript-Frontend, so you'll most likely have to develop the two separately.
Any references which show any of such kind of application?
I guess any WIA/TWAIN application would be a reference, at least your description sounds so.
Your suggestions on building this kind of application.
See your first question.
I know that you can create a separate console application, however, I am in the final stages of testing and my application does not have an interface. Is there a way to simply open a console and interact with that inside the desktop application? This would be in a test method. (I am using C#, in Visual Studio 2008).
Thanks,
badPanda
You might be able to do what you want using AllocConsole (creates a new console) or AttachConsole (attaches to an existing console), but I think there are some limitations to what you can do with them.
See here for the API documentation for AllocConsole and here's the PInvoke page.
Here's a list of lots of Console functions, might be something else useful there too.
This may or may not be helpful, but some of the same techniques of GUI testing can be applied to a console app too, of course.
Here is an article and example code in C# for a user interface test.
Or there are totally different tools/languages that can be used for UI testing, such as AutoIt v3, which is easy to learn and apply. AutoIt does have a DLL/COM control that you can access from your preferred programming language (but I haven't used it that way so I can't comment on how well it works).
I want to know how can I build UIs like skype using standard .Net/C#. Is it possible at all?
Thanks
You can use Windows Presentation Foundation to build more stylish GUIs than Windows Forms. It's pretty difficult to move from Forms to WPF. You usually need a good design tool, like Expression Blend.
AFAIK skype was built using Qt4, it's rather easy to build custom gui widgets, check
C++ GUI Programming with Qt4, 2nd Edition and this tutorial.
P.S. check this to see how to build qt4 on windows using MSVC 2008.
It might be possible to build such an UI using Windows Forms, but only with a lot of custom control code or a really good component suite. But as Chris said, WPF should be the tool of your choice when you want to use .NET.
Qt4 is a really powerful C++ framework, also powering apps like Google Earth. The Qt SDK, inclduing everything you need to get started (Compiler, IDE, documentation), can be obtained here. It's licensed (among others) under the LGPL.
Windows Presentation Foundation will give you the most flexibility, but it can be hard to use. An alternative to this is Sliverlight - Version 3 is going to be capable of being used outside of the browser (similar to Adobe Air), and in some ways provides an easier development experience. You might want to consider using some third party controls to give you access to nice functionality that you wouldn't get out of box.
To my acknowledge Skype is build with Delphi an a set of third party tools, so it for sure can be done without WPF.
Take a look at the components from DevExpress or TMS.