CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Posts
    0

    listbox selection

    HI. new to the board and ive gotten stuck on a listbox problem. making a simple media player and i have a button, that when a listbox file in the listbox is selected, it will play.
    .....(simple explanation) it is my play button. .............select mp3 in listbox and hit play
    I know I have to use getcursel ...tried but no luck


    i have no problem playing the sound file with mci commands. i just wanted to master the listbox

  2. #2
    Join Date
    Mar 2010
    Posts
    4

    Re: listbox selection

    I assume the text on the list items is the filename for the file you want to play?

    Keep in mind that LB_GETCURSEL only returns the numeric index of the selected item. You'll need to use LB_GETTEXT with that index to get the actual text of the list item.

    You may want something like this:
    Code:
    TCHAR szFilename[MAX_PATH];
    int iCurSel = SendMessage(hWndList, LB_GETCURSEL, 0, 0);
    SendMessage(hWndList, LB_GETTEXT, iCurSel, (LPARAM)szFilename);
    
    //Use MCI functions to play szFilename here.

  3. #3
    Join Date
    Jun 2010
    Posts
    115

    Re: listbox selection

    May I ask why do you have to suffer using what might be so much error-prone ?
    I use only MFC, I know it might be a little overweighted a framework to load into the executable. But it is helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured