Select item from ListBox 
Author Message
 Select item from ListBox

Hi all

I have to select some items from a listbox of another program and I have no
idea how to do that. I wrote some programs with functions like that and used
the ::SendMessage function. Now, I have the hWnd of the listbox but I don't
know the correct parameters...
Thanks for your help.

Greets Chris



Fri, 04 Mar 2005 13:40:28 GMT  
 Select item from ListBox

Quote:
>I have to select some items from a listbox of another program and I have no
>idea how to do that. I wrote some programs with functions like that and used
>the ::SendMessage function. Now, I have the hWnd of the listbox but I don't
>know the correct parameters...

Chris,

Have you had a look at the LB_SETSEL message documentation?

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Fri, 04 Mar 2005 15:15:57 GMT  
 Select item from ListBox
Hi Dave

I just had a look at the documentation. It sounds good, but I have one
problem: How can I get the index of a data record? Is there a function for
that? I have only the text and not the index...

Chris



Quote:
> >I have to select some items from a listbox of another program and I have
no
> >idea how to do that. I wrote some programs with functions like that and
used
> >the ::SendMessage function. Now, I have the hWnd of the listbox but I
don't
> >know the correct parameters...

> Chris,

> Have you had a look at the LB_SETSEL message documentation?

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Fri, 04 Mar 2005 17:48:55 GMT  
 Select item from ListBox
Perhaps with LB_GETCOUNT, LB_GETTEXT?
For more info, see
http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/lis...
listboxes.asp

Luc K


Quote:
> Hi Dave

> I just had a look at the documentation. It sounds good, but I have one
> problem: How can I get the index of a data record? Is there a function for
> that? I have only the text and not the index...

> Chris



> > >I have to select some items from a listbox of another program and I
have
> no
> > >idea how to do that. I wrote some programs with functions like that and
> used
> > >the ::SendMessage function. Now, I have the hWnd of the listbox but I
> don't
> > >know the correct parameters...

> > Chris,

> > Have you had a look at the LB_SETSEL message documentation?

> > Dave
> > --
> > MVP VC++ FAQ: http://www.mvps.org/vcfaq



Fri, 04 Mar 2005 18:11:28 GMT  
 Select item from ListBox
I tried it like that:

 iDataRecords = ::SendMessage(ChildhWnd, LB_GETCOUNT, 0, 0);

But I always get 0. Do you know, why?



Quote:
> Perhaps with LB_GETCOUNT, LB_GETTEXT?
> For more info, see

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/lis...
Quote:
> listboxes.asp

> Luc K



> > Hi Dave

> > I just had a look at the documentation. It sounds good, but I have one
> > problem: How can I get the index of a data record? Is there a function
for
> > that? I have only the text and not the index...

> > Chris



> > > >I have to select some items from a listbox of another program and I
> have
> > no
> > > >idea how to do that. I wrote some programs with functions like that
and
> > used
> > > >the ::SendMessage function. Now, I have the hWnd of the listbox but I
> > don't
> > > >know the correct parameters...

> > > Chris,

> > > Have you had a look at the LB_SETSEL message documentation?

> > > Dave
> > > --
> > > MVP VC++ FAQ: http://www.mvps.org/vcfaq



Fri, 04 Mar 2005 20:05:33 GMT  
 Select item from ListBox

Quote:
>I just had a look at the documentation. It sounds good, but I have one
>problem: How can I get the index of a data record? Is there a function for
>that? I have only the text and not the index...

Chris,

I'm sure we're missing some aspect of what you're doing.

Anyhow, to find the item corresponding to the text of an entry, you
can use LB_FINDSTRING or LB_FINDSTRINGEXACT.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Fri, 04 Mar 2005 23:47:54 GMT  
 Select item from ListBox
Ok, I have to write a program in mfc. This program must automate some steps.
And one of these steps is to select some items in a listbox of another
program. This other program I started with ShellExecute. Everything worked
but the listbox is my problem. I looked for LB_FINDSTRINGEXACT in the msdn
library and I tried it in my program. But it doesn't work. I do not believe
that the problem is with LB_something. I think I have a problem with the
listbox.
I have to explain you something:
I used Spy++ to get the hWnd of my listbox. This "other program" has only
one listbox. The window name of it is "List1" and its class name is
"SysListView32". But this hWnd has a Childwindow. No window name and class
name "SysHeader32".

Some code:
//ChildhWnd = FindWindowEx(ChildhWnd, NULL, "SysHeader32", "");  // I don't
know... Must I take this Childwindow??
for(iCounter = 0; sSelectItem[iCounter+1] != "";
iCounter++){                 // I have an array of CString. I have to select
all.
      iListBoxIndex = ::SendMessage(ChildhWnd, LB_FINDSTRINGEXACT, -1,
(LPARAM) (LPCTSTR) sSelectItem[iCounter]);
      // -1 because I want to search in the whole list
     ::SendMessage(ChildhWnd, LB_SETSEL, (WPARAM) (BOOL) TRUE, (LPARAM)
(INT) iListBoxIndex);
 }

For each element in my array I want to get the index(iListBoxIndex). Then I
try to select it with this index. But I always get 0...
I don't know, but I think I have a problem with my listbox.

Thanks for help!

Chris



Quote:
> >I just had a look at the documentation. It sounds good, but I have one
> >problem: How can I get the index of a data record? Is there a function
for
> >that? I have only the text and not the index...

> Chris,

> I'm sure we're missing some aspect of what you're doing.

> Anyhow, to find the item corresponding to the text of an entry, you
> can use LB_FINDSTRING or LB_FINDSTRINGEXACT.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sat, 05 Mar 2005 15:24:52 GMT  
 Select item from ListBox

Quote:
>And one of these steps is to select some items in a listbox of another
>program.

Chris,

There's your biggest problem. Only a few select messages work across
process boundaries (to cater for compatibility with old 16-bit
Windows). Passing pointers to strings is usually not possible.

I suspect your solution needs to be somewhat more complicated,
involving a system-wide hook (DLL) so that you can get your code
injected into the other process' address space, and then some
inter-process communication between your hook code and your
application in order to pass the data.

Quote:
>I used Spy++ to get the hWnd of my listbox. This "other program" has only
>one listbox. The window name of it is "List1" and its class name is
>"SysListView32".

That's not a listbox, it's a list control (CListCtrl in MFC). You
can't pass listbox messages to a list control - well you can, but it
won't work as you'd expect.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sat, 05 Mar 2005 16:47:20 GMT  
 Select item from ListBox
ooouuuuuuuhhhhhhhh, that sounds very, very bad, because I haven't any
experience in writing DLLs. Is there no other way to solve this problem?

Anyway, thanks

Chris



Quote:
> >And one of these steps is to select some items in a listbox of another
> >program.

> Chris,

> There's your biggest problem. Only a few select messages work across
> process boundaries (to cater for compatibility with old 16-bit
> Windows). Passing pointers to strings is usually not possible.

> I suspect your solution needs to be somewhat more complicated,
> involving a system-wide hook (DLL) so that you can get your code
> injected into the other process' address space, and then some
> inter-process communication between your hook code and your
> application in order to pass the data.

> >I used Spy++ to get the hWnd of my listbox. This "other program" has only
> >one listbox. The window name of it is "List1" and its class name is
> >"SysListView32".

> That's not a listbox, it's a list control (CListCtrl in MFC). You
> can't pass listbox messages to a list control - well you can, but it
> won't work as you'd expect.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 06 Mar 2005 16:00:10 GMT  
 Select item from ListBox

Quote:
>ooouuuuuuuhhhhhhhh, that sounds very, very bad, because I haven't any
>experience in writing DLLs. Is there no other way to solve this problem?

I can't think of one - other than to have someone else write the code
for you :)

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 06 Mar 2005 17:00:11 GMT  
 Select item from ListBox

Quote:

> ooouuuuuuuhhhhhhhh, that sounds very, very bad, because I haven't any
> experience in writing DLLs. Is there no other way to solve this problem?

> Anyway, thanks

> Chris

There is a (slim) chance you might be able to do it by simulating user
keystrokes.  If you can come up with a 'key algorithm' you can simulate
it with the SendInput API.  This technique requires the target app to be
the active window (another dicey proposition!).

--
Scott McPhillips [VC++ MVP]



Sun, 06 Mar 2005 18:20:32 GMT  
 Select item from ListBox
Thank you very much, David. That was a great idea:-).
I'll do that.



Quote:
> >ooouuuuuuuhhhhhhhh, that sounds very, very bad, because I haven't any
> >experience in writing DLLs. Is there no other way to solve this problem?

> I can't think of one - other than to have someone else write the code
> for you :)

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 06 Mar 2005 17:31:05 GMT  
 Select item from ListBox
Hi all

There is hope!
I looked at the documentation of the SendInput API  but I think, it's hard
to understand.
UINT SendInput(
  UINT nInputs,     // count of input events
  LPINPUT pInputs,  // array of input events to insert
  int cbSize        // size of an INPUT structure
);

Nevertheless I tried to write a small example program which did not work. I
don't know how to use the parameters. Does anybody have a small example?
That would help me.

Chris



Quote:

> > ooouuuuuuuhhhhhhhh, that sounds very, very bad, because I haven't any
> > experience in writing DLLs. Is there no other way to solve this problem?

> > Anyway, thanks

> > Chris

> There is a (slim) chance you might be able to do it by simulating user
> keystrokes.  If you can come up with a 'key algorithm' you can simulate
> it with the SendInput API.  This technique requires the target app to be
> the active window (another dicey proposition!).

> --
> Scott McPhillips [VC++ MVP]



Sun, 06 Mar 2005 22:15:17 GMT  
 Select item from ListBox

Quote:

> Hi all

> There is hope!
> I looked at the documentation of the SendInput API  but I think, it's hard
> to understand.
> UINT SendInput(
>   UINT nInputs,     // count of input events
>   LPINPUT pInputs,  // array of input events to insert
>   int cbSize        // size of an INPUT structure
> );

> Nevertheless I tried to write a small example program which did not work. I
> don't know how to use the parameters. Does anybody have a small example?
> That would help me.

> Chris

There is a nice SendInput example/utility by John Robbins in the April
99 MSJ magazine, available in MSDN library.

--
Scott McPhillips [VC++ MVP]



Mon, 07 Mar 2005 07:01:14 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Dynamically select items in ListBox

2. Select item from ListBox

3. Removing selected items from ListBox object...

4. Listbox event when selected item changes

5. Multiple selected items in a listbox

6. Select Listbox item by right (!)mouse button pressing

7. ???Warning: No listbox item selected

8. how do I invalidate the entire listbox not just the selected item

9. How to set the selected item in a listbox to the top

10. problem with selecting an item from a listbox

11. problem with selecting an item from a listbox

12. Dynamically change Listbox from Single Select to Extended Select

 

 
Powered by phpBB® Forum Software