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


Sam HobbsRank #107 · 20.5K reputationPosted May 18, 2013, 2:58 PM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 18, 2013, 3:05 PM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 18, 2013, 3:11 PM EDT
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 KAVILIPATI26 reputationPosted May 18, 2013, 3:33 PM EDT
from the listbox selected
//Exporting Data
Sam HobbsRank #107 · 20.5K reputationPosted May 18, 2013, 4:02 PM EDT
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
Sam HobbsRank #107 · 20.5K reputationPosted May 18, 2013, 4:13 PM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 18, 2013, 4:39 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 18, 2013, 5:05 PM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 20, 2013, 2:14 PM EDT
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 HobbsRank #107 · 20.5K reputationPosted May 20, 2013, 9:56 PM EDT
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 KAVILIPATI26 reputationPosted May 21, 2013, 10:52 AM EDT
"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
SIDDARTHA KAVILIPATI26 reputationPosted May 21, 2013, 11:16 AM EDT
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??
Sam HobbsRank #107 · 20.5K reputationPosted May 21, 2013, 11:21 AM EDT
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.
Sam HobbsRank #107 · 20.5K reputationPosted May 21, 2013, 11:30 AM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 22, 2013, 12:34 PM EDT
This works for me to extract data from listbox. Sam thanks for all the information shared.
Sam HobbsRank #107 · 20.5K reputationPosted May 22, 2013, 1:51 PM EDT
SIDDARTHA KAVILIPATI26 reputationPosted May 22, 2013, 1:55 PM EDT
Many Thanks
Sid