Link to home
Start Free TrialLog in
Avatar of mustang070597
mustang070597

asked on

Windows Messaging

Hi,
Having a little problem with VC++ 4.2 (&5.0) sending and receiving messages.  It is probably something stupid I'm doing, but I cannot send messages to my application.  I have a couple of instances.  

First off, I start a timer as this->SetTimer (1, 5000, NULL);  from the CMainFrame class initialization.  I've tried it from a few other places, such as OnOpenDoc, but this is where it is now.  This sends a message to my CMainFrame class object, and I have to put the message handlers in by hand since ClassWiz won't do it.  The CView class, on the other hand, does have a ClassWiz interface which I use to put in the OnTimer handler.  The problem is, the WM_TIMER message only goes to the MainFrame, and not the View class.  The way it's explained in the VC++ Programmers guide, the MainFrame is supposed to pass the message on to a number of other objects, but it isn't.  Is there something I need to do to get it to forward it?  

I am also having the same problems sending basic messages from anywhere in my code to my application.  Is there something undocumented to this?  I've seen example code where they just do a PostMessage with the Main windows handle, and that's all they do.  What gives?  I have tried all the versions of PostMessage, using the AfxGetMainWnd() to get the Window, passing in the handle of the window, and just using the NULL parameter to supposedly send to my app, but the messages never show up.  The return from the PostMessage says it did it, but Spy doesn't even see any message comming out, and the app doesn't respond in any of the class objects to the message.  Any help is appreciated.

Mark
ASKER CERTIFIED SOLUTION
Avatar of milenvk
milenvk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Answers2000
Answers2000

"First off..." etc.

1. WM_COMMAND messages get rerouted

2. WM_TIMER messages can be sent to anywindow if you set them up as such.  The MFC class will send em to the class the timer is created in or an alternative call back function you can optionally provide.  The API version of the function can send WM_TIMER messages to anywindow, provided you have a pointer to the CWnd or the hWnd of the window you want to send the messages to, example:-
::SetTimer( pWnd->m_hWnd, 1, 5000, NULL ) ;
or
::SetTimer( hWnd, 1, 5000, NULL ) ;

:: means global scope, which means use the global SetTimer function (the API version) rather than the CWnd::SetTimer function.


"I am also having...etc"
PostMessage is asynchronous (the message is queued to be processed whenever Windows feels like) a success return value means it was posted to the queue successfully, that's all

see also SendMessage which is synchronous (doesn't return until the message is processed).

Your params may be wrong, post the line if you need more help.


BTW
Milenvk's answer looks like it will work to me, but isn't strictly necessary for what I think you're doing (he's forwarding all Timer messages sent to the mainframe to all views).




Avatar of mustang070597

ASKER

Thanks, this looks good.  I've also had the same problems with SendMessage that I described above, but I think I've been confusing Command messages with User messages.  I've been looking at this more like a socket/PDU interface than a Windows Messaging structure and that's where I'm going wrong.  I'll accept this for now and keep working.  I'm mainly just collecting info and developing test programs before starting  a larger design/development project.  Thanks again.