Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message handler not working in CMainFrameClass

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
US
Hi<br>&nbsp;&nbsp;I have generated a application ( a do nothing) application<br>using appWiward . I addded a private status bar variable<br>in CMainFrame class . I want that on mouse move the mouse<br>coordinates should be displayed in the status bar . So I<br>have added a WM_MOUSEMOVE message handler in the CMainFrame<br>class . And on this handler i am showing the mouse position<br>in the status bar . But problem is that on moving the mouse<br>also , the code is not being executed .Why is it so ? If<br>we can't access the mouse handler then how to get the mouse<br>position in the CMainFrame class . I can get it in the view<br>class, but my status bar is private member of the cMainframe<br>class . So how do i show the mouse position in the status<br>bar . <br>&nbsp;&nbsp;Please reply this ASAP . I would be really thankful to you..<br>&nbsp;&nbsp;&nbsp;&nbsp;Regards<br>&nbsp;&nbsp;&nbsp;Dev
 
Dear Moonoo,<br><br>There are many ways to build a solution, here is one way, not necessarily a good way, but this should get you going.<br><br>class CMainFrame : public CFrameWnd<br>{<br>.... <br><br>public:<br>&nbsp;&nbsp;void updateMouseCoordDisplay( int x, int y){<br>&nbsp;&nbsp;&nbsp;&nbsp;CString posout;<br>&nbsp;&nbsp;&nbsp;&nbsp;posout.Format(&quot;x:%d y:%d&quot;, x, y);<br>&nbsp;&nbsp;&nbsp;&nbsp;theStatusBar.SetPaneText( EPANE_MOUSEPOS, posout);<br>&nbsp;&nbsp;}<br>};<br><br>class CMyView : public &lt;whatever&gt;<br>{<br>....<br>&nbsp;&nbsp;afx_msg void OnMouseMove(UINT flags, CPoint pt);<br>};<br><br>void CMyView::OnMouseMove(UINT flags, CPoint pt){<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;CMainFrame* pFrm = <br>&nbsp;&nbsp;&nbsp;&nbsp;dynamic_cast&lt;CMainFrame*&gt;( AfxGetMainWnd());<br><br>&nbsp;&nbsp;if ( pFrm)<br>&nbsp;&nbsp;&nbsp;&nbsp;pFrm-&gt;updateMouseCoordDisplay(pt.x, pt.y);<br>}<br><br>Hope this helps<br>-pete<br>
 
Hi<br>&nbsp;Thanks a lot for your reply . Is there any other<br>ways to solve the same problem.But why are the<br>mouse message handlers are not working in the CMainFrame<br>class ? Please reply...<br>&nbsp;&nbsp;Thanks a lot again for your reply..<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;moonoo
 
Dear Moonoo,<br><br>For example another approach would be to create your own message, i.e., (WMUSER_UPDATEMOUSEPOS) and handler in your CMainFrame class. Then use SendMessage from your view class to talk to the frame.<br><br>Another (poor.. in my opinion) is to just have the view get a pointer to the CStatusBar member from the frame and keep it. Then use the status bar directly in the mousemove handler of the view.<br><br>Yet another is to define an interface for communicating to the statusbar and derive the frame class from it. <br>&lt;<br>struct IMousePosDisplay{<br>&nbsp;&nbsp;virtual void IMPD_onMouseMove(int x, int y);<br>}<br><br>class CMainFrame : public CFrameWnd, IMousePosDisplay{<br>...<br>public:<br>&nbsp;&nbsp;virtual void IMPD_onMouseMove(int x, int y){<br>&nbsp;&nbsp;&nbsp;&nbsp;// update the status bar...<br>&nbsp;&nbsp;}<br>}<br>&gt;<br>Then supply the View with a pointer to the interface instance for the purpose of updating the status bar display. This way if you choose to move the responsibility for handling that function to another class later the view never has to know about it. Also if you choose to display the mouse postion other than in the status bar, again, the view doesn't need to know.<br><br>Do you still have the handler for mousemove in the View class? This is one reason that the frame would not process the event.<br><br>-pete<br><br>
 
Thnaks for the prompt reply . I got all your<br>answers . That cleared all my doubts . If I<br>have any doubts in future , please help me .<br>&nbsp;&nbsp;&nbsp;Thanks again<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Moonoo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top