Jump to content
  • Advertisement

Archived

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

FERNANDO-BRASIL

MFC: #$@#$##$#@$#@

This topic is 5795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I''ve been trying to make a MFC application in the last 3 days, and I''m getting nervous with all this.... I didn''t understand well, but I think we can say MFC is subvided in 3 parts: CFrameWnd, CView and CDocument. Well, ok... My problem is that I have a toolbar declared in CFrameWnd and I want to access this toolbar when I''m inside CView. How can I do this? I just can''t understand this!! The application has a class CFrameWnd, but I don''t see anywhere the declaration of a variable for this class... so, how I''m going to access it?? By mind? Thank you guys. Fernando

Share this post


Link to post
Share on other sites
Advertisement
Yeah, but how Am'I goind to send the toolbar a message if there isn't a way to reference it?

The problem is that the toolbar is declared in the CFrameWnd class of the application.

To reference it, i would have to use something like this:

framewnd.Toolbar.SendMessage();

But I don't know how to do this! MFC is so different, I searched on the entire code, but I didn't find something like this:

CFrameWnd framewnd;

So, how does it work? I really don't know.

[edited by - FERNANDO-BRASIL on August 31, 2002 2:47:24 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think what''s going on here is that you are trying to put code in the wrong class. The way MFC was explained to me was as three layers of abstraction:

CFrameWnd handles the user interface (toolbar, menus, buttons, etc.)
CDocument stores the instance-specific data for a single document
CView creates a visual representation based on the given CDocument instance

So if there is a block of code which, say, enables or disables buttons on the toolbar, I would put that block of code in your CFrameWnd class.

Otherwise, CView should have a pointer to its CDocument, and CDocument should have a pointer to the CFrameWnd. There again I''m working from memory, as I haven''t used MFC in years.

Hope that helps.

Tom

Share this post


Link to post
Share on other sites
Thank you for the information Tom! It really helped me!

But let's say I want to enable all the buttons of the Toolbar when the mouse Moves on the Principal Application, How can I do that?

I tryed to make a CFrameWnd::OnMouseMove, but the application didn't send the message to it, it only sended the message to CView::OnMouseMove. And here, I don't have access to CFrameWnd...



[edited by - FERNANDO-BRASIL on August 31, 2002 3:01:39 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Glad I can be of help. But I''ve been playing with MFC for a few minutes and I can''t figure out how CView accesses CFrameWnd.

My only further suggestion is to let CView send a custom Window Message to the parent window by its window handle, and catch that in the CFrameWnd.

Hope that works out for you.

Tom

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Code is as follows:

void CMfctestView::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd *w = GetParent();
w->SendMessage(WM_MOUSEMOVE, nFlags, point.x + (point.y<<16));

CView::OnMouseMove(nFlags, point);
}

Then you can catch WM_MOUSEMOVE messages in CFrameWnd.

Tom

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Simple answer to your problem (2 actually);

For the default toolbar included in your Application:

First, include the MainFrame.h header in your view class:
#include "MainFrame.h" 


After that, take the tool bar declaration out of the protected member section of the MainFrame class header and put it in the public section.

Next where ever you want to use the tool bar, insert this snippet of code.

CMainFrame* pMainFrame;
pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;


And use the tool bar like this:
pMainFrame->m_wndToolbar.ShowWindow(SW_HIDE) 

Or what ever you want to do with the toolbar.

For future tool bars, goto the "project" menu, goto "insert component and controls", open up the VC++ library and insert a tool bar. Register the tool bar to the CView class when you are asked to provide the class that handles it.

-James

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!