Screen-scraping a windows application in c# [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I need to scrape data from a windows application to run a query in another program. Does anyone know of a good starting point for me to do this in .NET?

You may want to look into the WM_GETTEXT message. This can be used to read text from other windows -- it's an archaic part of the Windows API, and if you're in C#, you'll need to p/invoke for it.
Check out this page for an example of doing this in C#.
Basically, you first FindControlEx() to get the handle of the window that you want (by caption).
Second, you recursively enumerate the controls on that window with EnumChildWindows() to find all of the window's child controls, and all of those children's children until you have a complete map of the target form.
Here is a selected portion of Theta-ga's excellent explanation from Google Answers:
To get the contents of any textbox or listbox control, all we need is it's window handle. If you have already obtained the window handle then move to part 2 of the explaination.
PART 1: Obtaining the control handle
To obtain the handle of a control, we first obtain the handle of it?s parent window. We can do this by using the Win32 FindControlEx() method. This method takes in the window caption (such as 'Calculator') and/or its class name, and return its handle.
Once we have the parent window handle, we can call the Win32 EnumChildWindows method. This method takes in a callback method, which it calls with the handle of every child control it finds for the specified parent. For eg., if we call this method with the handle of the Calculator window, it will call the callback method with the handle of the textbox control, and then again with the handles of each of the buttons on the Calculator window, and so on.
Since we are only interested in the handle of the textbox control, we can check the class of the window in the callback method. The Win32 method GetClassName() can be used for this. This method takes in a window handle and provides us with a string containing the class name. So a textbox belongs to the ?Edit? class, a listbox to the 'ListBox' class and so on. Once you have determined that you have the handle for the right control, you can read its contents.
PART 2: Reading the contents of a control
You can read in the contents of a control by using the Win32 SendMessage() function, and using it to pass the WM_GETTEXT message to the target control. This will give you the text content of the control. This method will work for a textbox, button, or static control.
However, the above approach will fail if you try to read the contents of a listbox. To get the contents of a listbox, we need to first use SendMessage() with the LB_GETCOUNT message to get the count of list items. Then we need to call SendMessage() with the LB_GETTEXT message for each item in the list.

Related

ShowDialog() displays no data but Show() does [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
Maybe this can't be answered without context but when I use Show():
TestView test = new TestView()
{
Owner = Application.Current.MainWindow
};
test.Show();
Everything works fine, the events are fired and my textbox/comboboxes are populated with data on the test view. But when I use ShowDialog() nothing is populated. Anyone know a reason why? I want a modal window.
This is by design.
As by documentation:
When a Window class is instantiated, it is not visible by default. ShowDialog shows the window, disables all other windows in the application, and returns only when the window is closed. This type of window is known as a modal window.
Modal windows are primarily used as dialog boxes. A dialog box is a special type of window that applications use to interact with users to complete tasks, such as opening files or printing documents. Dialog boxes commonly allow users to accept or cancel the task for which they were shown before the dialog box is closed.
Thus, the ShowDialog is blocking until the window is closed.
This means that dealing with events and similar, specifically from the Owner window will not work.
If you have additional questions, please show the relevant code with the events and how you populate them.
If for some reason you need a full blocking window - it is possible; but we will need more details.

What component should I use to display enabled/disabled state? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have been wondering what component I should use to display state of enabled/disabled behaviours in WinForms.
For example I have function that returns state of 2 different processes.
And I want to display like green and red color on GUI, so that user could easily know which process has wich state.
In Java I have used ProgressBar, like setting it to 100 and 0, so it represents the state of that process. But as for now, I have moved to C#, so I would like to know what components you use for this purpose, maybe there is something better to use.
Any component with a background color property will do. I suggest you use Panel and switch the background color according to your state.
You didn't specify the technology, but CheckBox is one option in both WinForms and WPF. Plus you can use Label too (with BackColor / Background properties). Finally if you want to go fancy, you can use animations in WPF.
You could either use a Panel and change its background color or (more intuitively) a read-only CheckBox.
A progress bar is not really a good choice, unless you put it in "marquee" state when something is currently active and hide it when it is not. Otherwise a progress bar is meant to display ... well ... progress.
So this comes down to:
If you want to show that some process is activated/deactivated, for example by some sort of configuration, or simply "not performing a task right now", I'd use either a Panel with a background color or a CheckBox.
If you want to show that some process is currently working (without knowing the exact progress), I'd use a ProgressBack with a "marquee" state (also called "indeterminate").

How do GroupBox's and RadioButton's work together? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anyone explain me how the compiler knows to perform appropriate method when we select RadioButtons in this example ?
It's hard to say for sure what you're asking. I think you're asking how the system knows that it should execute the iconType_CheckChanged method when one of the icon radio buttons is clicked, and how it knows that, for example, the asteriskRadioButton changed.
The answer is in two parts. First, in creating the program in Windows Forms, you hooked up the CheckChanged event handler for each of the radio buttons. So the asteriskRadioButton CheckChanged method contains the value iconType_CheckChanged. That information is added to the partial class that you don't usually see. It's in your Form.Designer.cs file in the InitializeComponent method. It looks something like:
this.asteriskRadioButton.CheckChanged += iconType_CheckChanged
You don't typically see the Form.Designer.cs file. To view it, expand the form node in the Visual Studio Solution Explorer and you'll see the file listed:
The second part of the answer is that when you click the radio button (or when some code changes the state of the radio button), the underlying control machinery calls iconType_CheckChanged, passing a reference to the control that triggered the event in the Sender argument.

injecting text to process without injecting dll [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a way to overlay an application over a full-screened program?
Is it possible in C# to inject a text to process (like fraps for example), but without using any .dll injections?
Thanks in advance for responses.
#update
"A text" means some fast refreshing labels or something, which will show informations e.g.:
Name:Test
Pos: x=123,y=456,z=0
Level: Unknown
Something.....
You can use automation to send keyboard actions and suchlike to another program. Otherwise if there is no exposed API then things look bleak. See this question for an overview on the methods you use to send keystrokes.
EDIT: What you're asking for is not injection, it's an overlay. What you're looking to do is take control of the display buffer so that your overlay always has a higher z-index than whatever is being rendered. Take a look at this answer

Excel VSTO ->Hide/Unhide Ribbon Button based on another Ribbon Button click [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
We are creating Excel 2007 AddIn using VSTO. Now we have a scenario where in there are 2 buttons. Button 'A' and Button 'B'. Button 'B' needs to be hidden based on the click on the button 'A'.
But since the ribbon bar is not getting refreshed dynamically we are unable to see the change on the Ribbon Bar.
I heard from some blods we need to use callback methods for the same. If that is so, how can I do that?
Two remarks:
1) in order to "force" a refresh on the ribbon you can call ribbon.Invalidate();
This may be useful if you need to programmatically enable/disable buttons or other items.
2) dynamically hiding/showing buttons in the ribbon is against the Ribbon UI Guidelines, which you must comply. I'm not sure if it applies to Office Add-ins as well (or only to standalone applications), but I would be surprised if that's not the case.
You can read more here: http://msdn.microsoft.com/en-us/office/aa973809.aspx
Here is how I solved it:
Step 1: Make Button "B" visible False
Step 2: on Click event on Button "A" make it visible true.
I got confused by reading too much, and made simple question a complex one.

Categories