Thread: Recieving Message

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    17

    Recieving Message

    I am using MCI to play a sound but i need to know when its finnished so i can close it, so i added the notify flag, the msdn documentation says u need to handle the MM_MCINOTIFY message, how do u do this?
    Parinoia Means Having All The Facts!

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    26
    If you want to handle notification messages, you usually put it through WM_COMMAND message. You use a switch statement with HIWORD(wParam) or LOWORD(wParam).

    example
    Code:
    case WM_COMMAND:
    
    			switch(LOWORD(wParam))
    			{
    				case IDOK:
    					SendDlgItemMessage(hwnd, IDC_LIST1, LB_RESETCONTENT, 0, 0);
    				break;
    
    			}
    
    
    			switch(HIWORD(wParam))
    			{
    				char buffer[5];
    				int index;
    
    				case LBN_SELCHANGE:
    				{
    					index = SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETCURSEL, 0, 0);
    					SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETTEXT, index, (LPARAM)buffer);
    					SetDlgItemText(hwnd,IDC_EDIT1,buffer);
    					switch(LOWORD(wParam))
    					{
    						case IDC_LIST1:
    						{
    
    							index = SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETCURSEL, 0, 0);
    							SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETTEXT, index, (LPARAM)buffer);
    							SetDlgItemText(hwnd,IDC_EDIT1,buffer);
    						}
    						break;
    
    					}
    
    				}
    				break;
    			}
    		break;
    Last edited by ganonl; 08-14-2003 at 08:27 PM.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>f you want to handle notification messages, you usually put it through WM_COMMAND message.

    Actually thats command msg's.

    Notify msg's go thru the WM_NOTIFY or WM_PARENTNOTIFY handler.

    Heres some code from MSDN for setting up the device to send the MM msg's.
    The HWND you use will determine the dialog / window that gets the msg.

    I could not find any ref to what type of msg, WM_COMMAND or WM_NOTIFY or just a simple MM_MCINOTIFY will be sent.

    I suggest you write a simple handler, put a break point there and move the code until you get the msg. ie experiment

    Unless someone else knows.........

    Code:
    MCI_DGV_PLAY_PARMS mciPlay; 
    DWORD dwFlags; 
     
    mciPlay.dwCallback = MAKELONG(hwnd, 0); // this dialog / windows callback will get the msg
    dwFlags = MCI_NOTIFY; 
     
    mciSendCommand(wMCIDeviceID, MCI_PLAY, dwFlags, (DWORD)(LPSTR)&mciPlay);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    17
    Where would the above switch statement go?

    I suggest you write a simple handler
    how do u do that?
    Parinoia Means Having All The Facts!

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Why not just try to receive the msg through WM_NOTIFY:
    Code:
    case WM_NOTIFY:
      switch(((LPNMHDR)lParam)->code){
      case MM_MCINOTIFY:
        // Do something
        break;

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    actually, wparam is the reason for the mci message and lparam is the device id code it came from

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Originally posted by spike232
    Where would the above switch statement go?
    In your main app message processing loop.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    17
    i dont have a main message processing loop
    what is it?
    Parinoia Means Having All The Facts!

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    In WinMain() you specify the main message loop

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    17
    im making a dll but i dont have access to the main app that will be executing its functions, is there any other way to get this?
    Parinoia Means Having All The Facts!

  11. #11
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    You could subclass a window in the target process to run your own window procedure, that way you can get the notifications. You'll have to force the .dll to load into the target process using CreateRemoteThread() and LoadLibrary() (complicated process), or using the registry option (slows computer down).

    Does that sound like what you need?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  12. #12
    Registered User
    Join Date
    Mar 2002
    Posts
    17
    that sounds like overkill to play a simple mp3 sound

    are there any alternitive methods of playing mp3 files? perferably ones that dont require extra dlls and stuff on the clients machine.
    Parinoia Means Having All The Facts!

  13. #13
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Open a hidden window and tell it to send the commands to that window.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 02:22 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM