Classname of ActiveWindow in MFC
In my MDI application I'm loading one DialogBar in mainframe.But I want to show that DialogBar when some child window gets invoked(GroupView,TrendView).For other windows it should be hidden(GraphView).So for all functions used to invoke child window from CMainFrame is hiding the DialogBar like this.
void CMainFrame::OnGroupview()
{
.
.
.
m_RecentAlarms.ShowWindow(SW_HIDE);
}
For some view
void CMainFrame::OnGroupview()
{
.
.
.m_RecentAlarms.ShowWindow(SW_SHOW);
}
So,when I click TrendView I get the DialogBar and when I click GraphView the DialogBar gets hidden.But Again when I click TrendView I didn't get Dialogbar. Because the application is multiple window.The previous TrendView is behind the GraphView, when i invoke just it show in front.
So my idea is I have one thread in Mainframe,this function updates some values in all views.In that I will check whether the Active View is TrendView, if it is so then DialogBar will be shown other wise it will be hidden.
I used this..
CMDIChildWnd* pChild = ((CMainFrame*)AfxGetMainWnd())->MDIGetActive();
开发者_如何学JAVABut I dont know how to get the active view is TrendView only....
Pls help me in this issue.
Here, you have the active window in pChild
.
Hope you have a member variable corresponding to each view (GraphView, TrendView etc)
I suppose it will be something like: m_GraphView
, m_TrendView
etc.
Now what you have to do is compare the handles of both the windows.
Try this code:
if( pChild->GetSafeHWND() == m_GraphView.GetSafeHWND() )
{
m_RecentAlarms.ShowWindow(SW_HIDE);
}
else
{
m_RecentAlarms.ShowWindow(SW_SHOW);
}
To compare the handle of the window is the best way.
First, CMDIFrameWnd::MDIGetActive gets the active MDI child frame.
Next, you can get its active view by a call of CFrameWnd::GetActiveView.
Finally, call CObject::IsKindOf.
Example:
CMDIChildWnd* pFrame = ((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
if(NULL != pFrame)
{
CView* pView = pFrame->GetActiveView();
if(NULL != pView)
{
if(pView->IsKindOf(RUNTIME_CLASS(TrendView)))
{
// The active view is of type 'TrendView'
}
else if(pView->IsKindOf(RUNTIME_CLASS(GraphView)))
{
// The active view is of type 'GraphView'
}
}
}
Notes:
- Be sure the view classes have defined DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE in order to use IsKindOf(RUNTIME_CLASS...
- I posted here related sample code about finding the active view in SDI/MDI MFC applications.
精彩评论