Archived

This topic is now archived and is closed to further replies.

gavrhen

Weird Problem with MFC!

Recommended Posts

Before I begin I gota tell you I''m a somewhat new to MFC so don''t try to kill me if the problem probably has an easy answer. First I added in a CDirect3D class to my SDI app that had a base class of CView. I then added in OnDraw OnCreate OnDestroy and some other functions to the CDirect3d class. My problem is that none of those messsage maps are being called. How I tested this was by first putting in a command to make my speaker beep in the CView:OnDraw. It beep but when I put it in CDirect3d:OnDraw nothing beeped at all. What it the world am I doing wrong. I thought that the CDirect3d::OnDraw would be called or even overload the CView::OnDraw. Some help and advice on a good MFC programming book would help.

Share this post


Link to post
Share on other sites
Did you add the OnDraw manually to your DirectDraw class? You shouldn''t. There is something called a message map, if you are new to MFC leave it alone.

I suggest you reconstruct the class using the class wizard.

D.V.

Share this post


Link to post
Share on other sites
This is a quote from Programing Windows with MFC by Jeff Prosise

"What MFC message-mapping mechanism amounts to is a very efficient way of connecting messages to message handlers without using virtual functions. Virtual functions are not space-efficient because they require vtables, and vtables consume memory even if the functions in them are not overridden."

Why couldn''t MFC designer just make some kind of mechanism that didn''t bother the programer with writing Macros or using the wizards? Just standard c++ would be fine.

Share this post


Link to post
Share on other sites
quote:
Original post by gavrhen
How I tested this was by first putting in a command to make my speaker beep in the CView:OnDraw. It beep but when I put it in CDirect3d:OnDraw nothing beeped at all.



I''m used to working with MFC ( 4 years experience already ), and from what I''m reading here, I think I can deduce the problems:

How can you put a speaker-beep command in CView::OnDraw? Have you been modifying the MFC source, or do you have two CView-derived classes in your project? If you have two, you''re probably never using the CDirect3d class in your document-view architecture.
By the way, there''s an easier way to find out if a function gets called, which is the TRACE macro. It "traces" (outputs) a string into the debugger-output window of visual studio. For instance, you could put TRACE( "CView::OnDraw\n" ) in the corresponding function, and you''d see that string show up in the debugger output window if the function was ever called.

The easiest thing to do would be to post a link to your code (MainFrm, document and views) so I could have a look at it, see if the message maps are correct, and the right view is attached to the document.
MFC and the Doc/View architecture aren''t particularly elegant, specially if you are new to them. It takes a while to get to know its quirks.




People might not remember what you said, or what you did, but they will always remember how you made them feel.
Mad Keith the V.

Share this post


Link to post
Share on other sites
gavrhen-

Check out this link at CodeGuru.com. The <> link may help you.

http://codeguru.earthweb.com/directx/index.shtml

Share this post


Link to post
Share on other sites