Determine number of screens and screen relative location without WinForms - wpf

I want to save and restore the window position of my WPF application. I want to make the code robust to use with multiple monitors who's number and relative location can change (I want to avoid opening my application off-screen when the monitor configuration has changed inbetween invocations).
I know of the Screen class in System.Windows.Forms, but I don't want to take a dependency on that assembly just for this feature.

Windows will keep your application on the screen even if you use corrdinates which are now outside fo the viewable range. Just persist DesktopLocation, Size, and WindowState (to see if the app was maximized). Be sure not to save these settings if the app was closed when minimized.

Related

Click a button in second life menu automatically

i recently started to play Second Life and I would like to know if there is a way to write a program outside of SL viewer that allow to click on sl menu's button automatically.
Not unless You really feel like writing Your own 3rd party viewer. The only time I've seen this done is through SmartBots, but even that is using a custom coded viewer to host the bot.
You can always use external programs such as AutoHotkey to do clicks at certain locations on-screen.
Do note that all UI elements in SL viewer are drawn not using the OS's GUI component system, but actually drawn by SL viewer itself using OpenGL calls, so you'll have to do coordinate calculations yourself, and click at certain relative coordinate to the viewer's window.

Touch screen operations for .NET windows application?

We are building a Windows application in .NET and one of its requirements is touch screen monitor. Other than that, it's a normal windows form based application. But except for making UI items little bigger for touch, I can't find anything I as a developer need to do for the requirement since touch screen is basically mouse operations. Am I missing something?
No, you are not missing anything. Do get the actual hardware hooked up so you can test it, "little bigger" is invariably underestimating the problem of fat fingers. Everything should work from a single click, right-clicks are horribly impractical, double-clicks are best avoided.
The only other thing you'll want to do is go into the Control Panel + Display applet and change the size of standard Windows UI elements. Pick a large window caption font if you want to allow the user to drag or close windows. Make the scrollbars at least twice as wide. And the menu and message box font. Go in the Mouse applet to increase double-click range and time if you want to support that.
If you do not need touch-specific event handling I think it's all you have to do. But touch means more than that and you may want to support it in a better way: http://archive.msdn.microsoft.com/WindowsTouch/Release/ProjectReleases.aspx?ReleaseId=2127

WPF Printing in XPS Document Writer

I've implemented a printing feature to print some of the Financial charts in my WPF application by using PrintVisual method. Since the user is free to change his/her window size and/or screen resolution I've use a LayoutTransform, Measure and Arrange methods to make sure that the printed charts gets spread across the entire page evenly irrespective of the size of the application window. All works absolutely well when the user prints on an actual printer or selects PDF Print Driver to print. Layout transform takes effect behind the scene and that shows up in the print, but the user doesn't experience any flicker or change in display on his screen.
The problem comes when the user selects XPS Document Writer. When user does that, the layout on the screen also changes. When the "Save As" dialog box comes up the screen layout changes based on the LayoutTransform provided, which makes the charts go smaller or bigger. The moment user saves the XPS file OR hit cancel on the Save as dialog box the layout goes back to normal. But the strange part is, this happens only when we select XPS Document Writer.
But, user doesn't want to see this.. What can I do to prevent this to happen in the case of XPS Document Writer?
Please suggest. Thanks
perhaps you can make a clone of your canvas or visual prior to applying your transform. clone is not built-in to wpf UIElements but you can use XamlWriter.Save() and XamlReader.Load to clone via XmlReader. google "wpf clone UIElement" or I can post some code if you feel that's the way to go.

Specifying which screen my application should open on

I've created two WPF applications that are designed to run full screen on the same server with dual monitors.
Is it possible to specify which application opens on which screen?
I currently have the executable on different monitors desktop which works but ideally I'd like to control this programmatically.
If that isn't possible, then I could move the application into a WPF web client and open in two full screen Internet Explorer windows but again I'd need to specify which ones load on which screens.
Thanks
You will have to set the Window.StartupLocation to manual for both of your exe's and then you will have to manually set the Window.Top and Window.Left to the coordinates for the monitor you want each to show up on.
You will probably want to use the Screen class to determine where each screen is at
http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

Hooking into Forms redrawing

I'm looking for a way to overlay the graphical output of a third-party application with some lines, arcs etc. The applications accepts a handle of a window in which it will then display its output.
Using VC++ I put together a Windows Forms app in Visual Studio that draws (non-static) stuff in the onPaint-method of a form. Passing this form's handle to the other app, of course, overwrites my graphics stuff every time the other app redraws.
Can I somehow hook into this redrawing process to add my graphics after the other app redraws? Overlaying the form with a transparent panel onto which I draw could be an alternative. But real transparency for controls seem to be a problem of its own in Windows ...
You can't do this easily without getting notifications from the app. Which, if it doesn't provide them, would require setting a global hook with SetWindowsHookEx() so you can see the WM_ERASEBKGND and WM_PAINT messages. That's hard to get right, you cannot write such a hook in managed code. Since it requires injecting a DLL into the target process.
The only other option is that you put a transparent overlay on top of your form. Another form that has its TransparencyKey property set. The basic code you need to get that right is available in my answer in this thread. You just need to tweak it so it is permanent.

Resources