Hi ,
I need to extract data from a third party application's ListBox and store it into a .csv .
would like to do something like this article http://www.c-sharpcorner.com/UploadFile/SamTomato/clicking-a-button-in-another-application/
I am new to C# and any sample code would be greatly appreciated . I can have the Listbox id through SPY++ as shown in the above article.
Thanks & Regards
Sid

SIDDARTHA KAVILIPATIPosted May 22, 2013, 5:55 PM
Many Thanks
Sid
Sam HobbsPosted May 22, 2013, 5:51 PM
SIDDARTHA KAVILIPATIPosted May 22, 2013, 4:34 PM
This works for me to extract data from listbox. Sam thanks for all the information shared.
Sam HobbsPosted May 21, 2013, 3:30 PM
Sam HobbsPosted May 21, 2013, 3:21 PM
FindWindowEx however does not work the way I was thinking it does. The reason why is quite technical; it involves the difference between owned windows and child windows. So it will not work to specify a window handle with FindWindowEx, which means that you will search all windows in the system for a specified class name. That might work. Use null for hwndParent, Window F's class name for lpszClass and null for hwndChildAfter and lpszWindow. If you get a window using that then I suggest making a second call to FindWindowEx using that handle in hwndChildAfter and Window F's class name for lpszClass. If you get a window from the second call then that means there are more than one windows with that class name and that is a probable problem. If you get one and only one window then you can use GetDlgItem to get the ListBox.
SIDDARTHA KAVILIPATIPosted May 21, 2013, 3:16 PM
IntPtr hWndButton = GetDlgItem(handle, ButtonId); //returns 131740
whereas if I do
IntPtr hWndButton = FindWindowEx(handle, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.378734a", null); // returns 131700
for the same button using class name search it gives a different result??
SIDDARTHA KAVILIPATIPosted May 21, 2013, 2:52 PM
"WindowsForms10.LISTBOX.app.0.378734a"
So I am doing this
IntPtr hWndListBox = FindWindowEx(handle, IntPtr.Zero, "WindowsForms10.LISTBOX.app.0.378734a",null );
but still my hWndListBox is null.
Regards
Sid
Sam HobbsPosted May 21, 2013, 1:56 AM
If you are lucky then Window F has a unique class name. In Spy++ the properties of a window has a Class tab. At the top of the Class tab is a class name. If that class name is unique then you can use that. You can use the FindWindowEx function with the window handle for Window A and the class name. You can use NULL for hwndChildAfter and lpszWindow.
If it is not possible to do that then hopefully you can walk the window hierarchy. Look at the GetWindow function. You can use it to do various things to find windows depending on the relationship of the windows. I assume that Window B is the first child of Window A, so you get the child of Window A. Then get the first window in the Z-order (GW_HWNDNEXT) and that should be Window C. Then get the child of Window C. If it were me I would add logic that does something to ensure it is working as expected; something such as checking the window titles (either the entire title or a portion of it) (using a WM_GETTEXT message I think) but that depends on your application. Use whatever works for your application to check each window to ensure it is the correct window so if the application changes then your application will fail gracefully.
There might be other ways to do it but it depends on your application. You can look at the Windows API functions in case something else will help.
SIDDARTHA KAVILIPATIPosted May 20, 2013, 6:14 PM
Window 0001027C "A"
Window 0001028E "B"
Window 000102B4 "C"
Window 00170108 "D"
Window 00C00FE "E"
Window 001003A6 "F"
F is my target Listbox I need handle for F and A is the process main window with the below code from your earlier article I get handle for the mainwindow A.
How to do get handle for my listbox which is in child window. The above code works for the immediate child widgets.
Sam HobbsPosted May 18, 2013, 9:05 PM
SIDDARTHA KAVILIPATIPosted May 18, 2013, 8:39 PM
Sam HobbsPosted May 18, 2013, 8:13 PM
Sam HobbsPosted May 18, 2013, 8:02 PM
The following is a C++ console application that gets the items of a ComboBox. I used a ComboBox just because it is easier for me to find one for testing with. It is easy to do the equivalent for List Boxes.
int n = ComboBox_GetCount(hWnd);
std::wcout << n << L'\n';
_TCHAR Buffer[100];
int length;
for (int i=0; i
if (length < 99) {
ComboBox_GetLBText(hWnd, i, Buffer);
std::wcout << Buffer << L'\n';
}
else
std::wcout << "Item " << i << " is too big\n";
}
The stdafx.h file for that is:
#pragma once
#include "targetver.h"
#include
#include
#include
#include
#include
#include
SIDDARTHA KAVILIPATIPosted May 18, 2013, 7:33 PM
from the listbox selected
//Exporting Data
SIDDARTHA KAVILIPATIPosted May 18, 2013, 7:11 PM
I can write code to appendCSV File with extracted data I am looking for a SendMessage Command which can return a string of data from the listbox.
SIDDARTHA KAVILIPATIPosted May 18, 2013, 7:05 PM
Sam HobbsPosted May 18, 2013, 6:58 PM