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

Started by
18 comments, last by FERNANDO-BRASIL 21 years, 7 months ago
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
Advertisement
What do you need to do with this toolbar? Have you tried sending it a message?
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]
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
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]
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
Thank you tom! But how I send a message to the parent window? I''m a beginner with MFC and don''t know the command!

Thank you!
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
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
Thank you guys!
Both solutions worked.

My code is running now! I really enjoyed your help!

Thank you again.
Fernando

This topic is closed to new replies.

Advertisement