Printing Multiple Windows Using PrintVisual() - c#

I'm currently using PrintVisual() in a wpf application to do printing. This is working perfectly at the moment, the only issue I now have is when processing large amounts of data I need to paginate, whereby I want to render the window multiple times to a buffer and then execute a print job. Currently PrintVisual() creates multiple print jobs, which works, but is not very eloquent.
I have attempted to use reflector to get the source for PrintVisual() in hopes of implementing that into an IDocumentPaginatorSource, unfortunately reflector is failing.
Perhaps I should try rending the window to a FlowDocument? Although I'm not too keen on having to code the printing layout.
Any suggestions?
Thanks In Advance!

I came right by calling RenderTargetBitmap() on each page's canvas.

Related

TestComplete Recorder doesn't recognize popups elements

I'm trying to record a test using TestComplete 10.
The application I test contains popups. The popup contains clickable buttons and links.
The problem is that when executing the recorded test- TestComplete does not recognize the popup itself and all the elements in the popup.
TestComplete waits for the popup element and then the test fails.
The application bases on WPF on Windows OS.
I'll be glad for some help regards this issue.
There is a way to pass this, any extension needed?
Since you are using TC10, I would always suggest updating to the newest version 12.5!
Beyond that, it could be a couple of different things, but first you should run through this requirements link to determine whether or not TC can see your application.
https://support.smartbear.com/testcomplete/docs/app-testing/desktop/wpf/requirements.html You could also take a look at this other link https://support.smartbear.com/testcomplete/docs/app-testing/desktop/wpf/index.html and see if it helps. Both links are for TC12.5, but some of these functionalities might still be available in your version.
Please let me know if you need some more assistance.

Sending and retrieveing data from another program using C#

for several days now I am trying to create a program that reads and writes values from/to textboxes in another application. To be more specific: I want to auto-update ticket cathegories in HP Service Manager.
My first attempt was using SendKeys. But I faced the problem that this method seems to be not really reliable as I need to reach text fields far from another and using loops that sended TAB was unreliable [of course I added an Application.DoEvents() and a Thread.Sleep].
After some time of testing I am now unable to control HPSM at all [SendKeys get executed on every program EXCEPT HPSM]. Dunno what is wrong but I read in the internet that there are several problems [only works with Visual Studio running, only while debugging etc.] so I dropped this solution.
I would welcome it if I can access the desired text fields directly. Now, using Spy++ I can select the desired text fields. But unfortunately, there is no fixed value to identify a certain text field: No way to do this programmatically.
The only thing that always seems to stay the same is the structure/hierarchy of the "Windows" provided by HPSM [see attached screenshot].
Now my idea: Is there a way to iterate through those sub-windows and read/modify the "Window Caption" portion of the certain window?
Or is there another, maybe simpler way to get this sucker automated?
Thanks in advance for every help since I slowly drown in desperation :)
HPSM structure:

How to get rid of a dynamic chat dialogue in web page by using coded UI

I'm wondering how I can solve the following issue. In a web application, which I suppose to automate by using Coded UI, there is a dynamic chat dialogue, which appears after some random time and swims from right to left edge. Since it moves, it hides some controls and will interfere with the automated test and causing the test to fail. Do you have any idea how I should get rid of it?
Since it moves, it doesn't have a fix position.
I thought, I may need to come up with a new thread and monitor the whole web application. As soon as it appears, I need to kill the chat dialogue box. This may work in theory but I'm not sure whether it works in the reality. Even if it works, it will be very costly and not easy solution.
Has anyone encountered a similar issue? If yes, can you please share your solution?
Coded UI works by searching for controls not by knowing their position on the screen. Hence a normal usage of Coded UI should work fine on your application. Consider using the WaitForControlExist or possibly the other WaitForControl... methods to deal with the dialogue that appears after an unknown time interval.

How can you read values from an open application in Windows?

I want to create a program or use a program that will read the memory values out of another application. Does anyone know of an application/library that will do this?
The target app is this. I would like to read the exchange rate values from it.
I'm an experienced c# programmer, but have never worked with the Win32/user32 api which is what I'm assuming I'll have to deal with to pull this off.
Any help that gets me going in the right direction is greatly appreciated.
Update:
I managed to use Spy++ to get the window handle, so I'm sure I can get the values some how.
Have you looked into AutoIT or AutoHotKey?
Both of these open source options have well documented abilities to read text from application windows (and send keystrokes or mouseclicks to them).
AutoIT is very easy to use and well documented.
An example of reading text from a window would be:
$text = WinGetText("title of window", "")
MsgBox(0, "Text read was:", $text)
This can be compiled into an executable.
Typically an application creates controls in a dialog in a consistent manor, same ID, same order etc, so finding a control programatically is fairly simple. Using Spy++ find the control's ID and then you can search the windows created by the application for the desired control. Not being familiar with the app in question I cannot give specifics, but if Spy++ shows the value you desire, it is likely not difficult to obtain the value in your code.
What type of control is the value displayed in? You'll may be able to use GetDlgItemText to obtain the value once you have the parent window handle and control ID? To get the parent window try using EnumWindows.
It might be easier to scrape their data by automating a screenshot and then ocr process. If that's your goal.
Potentially relevant links:
get-a-screenshot-of-a-specific-application
ocr-with-the-tesseract-interface
May be this article helps - http://msdn.microsoft.com/en-us/magazine/cc163617.aspx, but I think it's not universal and for your task is better to get access directly to Forex API/Web-Service or try to catch needed data on network.
It is possible to screen-scrap things created with native windows controls; if that is the case, you should be able to see the controls using Spy++. But some times controls are implemented "by hand", and there is no way to screen-scrap them (e.g. some Java graphic toolkits play directly with the graphics, so everything day do is meaningless from the outside, or even some Office menus are implemented without using the menu control).
The Windows accessibility API is a possible way to screen-scrap the values; check if "Narrator", the screen reader that comes with windows, is able to read aloud your target application.

Windows Terminal - Windows Form to embed cmd

I'm looking for a way to embed a cmd "Shell" into a Form. I want to build a C# based application that acts as a Terminal, better than the Powershell window (no tabs) or cmd (no nothing). Just start these interpreters in the backend.
I guess MS never thought of doing this. Any ideas what From elements I could use?
Thanks,
i/o
That's not a trivial task you're undertaking. I know of one project (Console2) which basically polls the screen buffer of the underlying console window and displays in its own. You certainly will have trouble coping with interactive applications like Far and the like as they (a) rely on getting keyboard events and (b) on manipulating their screen buffer. Both are icky things if you want a suitable wrapper around the console window functionality. Mouse input is possible as well (unless Quick Edit mode is enabled) which could give you further headaches.
I doubt you can use a ready-made control for this. Basically you need to display a grid of cells each of which has a foreground and background color. You could probably use a RichTextBox for this but I'd guess it's far from ideal.
Also I don't think no one at MS ever thought of this. It's just that there's a limited budget for new features and every one of them needs to be specified, implemented, tested, tested more for regressions with millions of applications out there, etc. It's just a freaking expensive thing (if you don't want to misuse your customers as testers, which they aren't).
It would propably be the easiest to extend the Textbox class and add logic so that it behaves like a console (respond to the KeyPressed/KeyUp/KeyDown events or similar). You can also add events for those things that your console needs to respond to. For example, add a CommandEntered event.
Basing your new console on a TextBox gives you the editing and display features of the textbox "for free", so you do not need to re-implement that.
You could use a richtext box, and set the background to black and foreground to white. RTB instead of text box to handle larger amounts of data.
You would have to write an awful lot of code to simulate the terminal though.

Categories