By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 2,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

how do i get a selected item in the list box

P: 1
how do i get a selected item in the list box....

i have my code to play a mp3....but cant get the listbox item

here is my code

Expand|Select|Wrap|Line Numbers
  1. #define _WIN32_IE 0x0300
  2.  
  3. // includes
  4. #include <windows.h>
  5. #include <mmsystem.h>
  6. #include <ufmod.h>
  7. #include <sys/stat.h>
  8. #include <commdlg.h>
  9. #include "res.h"
  10. #include "muzic.h"
  11. #include <commctrl.h>
  12. #include "vfw.h"
  13. MCIDEVICEID pDevice = 0;
  14. using namespace std;
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. HBITMAP hCarBmp = NULL;
  22. HBITMAP hSkinMBmp = NULL;
  23. int i = 0;
  24. HBITMAP hskin;
  25. RECT rc;
  26. HBITMAP hbup;
  27. HBITMAP hbdn;
  28. HBITMAP exitup;
  29. HBITMAP exitdn;
  30. HWND m_Video;
  31.  
  32. MCI_OPEN_PARMS op;
  33. // Destroy our windows caption
  34. void DestroyCaption(HWND hwnd, int windowWidth, int windowHeight)
  35. {
  36.  DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); 
  37.  dwStyle &= ~(WS_CAPTION|WS_SIZEBOX); 
  38.  
  39.  SetWindowLong(hwnd, GWL_STYLE, dwStyle); 
  40.  InvalidateRect(hwnd, NULL, true); 
  41.  SetWindowPos(hwnd, NULL, 0,0,windowWidth, windowHeight, SWP_NOMOVE | SWP_NOZORDER);  
  42. }
  43.  
  44. // Our dialogs callback routine
  45. BOOL CALLBACK dialog(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
  46. {
  47.  
  48.  
  49.  
  50.     INITCOMMONCONTROLSEX InitCtrlEx;
  51. InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  52.     InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
  53.     InitCommonControlsEx(&InitCtrlEx);
  54.  
  55.       switch(Message)
  56.     {
  57.  
  58.  
  59.  
  60.  
  61. // make window layered and set all pixels with an RGB value of 0,0,255 invisible              
  62. case WM_INITDIALOG:
  63. {
  64.  
  65.      case IDC_LIST1:
  66.                 // It's our listbox, check the notification code
  67.                 switch(HIWORD(wParam))
  68.                 {
  69.                     case LBN_SELCHANGE:
  70.                         // Selection changed, do stuff here.
  71.                     break;
  72.                 }
  73.  
  74.             break;
  75.  
  76.  
  77.        m_Video = NULL; 
  78.              //AnimateWindow(hWnd);
  79.  
  80.  
  81.  
  82.  
  83. }     
  84. break;
  85.  
  86. // move our window 
  87. case WM_LBUTTONDOWN:
  88.     {
  89.         PostMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION,0);
  90.         break;
  91.     }
  92.         case WM_DRAWITEM:
  93.             {
  94.  
  95.                 break;
  96.             }
  97.  
  98. // cleanup
  99.    case WM_CLOSE:
  100.     {     
  101.         DeleteObject(hSkinMBmp);
  102.         EndDialog(hwnd, 0);
  103.         break;
  104.     }
  105.  
  106. // draw our bitmap
  107.    case WM_PAINT: 
  108.     {
  109.  
  110. RECT rect;
  111.  
  112.         BITMAP bm;
  113.         BITMAP talkwithhandle;
  114.         PAINTSTRUCT attribstobmp;
  115.         PAINTSTRUCT ps;
  116.         HDC hdc = BeginPaint(hwnd, &ps);
  117.        HDC dcstuff = BeginPaint(hwnd, &attribstobmp);
  118.         HDC dcSkin = CreateCompatibleDC(hdc); 
  119.         HDC dcinmem = CreateCompatibleDC(dcstuff); 
  120.         GetObject(hSkinMBmp, sizeof(bm), &bm);
  121.         GetObject(hCarBmp, sizeof(talkwithhandle), &talkwithhandle);
  122.         SelectObject(dcSkin, hSkinMBmp);
  123.         SelectObject(dcinmem, hCarBmp);
  124.  
  125.       BitBlt(hdc, 10,10,160,108, dcinmem, 0, 0, SRCCOPY);
  126.         DeleteDC(dcSkin);
  127.         DeleteDC(dcinmem);
  128.         EndPaint(hwnd, &ps);
  129.          EndPaint(hwnd, &attribstobmp);
  130.         break;
  131.     } 
  132.  
  133.     case WM_COMMAND: 
  134.          {
  135. if(((HWND)lParam) && (HIWORD(wParam) == BN_CLICKED)){
  136.  int iMID;
  137.                  iMID = LOWORD(wParam);
  138.  
  139.  
  140.            switch(iMID){
  141.  
  142.  
  143.     case ID_ADD:
  144.          {
  145.  
  146.                 OPENFILENAME ofn;       // common dialog box structure
  147. char szFile[260];       // buffer for file name
  148.  
  149. // Initialize OPENFILENAME
  150. ZeroMemory(&ofn, sizeof(ofn));
  151. ofn.lStructSize = sizeof(ofn);
  152. ofn.hwndOwner = hwnd;  // handle to owner window
  153. ofn.lpstrFile = szFile;
  154. //
  155. // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
  156. // use the contents of szFile to initialize itself.
  157. //
  158. ofn.lpstrTitle = TEXT("Your Title Here");
  159. ofn.lpstrFile[0] = '\0';
  160. ofn.nMaxFile = sizeof(szFile);
  161. // filter name followed by null followed by filter extension,
  162. // repeat for each filter, and end list with double-null
  163. ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
  164. ofn.nFilterIndex = 1; // initial filter to select
  165. ofn.lpstrFileTitle = NULL; // initial file to select
  166. ofn.nMaxFileTitle = 0;
  167. ofn.lpstrInitialDir = NULL;
  168. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  169.  
  170. // Display the Open dialog box. 
  171.  
  172. if(GetOpenFileName(&ofn) == TRUE){
  173.  
  174.  
  175.  
  176.  
  177.                          m_Video = MCIWndCreate(hwnd,NULL,MCIWNDF_NOPLAYBAR,szFile);
  178.                           MoveWindow (m_Video, 729, 729, 1, 1, TRUE);
  179.  
  180. SendDlgItemMessage(hwnd, IDC_LIST1, LB_ADDFILE, (WPARAM) NULL, (LPARAM)szFile);
  181. MCIWndPlay(m_Video);
  182.  
  183.  
  184.  
  185.  
  186.                          }                         
  187.  
  188.  
  189.                 }
  190.                 break;
  191.                 case ID_PLAY:
  192.                      {
  193.  
  194.  
  195.  
  196.  
  197.                              }
  198.                              break;
  199.                 case ID_CLEAR:
  200.                      {
  201.  
  202.                      SendDlgItemMessage(hwnd, IDC_LIST1,LB_RESETCONTENT, 0, 0);
  203.  
  204.  
  205.  
  206.  
  207.                      }
  208.                      break;
  209.                 case ID_REMOVE:
  210.  
  211.                      {
  212.  
  213.  
  214.                             SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETCURSEL, 0, 0);
  215.                          SendDlgItemMessage(hwnd, IDC_LIST1, LB_DELETESTRING , 0, 0);
  216.  
  217.  
  218.  
  219.  
  220.                                }
  221.  
  222.         }}
  223.         break;
  224.  
  225.  
  226.  
  227. }
  228.        default:
  229.             return FALSE;
  230.     }
  231.      return DefWindowProc(hwnd,Message,wParam,lParam);
  232. }
  233.  
  234.  
  235. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
  236. {
  237.     WNDCLASSEX wc; 
  238.     wc.cbClsExtra = 0; 
  239.     wc.cbSize = sizeof(wc); 
  240.     wc.cbWndExtra = 0; 
  241.     wc.hbrBackground = NULL;
  242.  
  243.     wc.hIcon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_ICON));
  244.     wc.hIconSm = LoadIcon(NULL,MAKEINTRESOURCE(IDI_ICON));
  245.     wc.hInstance = GetModuleHandle(NULL); 
  246.  
  247.     wc.lpszClassName = "WinPatch";
  248.     wc.lpszMenuName = NULL;
  249.     wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC |CS_DBLCLKS;
  250.  
  251.   // load our bitmap
  252. hCarBmp= LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BALL));  
  253.    // create ourlog    
  254.    return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, dialog);
  255. }
  256.  
  257.  
please help
Aug 17 '11 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
? you should look into google.
follow the link

You also have used WM_INITDIALOG message in wrong way, better follow the link and rejudge what are you looking for.........

Best of luck with your work
Aug 18 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.