|
I don't know why that happens. I have just tried it with a simple dialog based app and the button looks like those from the dialog template.
|
|
|
|
|
You can see my window with tab control and the look of the button in below link. I just created a class which inherits from CTabView which created a window with tabcontrol and added a code to create a button at bottom of the window. But the button does not look like push button.
Imgur: The magic of the Internet[^]
|
|
|
|
|
It looks exactly like a Pushbutton to me. Are you using the correct themes and version of the Windows Common Controls[^]?
|
|
|
|
|
Instead of inheriting a class from CTabview, this time i inherited from CScrollView and created a button on it which you can see in below link. This button perfectly looks like pushbutton and when i click on the button, there is some interaction i can see, i.e., button movement in and out. You can even observe a border on this button since i clicked on it.
Imgur: The magic of the Internet[^]
I am not understanding how this behaviour is getting differ from a CTabView class to CScrollView class.
|
|
|
|
|
I wonder if the problem is that the CTabView has not been designed to allow what you want. Perhaps you should switch to the underlying CMFCTabCtrl Class[^], and roll your own version.
|
|
|
|
|
I created a class which inherits from CTabView as follows:
class CTabClass : public CTabView
{
void OnCreate()
{
m_CView = RUNTIME_CLASS(CDocumentView);
AddView(m_CView,_T("Tab1"));
AddView(m_CView,_T("Tab2"));
}
}
I want only one view for all the tabs. Is it possible in MFC?
|
|
|
|
|
How many more times do you plan to repost this question? We have explained why this will not do what you want, and given some suggestions for finding an alternative approach. Please try some of those suggestions for yourself.
|
|
|
|
|
Yes, it could work, but not like you tried above ... think that m_CView is the same CView instance on every tab, which is impossible ... but you can try to create a new instance on every AddView call, something like that:
AddView(new CYourView(),_T("Tab1"));
AddView(new CYourView(),_T("Tab2"));
this is simplistic approach, that I wrote it just you see the point, but in a real situation, you have to elaborate this: create any instance of CYourView object you need, add every one of them in an array of pointers, and supply this pointers on AddView call as first argument. Do you understand what I say ?
|
|
|
|
|
And the solution that I just give you is more as you see why your approach is not working than to be applied in your application ... because the creation of your CYourView is not that simple ... they must be attached at you CDocument, and so on ...
Because you have problems in completing your task, this reveal that your approach is not right ... you have to think to another ...
|
|
|
|
|
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.
|
|
|
|