Question Hooking - Intercept MM_MCINOTIFY message

DDTdevelop

New member
Joined
Aug 17, 2011
Messages
3
Programming Experience
5-10
Hi all. My first post here (asking for help obviously).

I play a midi file using this simple win32 api call:

MidiMsg = "open " & c_midiFile & " type sequencer alias mid1 notify"
ret = mciSendString(MidiMsg, "", 0, Form1.Handle)
MidiMsg = "play mid1"
ret = mciSendString("play mid1", "", 0, Form1.Handle)

Callback message MM_MCINOTIFY has a value of &H3B9 (found it using "spy++")

I have to know when this message (MM_MCINOTIFY) is fired and read his parameters. In an old version of code I've written years ago in VB6 i had to use CallWindowProc and SetWindowLong win32 api, but now in VS2005 i cannot get it to work.
Still I have to try with unmanaged code or are there any other ways to do this in vb .net?

Last but not least, thanks you all for your help!
 
In form that is supplied as callback handle write 'overrides' and select WndProc in the list, in the generated method handle the message provided by m parameter.
 
In form that is supplied as callback handle write 'overrides' and select WndProc in the list, in the generated method handle the message provided by m parameter.

First of all, thanks a lot for your reply.
Everything works fine now, done it like you suggested.

Now I understand mine question was a little stupid, but I came from pure C programming, so OO languages like C# or VB .net are still something new for me.
A simple override of wndproc solved everything. Less than ten lines of code. Starting to love the power of playing with OOP! :)

P.S.
I put the "wndproc override" on the main form (main and only atm, need to write classes now, then I'll pass to the gui and end user part) , while I'm using a user defined object/class for midiplay and other things I need. Is it possible to put the wndproc override code in my own class instead than putting it in the callback form code? I've tried to modify the last value of mcisendstring win32 api call but with no sucess. It's ok even now, but I think putting it all on my own class will make code much clear and reusable.


As always, thank you all for sharing your knowledge. :)
 
The forms WndProc override comes down to the Control class that implements IWin32Window, which essentially is native window that messages can be sent to, so any class derived from Control and that is created and has a window handle can receive the callback. That said, there is also the NativeWindow class (implements IWin32Window also) that represent "a low-level encapsulation of a window handle and a window procedure". A class derived from this can act as a standalone window and its Handle can be the target for windows messages, or it can be used to route messages from other existing windows.
 
Back
Top