954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Reading Listbox values of other window

Hi,

Can anyone help me finding an application which can read listbox values of any other window on screen and save the list items either to clipboard or some text file, etc.

This may be done by getting the handle of the window/listbox and then reading the values, etc. I am novice in C programming.

Any help would be greatly appreciated.

Thanks.

codecodile
Newbie Poster
5 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Assuming this is the defaut Windows API listbox..

Step 1: Find a handle to the window containing the list box. [link]
Step 2: Allocate enough space to hold the strings. eg.[INDENT]

int count = (int) SendMessage( listbox, LB_GETCOUNT, 0, 0 );
std::string *items = new string[count];


[/INDENT]Step 3: Retrieve those values. eg.[INDENT]

for (int i = 0; i < count; ++i) {
  int itemLength = SendMessage( listbox, LB_GETTEXTLEN, i, 0 );
  char *temp = new char[itemLength];

  SendMessage( listbox, LB_GETTEXT, i, (LPARAM)&temp );
  items[i] = temp;

  delete[] temp;
}


[/INDENT]I haven't tested this code, but it should work if you apply it right. Hope this helps.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

thanks William, for your response.
Can you pls do me a favor to write a tiny app to read those values. With an interface like, specifying the window handle by some drag/drop thing and then read the list box values, etc.

I am very new to C++ programming and got this as a task :-s

Look forward to your response...

codecodile
Newbie Poster
5 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

thanks William, for your response. Can you pls do me a favor to write a tiny app to read those values. With an interface like, specifying the window handle by some drag/drop thing and then read the list box values, etc.

I am very new to C++ programming and got this as a task :-s

Look forward to your response...


That's too much to ask for.

If you're very new to programming, you shouldn't have been set a task like this. I wontdo it for you, but what I will do is lead you in the right direction. Start by familiarizing yourself with basic C++, then follow this Win32 API tutorial [link]
There's plenty in there to get you started, after all, that's exactly how I learnt it.

Remember, we aren't here to write code for you.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 
I haven't tested this code,.


It won't fork for od listbox
.................................

marco93
Junior Poster
132 posts since Apr 2008
Reputation Points: -76
Solved Threads: 14
 

What? Once again, not helping.
Also, I said Assuming this is the defaut Windows API listbox.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

Well, thanks Williams for guiding me to the tutorial.

Actually I am C# developer and may be I can convert your provided code .net to have it work for me.

codecodile
Newbie Poster
5 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

OK... this program worked with no errors... But now I want to print the results and "cout << items[i]" is not working..

Could anyone please tell me how to print "std::string" type strings?

rohan1020
Newbie Poster
9 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You