By default, Windows hides the notify icons in the taskbar, and user can see them by clicking on the arrow button. But user can drag those and drop them into the taskbar, so it'll be always visible. This preference will be saved for that executable.
However, my WPF app uses Squirrel.Windows for installation and update, and Squirrel.Windows creates a new executable (in a different path) for each update. So Windows will treat it as another executable, and that preference about notify icon is reset. (It hides again, even if user dragged it to taskbar in the previous version)
Is there any way I can preserve that preference of user across updates?
Maybe there's an identifier or something I can uniquely set? or any other ideas?
I'm currently using System.Windows.Forms.NotifyIcon on my WPF app. But I'm open to using alternatives if an alternative can help solving this issue.
Related
How do I get the state of the Show-Desktop toggle?
Goal:
Show the taskbar when show desktop is toggled and desktop is shown
Hide the taskbar when show desktop is toggled and windows are restore
Problem:
I can toggle show desktop and I can show or hide the taskbar but I cannot find a way to determine the state of the "show desktop" toggle.
I'm working in C# in VS 2010 with .net 2.0 (if it has to have later version .net ok, but I suspect the answer is somewhere in win32 with a pinvoke. Just can't find it)
This app is for a touch screen where getting to a auto-hidden taskbar is nearly impossible. Normally the taskbar is hidden but users would like to get to it when they click show desktop. (i.e. please no non-constructive comments on windows doesn't want you to change the autohide state without user permission)
Semi-Solution that technically meets my project requirements but not the intent of them:
Show the start menu any time show desktop toggles. Of course the start menu disappears when you click anywhere else but... It was shown.
There are several tutorials on how to do this. Just Google
I have a Silverlight control containing an image. I want the user to be able to drag the image out of the Silverlight application and drop it anywhere they would be able to drop an image. For example, to the Desktop or to a PowerPoint slide or Word document. Everything that I have read thus far says it cannot be done but I find that hard to believe. I'm very new to Silverlight and RIA development so any help would be much appreciated.
Below is the code sample in my WinForm Form but the drag never starts.
string[] aString = { imagePath };
DataObject data = new DataObject(DataFormats.FileDrop, aString);
data.SetData(DataFormats.StringFormat, imagePath);
DoDragDrop(data, DragDropEffects.Copy);
Well the trouble is that a drag operation in Silverlight doesn't have simple access to anything outside the browser (by design). Depending on the user's settings you even have to get explicit permission for clipboard operations and sandboxed temporary file storage. This really sounds like a task better suited to a WPF application (perhaps with web deployment?) or some other desktop application technology.
However, that being said here are some things you could try/consider:
Silverlight/Javascript/ActiveX combination hosted in Internet Explorer
Silverlight 5 "Out of Brower" & P/Invoke (I heard P/Invoke will be supported when Silverlight 5 comes out)
Silverlight connecting to a web service running on the same computer (crazy, but you didn't ask for "not crazy", you asked for possible)
I am not very familiar with drag and drop in the Win32 API so it would take a lot of research and experimentation before I could confirm that this was even possible (and I can already tell you it isn't practical).
Edit: Based on the extra information you provided about the question I suspect it is possible to do what you are attempting. First, are you using WPF or WinForms? I assume WPF but one of your comments says WinForms. I wasn't very familiar with WPF drag/drop operations, but having looked into it, I think your code is on the right path. I created a WPF application and initiated a drag during a KeyDown event. This meant that the mouse button was not necessarily pressed. If I initiated the DragDrop while the button was down it worked. If I initiated while the mouse button wasn't down, I had to push the mouse button down and the drag operation would start (this was unexpected since I assumed the mouse would have to already be down). If I pressed the mouse down outside the application, then gave the WPF app focus (ALT+Tab), then initiated the DragDrop while the mouse button was still down, it didn't work. I got a reference to the MouseDevice and checked the LeftButton property, and the state was showing as "Released" even though the button was still being held down. It seems the key here is the way drag/drop interacts with internal mouse state. You might have to find a way to set the mouse state (maybe with the UI Automation API?). At this point it should be painfully obvious that this whole thing is a hack (even though it is probably possible to get it to work somehow).
The solution we came up with was as follows. The RIA i.e. Silverlight sends a message to our Desktop application WinForms with the path of the image to drag along with the bounding rectangle in screen coordinates that we want to start the drag from. The Desktop code creates and places a Panel over the area that we want to drag from. This panel is where we use DoDragDrop to initiate the native drag when the user left clicks. Since this panel is placed outside and above the silverlight control, everything works perfect. Sandbox defeated.
I have been working on some Silverlight apps for the past few months and fully investigated your exact requirements only to find it was not possible. I believe you can drag from the file system, from Silverlight control to control, but not to the file system.
Does Silverlight 4 support drag and drop from app to desktop?
http://msdn.microsoft.com/en-us/library/dd772166%28v=vs.95%29.aspx
I want to fake a drag and drop action (dragging a file from lets say Windows-Explorer to a certain program). This program has a window with four drop-targets.
The target-program has its own graphical subsystem, so its neither based on WinForms nor WPF. I tried WinSpy and all it detects is the window itself, but none of the controls.
When I drag above one of the targets it shows a Windows' copy option though (like when you drag a file to a folder on another drive).
I don't believe there's any documented way.
You could send WM_DROPFILES, but this (1) requires you to put the filename into an undocumented HDROP structure in the target process memory ahead of time, and (2) is the older method for accepting files, it won't work if the application uses the newer IDropTarget APIs.
IDropTarget is actually designed to be more general than just dragging files from explorer: there's a Win32 API, DoDragDrop, which allows an application to act as a drag source so the user can drop its data into other applications. Unfortunately DoDragDrop watches mouse movement directly, so you'd need to simulate mouse movement and button release in order to control where the item dropped. Even this won't work unless the other window is on top of the z-order, since DoDragDrop finds the window under the cursor, and will interfere with any mouse activity the user is doing. So it should be used as a last resort.
Is it possible to drag and drop (files, text) to the taskbar icon of a WindowsForms application (C#)?
I know there's no easy way to do it for the tray icon (it involves using Win32 API and hooks), but I was wondering if it's possible for the taskbar.
That's not possible, but the window manager automatically restores the minimized window if you hover over it long enough in the taskbar. Once restored, you can access all the drop targets your window implements.
It is possible, at least in Windows 7. Note that the blog post which the two older answers refer to is from 2004. In Windows 7 and possibly previous versions, it is possible to drop files onto applications on the taskbar if you hold shift while dropping. Examples of applications that support this are Firefox, Internet Explorer, Notepad, etc.
In order to support it, your exe needs to be able to support the command line myapp.exe <some file path> and I believe you need registry entries similar to those described in this SO answer.
Update:
I added this to one of my applications, and it works. You do not need the registry entries.
This is fundamentally impossible.
I am trying to create a C# application that runs in tray where I can drop files on it's icon.
Is there any way to get the path of the file dropped on the System Tray icon? System.Windows.Forms.NotifyIcon does not have any events related to drag and drop.
it's not possible to do this, the easy way.
You can show a dummy Form, if the cursor is in a special area near the notifyicon.
The dummy Form can get the filepath of the droped file.
It has az example, but it's not fully and written in C++ :(
DragnDropOnTrayIcon
It actually is possible to do with a slightly hacky method. Fluffy App does this for its file uploader. It uses Spifftastic which uses a pretty neat little method to identify the location of the tray icon. Then a transparent window is placed over the location of the icon and used as the actual drop target, but to the end user it all appears to be dropping the file on the icon.