Sign in to follow this  

need some, basic win api help

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, c++ programmer here that has never really had the need for the win api stuff. I have used it here and there but never got a good book on the subject and dont have that option for this project I'm working on plus its just a simple change really. That being said, I'm sorry that I dont have much of a clue here, and I do know how that can be frustrating. However my goal is relatively simple to explain and I would "think" not to hard to write, yet I can't figure it out. I'm working with a DLL interfacing winamp. I have access to the win api and have not included any sort of sdk. So I'm stuck hunting for the functions I need to make it work. What I do know.. I have the window name that I need. I can use SetFocus and it works fine. However with in this window I have a list box, or at least I think that's what it is. Here is a screen shot of two views its has http://sourceforge.net/dbimage.php?id=5078 I use spy++ to get the name of the list box and its called "SysListView32". and the nIDDlgItem is labeled "IDC_ALBUMLIST" ( I know this from the code ) . What I want to do. Simple really. The list box has a highlight and a cursor. The highlight follows what is clicked on and the cursor is whats playing( being used ). I want to tell the highlight to move the the cursor at the given point I tell it to. The reason I want this, is when a song plays the highlight stays behind. At a glance it looks like the wrong album is playing. This application is in a car, so its imperative that the highlight is what is playing. I have tried all kinds of things like: SetDlgItemTextA( FindWindow("SysListView32",NULL),IDC_ALBUMLIST, "test1"); or CDialog(IDC_ALBUMLIST).ShowWindow(0); or SendDlgItemMessage( FindWindow("SysListView32",NULL) ,IDC_ALBUMLIST, LB_SETCURSEL, 2, 0 ); etc.. but nothing changes it. So any help targeting this listbox and make a change would be helpful. I know this is not really game dev, but I like the people here and I cant find a better forum. Hope someone can help here,Thx.

Share this post


Link to post
Share on other sites
Quote:
Original post by jwezorek
It's not a ListBox: it's a ListView. Get an HWND to it and then call the macro ListView_SetItemState(), see here.


Ah no wonder I was having problems.

Ok I think I have it figure out but still dont see it change, can anyone spot a problem here?

LV_ITEM lvi;
lvi.state=0; // also tried 1
lvi.stateMask=LVIS_SELECTED;
WPARAM ItemIndex=(WPARAM)2;
::SendMessage(hwnd_albumlist_LV,LVM_SETITEMSTATE,ItemIndex,(LPARAM)&lvi);


[Edited by - ulao on March 2, 2010 11:30:45 AM]

Share this post


Link to post
Share on other sites
Assuming hwnd_albumlist_LV is indeed the window handle of the list view control, try:
ListView_SetItemState( hwnd_albumlist_LV, itemIndex, 0xFFFFFFFF, LVIS_SELECTED );
InvalidateRect( hwnd_albumlist_LV, NULL, TRUE );
UpdateWindow( hwnd_albumlist_LV );

Share this post


Link to post
Share on other sites
Quote:
Original post by Amr0
Assuming hwnd_albumlist_LV is indeed the window handle of the list view control, try:
ListView_SetItemState( hwnd_albumlist_LV, itemIndex, 0xFFFFFFFF, LVIS_SELECTED );
InvalidateRect( hwnd_albumlist_LV, NULL, TRUE );
UpdateWindow( hwnd_albumlist_LV );




according to spy++
I have a main window "Winamp Gen" (I used a HWND of hwnd_albumlist)
and
a LV inside it "SysListView32" (I used a HWND of hwnd_albumlist_LV)
I can set focus to the hwnd_albumlist, but not able to do anything with hwnd_albumlist_LV yet

I tied both with the code you offered and see no results. The frame work also has a wndWinampAL and I can see there are window functions available.

( i.e : wndWinampAL.SendMessageA ) or wndWinampAL.GetSafeHwnd().

::SetFocus( hwnd_albumlist ) ; works
::SetFocus( wndWinampAL ) ; works
::SetFocus( wndWinampAL.GetSafeHwnd()) ; does not work

but for now I'm using

HWND hwnd_albumlist = FindWindow("Winamp Gen",NULL);
HWND hwnd_albumlist_LV = FindWindow("SysListView32",NULL);

Can you think of any simple change I could test with, like set focus. My guess is I just cant get to the LV in the window. Thank you both for your help!

Share this post


Link to post
Share on other sites
I don't think the list view window would be called "SysListView32" since that's the name of the window class. But anyway, to make sure that it's the window, try something like printing out its dimensions (use GetWindowRect()) and see if the printed numbers indeed look like they are for the window you want. Alternatively, try ShowWindow( hWnd, SW_HIDE ) to hide it, or FlashWindow().

Share this post


Link to post
Share on other sites
I think my problem is how a window is constructed.

if I ::ShowWindow( hwnd_albumlist, SW_HIDE ); Sure as can be that window will hide. but Do I want the window? I though I needed to get the List View in that window.

like

HWND hwnd_albumlist_LV = FindWindow("SysListView32",NULL);

or

HWND hwnd_albumlist_LV_chd = FindWindowEx(hwnd_albumlist,0,"SysListView32",NULL);

but once I have the HWND how do I know I have it? What could I possibly do to a LV to make it dance for me? So far I have not been able to make it talk.

Share this post


Link to post
Share on other sites
Do to the information given in this form I was able to do it via the album list api.

one of my biggest pet-peeve is broken unfinished threads. Not that anyone would want to know this.. but here ya go..

m_wndList.SetCurSel(indx);

wndList is a class that extends HWND, and there is a built in function called SetCurSel. so that is all it took really, just needed to do a lot of search to find this function. Thx for the help guys. Because of that I knew what to look for ( i.e list_view and what not ).

Share this post


Link to post
Share on other sites

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this