473,467 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do i get a selected item in the list box

1 New Member
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
1 4410
johny10151981
1,059 Top Contributor
? 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

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

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
3
by: Stanley J Mroczek | last post by:
I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as selected. If Page.IsPostBack = False Then...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
4
by: Merdaad | last post by:
My drop down list is populated from a static array in my codebehind (c#) code. I set the selected index based on some known values(from DB), when the screen shows up, dropdown list shows that the...
5
by: Joe Fallon | last post by:
I have a list box with 7 text values in it. I have a pair of buttons to Move Up or Move Down the selected item one position. What is the simplest way to code the buttons so the item moves one...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
0
by: Geary | last post by:
I have a drop down list on an asp.net 2 page that is bound to a table. By default it displays the first item as the selected item. But I want to make sure that the user must change the selection. ...
1
by: bairamsunil | last post by:
I have a list box in which items are selected alternately, depending on the selection I have to remove the records in another table which matches this item as well as i have to refresh the list box....
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.