|
I can create different views successfully if i create objects for each individual view as you said
AddView(new MyView(),_T("tab1"));
AddView(new MyView(),_T("tab2"));
But my requirement is not create multiple view objects, only one view object should be available and multiple tabs should exists. The single view should keep on refreshing when tabs are changed.
|
|
|
|
|
"only one view object should be available and multiple tabs should exists"
If you need just one view, why you need tabs then ?
|
|
|
|
|
Based on user selection, the graphics on the CView should change. On this CView i will load some Active X control to render the graphics on this window.
If i create multiple CViews with new object, then i have to load the Active X Control on each CView which is a costly operation and memory increases and it not a good way to deal as there are many issues with memory, performance and other areas in my application.
Thats why i want multiple tabs with one single view to solve my issue.
|
|
|
|
|
Then you should simulate tabs with some simple buttons, which will change the CYourView content ...
|
|
|
|
|
|
I have made an test app, SDI, MFC, with view based on CFormView. On this CView, I have put an CTreeCtrl object. And I have mapped NM_RDBLCLK, in this way:
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
afx_msg void OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult);
DECLARE_MESSAGE_MAP()
and
BEGIN_MESSAGE_MAP(CTestTreeView, CFormView)
ON_NOTIFY(NM_RDBLCLK, IDC_TREE1, &CTestTreeView::OnNMRDblclkTree1)
END_MESSAGE_MAP()
....
....
void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
MessageBox(_T("Aha"));
*pResult = 0;
}
but I hit right-double-click, is happen nothing ... why ? I haven't done enough to have this feature on my CTreeCtrl object ?
|
|
|
|
|
Perhaps because some of other handlers such as (
OnRButtonUp, OnContextMenu ) intercept it?
|
|
|
|
|
These handlers were not mapped in message map, but, just to be sure, I have commented them:
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult);
DECLARE_MESSAGE_MAP()
IMPLEMENT_DYNCREATE(CTestTreeView, CFormView)
BEGIN_MESSAGE_MAP(CTestTreeView, CFormView)
ON_NOTIFY(NM_RDBLCLK, IDC_TREE1, &CTestTreeView::OnNMRDblclkTree1)
END_MESSAGE_MAP()
...
...
void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
MessageBox(_T("Aha"));
*pResult = 0;
}
Still not working NM_RDBLCLK handler at all ! Strange ...
|
|
|
|
|
Not a solution but some thoughts. Your parent view has a context menu handler. As a result that will be always called before the NM_RDBLCLK handler when the tree control does not handle it:
If a window does not display a shortcut menu it should pass this message to the DefWindowProc function. If a window is a child window, DefWindowProc sends the message to the parent. Otherwise, DefWindowProc displays a default shortcut menu if the specified position is in the window's caption.
If you have a context menu (in the parent and/or child) it will be shown before the NM_RDBLCLK handler is called. Then there should be no reason to act upon double clicks too. The message will even not being generated when the mouse is over the meanwhile opened popup menu when the second click occurs.
|
|
|
|
|
Yes, I see your point, but I don't have any right click, or contextMenu, or shortcut menu handler neither in CMyView (derived from CFormView), neither in my CTreeCtrl object (IDC_TREE1) ... or, I miss something ?
|
|
|
|
|
From your initial post:
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); That is an MFC handler for WM_CONTEXTMENU .
|
|
|
|
|
Yes, that was the default code put there by MFC wizard, but there was not mapped in the message map ... anyway, I have commented up, and that was change nothing.
|
|
|
|
|
It is sufficient to comment the message map entries (which should be created too by the wizard).
By the presence of the context menu handler I assumed that you want to use it.
All I can think of is that the NM_RDBLCLK notification is not send by some processing in the default (right mouse button related) MFC CWnd or derivatives handlers.
Another source of not getting the notification might be handling the message in your derived tree control using ON_NOTIFY_REFLECT() . If so, use ON_NOTIFY_REFLECT_EX() instead and return FALSE to get the notification passed to the parent.
|
|
|
|
|
Thank you for your time, Jochen.
No, I am not using any derived CTreeCtrl, so, I cannot use anything than ON_NOTIFY notification.
|
|
|
|
|
Be sure that your CTreeCtrl has the CS_DBLCLKS class style.
Try to handle WM_RBUTTONDBLCLK message.
|
|
|
|
|
I have tried double-click too, not working:
ON_NOTIFY(NM_RDBLCLK, IDC_TREE1, &CTestTreeView::OnNMRDblclkTree1)
ON_NOTIFY(NM_DBLCLK, IDC_TREE1, &CTestTreeView::OnNMDblclkTree1)
void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
MessageBox(_T("Right dbl-click"));
*pResult = 0;
}
void CTestTreeView::OnNMDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
MessageBox(_T("Left dbl-click"));
*pResult = 0;
}
I modified the control style, as follow:
void CTestTreeView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
m_Tree.ModifyStyle(0, CS_DBLCLKS);
ResizeParentToFit();
}
where m_Tree is my CTreeCtrl object.
|
|
|
|
|
_Flaviu wrote:
m_Tree.ModifyStyle(0, CS_DBLCLKS);
No, it won't work!
just because CS_DBLCLKS is not a window style. It is a window class style!
But forget this! Note that double-click in a tree control is used by default to expand/collapse tree items!
So these messages are handled by control itself and therefore you cannot handle them in your code.
|
|
|
|
|
Yes, you are right, I guess this messages (double-click, and right double click) are handled by the control, that is why I cannot catch them. Thank you !
|
|
|
|
|
You could subclass the Tree Control (in your own class derived from CTreeCtrl).
In the derived class implement the ON_NOTIFY_REFLECT_EX macro to handle left/right double click and then pass (or not) this message for the further handling.
|
|
|
|
|
Hi
I have a requirement where i need to display few tabs and render something in only one view instead of creating multiple views for each tab. The reason is i am loading an active x control on that view. So, i written class which inherits from CTabView, but When i call AddView(), each AddView() is creating a new object and i need to load active x control on each view which is violating my requirement and unnecessary memory is getting created.
Is there is any way to create only one view for all the tabs, such that i can create only one view and load active x control on that view and switch the tabs to render different things on one view.?
Currently i am trying with tabbedpane assuming my above requirement will get solved.
Please let me know incase if there is any other option?
modified 13-Mar-18 23:59pm.
|
|
|
|
|
Why do you need multiple tabs in the first place? It sounds like you just want your view to render different data based on some external setting or user selection.
|
|
|
|
|
I have some drawings to display.
For Eg: I have a drawing file which internally contains 5 sub drawings in it. So based on no. of sub drawings, i have to create 5 tabs. In each tab each sub drawing should get render. But user is allowed to view only one sub drawing at a time i.e., the active tab drawing. Thats the reason why i need to create tabs.
When i click on first tab, first sub drawing will be displayed. if second tab is selected then second sub drawing should be displayed. like wise rest of the drawing when user selects the tab.
|
|
|
|
|
According to your original question your requirement is to have only a single View, so you do not need multiple tabs. You just need to render the appropriate drawing when the user makes a choice.
|
|
|
|
|
Yes exactly. I need only one view. But the User interaction should be on tabs. To be more precise, i need the UI in the form of tabs but the view should be only one.
But when i call Addview(), each time a new view is getting created.
|
|
|
|
|
Sampath579 wrote: But when i call Addview(), each time a new view is getting created. You need to show your code; it is difficult to guess what you are doing.
|
|
|
|