Subclassing CTreeCtrl in CTreeView

I want to use a derived CTreeCtrl in a CTreeView and suppose I must subclass
the usual CTreeCtrl to achieve that.
How can I subclass the CTreeCtrl (and where should I put the subclassing
code)?
An example would help much of course


0
Hccnet (30)
7/18/2003 6:13:22 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1741 Views

Similar Articles

[PageSpeed] 45

"JackRnl" <Hccnet@Runit.Scarlet.nl> wrote in message
news:bf9dcf$5jb$1@news.hccnet.nl...
> I want to use a derived CTreeCtrl in a CTreeView and suppose I must
subclass
> the usual CTreeCtrl to achieve that.
> How can I subclass the CTreeCtrl (and where should I put the subclassing
> code)?
> An example would help much of course

Jack,

The bad news is that there is no CTreeCtrl to subclass, or rather the
CTreeView is the subclass of the WC_TREEVIEW common control. Now if you're
willing to be a guinea pig, I've spent the last week working on a template
class implementation that may serve to combine the implementation (assuming
it's message based) of your CTreeCtrl derived class with your CTreeView
derived class. Basically, it works something like...

    #include "MyTreeCtrl.h"
    #include "TCtrlView.h"
    DECLARE_CTRLVIEW(CTreeView, CMyTreeCtrl);
    class CMyTreeView : public CTRLVIEW::CTreeView
    {
    };

....Just keep in mind that its a beta. Fellow MVP, Doug Harrison has hinted
at another method he uses -- I think it was adding the derived CTreeCtrl to
a CView, and handling a few messages to wire it up. Frankly, his method
sounds a better way to go, and no doubt he can fill in the details. The
other way is to implement a custom WNDCLASS based on WC_TREEVIEW, and use
that to implement your own custom CWnd and CCtrlView wrappers.

--
Jeff Partch [VC++ MVP]



0
jeffp (1711)
7/18/2003 7:47:17 PM
On Fri, 18 Jul 2003 20:13:22 +0200, "JackRnl"
<Hccnet@Runit.Scarlet.nl> wrote in <bf9dcf$5jb$1@news.hccnet.nl>:

>I want to use a derived CTreeCtrl in a CTreeView and suppose I must subclass
>the usual CTreeCtrl to achieve that.
>How can I subclass the CTreeCtrl (and where should I put the subclassing
>code)?

You don't.  See these two articles instead:

<http://www.codeguru.com/doc_view/custom_view.shtml>
<http://www.codeguru.com/doc_view/Control2View.shtml>

-- 
Charles Calvert             |  Software Design/Development
Celtic Wolf, Inc.           |  Project Management
http://www.celticwolf.com/  |  Technical Writing
(703) 580-0210              |  Research
0
cbciv (23)
8/15/2003 3:33:42 AM
Reply:

Similar Artilces:

CTreeCtrl Drag&Drop Text problem.
When I do drap&drop tree item in a CTreeView derived window, the text does not show, only has the image icon. When I put a CTreeCtrl in a CFormView, the drag and drop has icon+ text(label). The codes for BeginDrag and moving are all most the same. I wonder what is wrong in CreateDragImage(). It assumes that this will create a bitmap with Icon and Text by call: HIMAGELIST hImageList = (HIMAGELIST)::SendMessage(m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem); Are there any differences in Drag& drop between CTreeView's CTreeCtrl and CTreeCtrl localted on CFormView ? Thanks f...

Subclassing
Hello, Im very new to c++ programming so pardon me if this is a dumb question and my bad english. I made a subclass from CListBox. I want to handle all the list controls derived from this class on one function, for example, void CListBox_SC::OnRButtonUp(UINT nFlags, CPoint point) { ..... } on this function I want to manage the OnRButtonUp event, and with a switch or if statement, select the code to execute. The following does work: SetCurSel(ItemFromPoint(point, ifp)); but the following comparison is never true, (IDC_LST_TIPO is a resource for one of the ListBoxes) UINT currLst = It...

Custom Drawing CEdit : Subclassing
Hello experts, My objective is simple, but I'm not entirely sure what needs tweaking. I am using MSVC 6, and I would like to subclass the CEdit box so that it appears as the color-picker editbox of a PropertyGrid. There is a color box followed by three values. Like this: [###] 255; 192; 192 Where ### is just a color box representation of the value. So thus far, I've made a masked CEdit box, where I can edit the numbers (or click a button that visually sets the numbers from a different window), and I'm happy with that - but what I would like to do next is to subclass the dra...

CTreeCtrl SortChildren centers the selection, moves scrollbar
I've encountered a situation where calling SortChildren (or SortChildrenCB) centers the scrollbar of my CTreeView pane for the selected item (even if the scrollbar was all the way to the left) I can't find anything in the knowledge base on microsofts site about this at all. Anyone have any ideas? Thanks -Cindy If I was to guess at what you are trying to say, seems like that your Horizontal Scrollbar gets centered when you sort your treectrl. That's because the selected item at the time of SortChildren call is larger than the width of the window. I think there is only one way...

Vector CTreeCtrl
Hi, I am not able to add an item to a vector of type CTreeCtrl. vector<CTreeCtrl> v; CTreeCtrl obj; v.push_back(obj); throws an error : Error 1 error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxwin.h 1820 Vector of strings or other regular items works fine. Please let me know if you know the answer to the same. Thanks, Hemanth On May 28, 3:05 pm, Heman...@gmail.com wrote: > Hi, > > I am not able to add an item to a vector of type CTreeCtrl. > > ...

Help with subclassing a RichEditCtrl
Hi folks, I could use some help. As a side project I am trying to write a DLL that will extend the functionality of an existing application that I do not have source code for, i.e., some autocompletion functionality, word lookup, etc. In the actual DLL, I am going to have to inject it into the existing app and then use FindWindow or something like that to subclass the existing RichEditCtrl. I need to be able to process the WM_CHAR and WM_KEYDOWN messages only. I started out by creating my own sample project using a RichEditCtrl in my project to code my object. I've now moved everythin...

Updating CTreeCtrl from other view ?
I have a CTreeCtrl and a 3D render view. With the mouse, I create elements picking in the 3D render view. This elements must be showed in the CTreeCtrl. What is the process to do it? I think 3D render view must send a message to the CTreeCtrl. CTreeCtrl captures it and update itself. But what kind of message and how? On Jul 16, 8:35=A0am, Ravnock <Ravn...@discussions.microsoft.com> wrote: > I have a CTreeCtrl and a 3D render view. > > With the mouse, I create elements picking in the 3D render view. This > elements must be showed in the CTreeCtrl. > > What is the ...

WM_CREATE for a subclass
Hi All, I am fairly new to C++, although I have developed OO windows applications in the past using CTD and Power Builder. I am developeing an edit class based on a CEdit. I am trying to trap the WM_CREATE message to modify the style of the window (i.e. to make is multiline). For some reason the control does not appear to be getting the WM_CREATE message ( or at least it is not implementing the handler I have for it). At present I create an edit control on a form and the Subclass the edit. This appears to work as my user defined menu is used and my color modifications appear as requir...

CTreeCtrl::DeleteAllItems problem
Hi all, I have faced a weird problem with a CTreeCtrl control. I have a function which has the responsibility of refreshing a tree control, which means deleting all the previous items, and populating the tree again. I wrote a helper function which deletes all the previous items, and creates a root item which will be later used. Here's the function's code: bool CSekManView::InitializeGroupTree() { if (m_ctlMainTree.GetCount() > 0) if (!m_ctlMainTree.DeleteAllItems()) return false; TVINSERTSTRUCT tvis =3D { 0 }; tvis.hParent =3D NULL; tvis.hInsertAfter =3D TVI_FIRST; tvis...

Subclassing CWinThread
I created a subclass of CWinThread - no big deal! Now, what I would like to do is use that subclass as a base class for a couple of other, more specialized classes. How can I do this? If I create a subclass as a generic C++ class, then I'm running into the assertion, "Invalid Address specified to RtlValidateHeap( 00940000, 0042DBA0 )" when I post the quit message to the thread. I assume this might have something to do with the virtual/non-virtual constructor combination of the MFC class and the generic C++ class. Any thoughts? Create more subclasses of CWinThread, then ...

CTreeCtrl drag and drop
Alright, I've been looking everywhere for this. I'm using a CTreeCtrl in VC++6.0. I am able to get the drag and drop functionality to work the way I'd like. The CImageList, and dragicon is showing correctly and where I want it. However, with the OnMouseMove() method, the item selected (and thus HitTest()'ed) is not at the end of my mouse pointer. It is below the bottom of the mouse pointer. I though I could resolve this with GetClientRect() and GetWindowRect() manipulation, but I think that whatever point is being passed to this function is incorrect. The problem may al...

Subclassing TreeView
I created a class derived from a TreeView (ShellTree) that displays the Shell directory structure . I changed the LeftView class so that it is derived from my ShellTree class, and everything works as expected, except I cannot add any TreeView specific message handlers to my LeftView class any more eg. NM_DBLCLICK. Basically in a nutshell what i want to do is display the directory name (which is stored in a variable in the ShellTree class) when the LeftView is Double clicked Check out http://www.codeproject.com/treectrl/enumdeskclones.asp Which isn't perfect.. but is a good star...

CTreeCtrl ASSERT question?
1) Why do I get a "Debug Assertion Failed!" when I insert an item in the CTreeCtrl as shown below? BOOL CDeviceProp::OnInitDialog() { // TODO: Add extra initialization here mDeviceTreeCtrl.InsertItem( "TEST" ); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDeviceProp::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO: Add your control notification handler code here *pResult = 0; } 2) Is it poss...

No refresh CTreeCtrl
How to update a CTreeCtrl, without repaint it? So, I refresh only one time and my program becomes more fast. Thanks Carlos ...

Subclassing a subclass of CDialog, for cross-platform compilation
Hi people, I've been working on porting an app from PC to Mac. What I'm trying to do, is separate out the PC specific components into it's own subclass. So there are the PC specific functions like PCAppDlg::OnBtnClicked1, and mac specific functions like MacAppDlg::BlaBlaBla. Of course the Mac subclass doesn't compile on the PC, and the same the other way around. I've had to write my own CDialog wrapper for Mac but that's another story. Now anyhow, this leads me to a question. How to subclass a subclass? Specifically, how does the message maps work? Will there be any p...

avoid Drag & Drop in CTreeView
I've got a CTreeview and want to disallow Drag&Drop if not in 'editmode' To handle DAD I use void CMyTreeView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)pNMHDR; *pResult = 0; // allow drag ...... } What shoiuld I do to diallow it (because it works 'always') JackRnl wrote: >I've got a CTreeview and want to disallow Drag&Drop if not in 'editmode' >To handle DAD I use > >void CMyTreeView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) >{ > NM_...

Traversing a CTreeCtrl structure
Below is a segment of the example published in msdn.microsoft.com for the usage of the DeleteItem method of CTreeCtrl. I ran this in the Visual C++ debugger, and the call to GetNextItem fails. The call stack shows the following call: CTreeCtrl::GetNextItem(_TREEITEM * 0xffff0000,unsigned int 1). I hope you can point me to where I went wrong. Thanks for your help, Miguel // Gain a pointer to our tree control CTreeCtrl* pCtrl = (CTreeCtrl*) GetDlgItem(IDC_TREE1); ASSERT(pCtrl != NULL); // Look at all of the root-level items HTREEITEM hCurrent = pCtrl->GetNextItem(TVI_ROOT, TVGN_NEXT); ...

Xml Serializing subclass problem
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. Actually, the class I'm serializing is two steps down in the inheritance ladder. It's got a parent class which also has a parent class :( All those classes in the hierarchy are Xml Serializable, and I'd think that it should be obvious that all attributes/properties of the parents should be serialized for any given subclass, no ? Here's the two classes, subclass first, parent class...

CTreeCtrl / deleting selected item
All I have a CTreeCtrl with theTVS_SHOWSELALWAYS style. If the program deletes the item that is currently selected, I would like to disable the program from automatically selecting a different item (I would like there to be no selection at all in this case). Anyone any idea how this could be achieved ? Many thanks in advance! Sorry - already figured it out. before running ... treeCtrl.DeleteItem(itemh); I am just calling this ... if (treeCtrl.GetSelectedItem() == itemh) treeCtrl.SelectItem(NULL); ...

Subclassing problem???
Hi there, I've got: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch(uMsg){ case WM_NCACTIVATE: if((BOOL)wParam==FALSE){ DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); return TRUE; } case WM_NCPAINT: DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); break; } DefWindowProc(hwnd, uMsg, wParam, lParam); } void CreateText(HWND hwnd){ HDC hDC = GetWindowDC(hwnd); int x,y; RECT rc1,rc2; GetWindowRect(hwnd, (LPRECT)&rc2 ); x = GetSystemMetrics(SM_CXSIZE) + GetSystemMetrics(SM_CXBORDE...

CTreeCtrl : CustomDrawn => uItemState alaways equal to 0
Hi, I have just started playing with CustomDrawn to modify dynamically item background and have realised that every time i test ed the uItemState flag of the message, it was always equal to 0 :( exemple : void CMyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR ); if (pLVCD->nmcd.uItemState!=0) { //Never enter here } *pResult = 0; } It s just so disturbing because it has to be simple. Could someone ple...

subclassing CStatic
Hi, I have subclassed a few CStatic ctrls so i can quickly change their font, BG and FG colors etc... I have also handled the CFormView's CtlColor message and painted the form white and text blue. The problem that im having is the subclassed objects are painting themselves the colors i specify, then the CFormView::OnCtlColor is painting them again. This isnt too much of a problem as i can simply exclude the subclassed items from the painting using: HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { // create white brush: m_DlgBrush.DeleteObject(); ...

CTreeCtrl : change item rect #2
Hi, Anyone knows how to change the items rect in a CTreeCtrl object? Thanks in advance, Jorge Loureiro ...

VC
I need a way to come up with a simple (free) combobox activeX control I can use in a third party development tool. I tried just subclassing ComboBoxEx using the ActiveX control wizard in VC6. It clearly creates the control, but it doesn't seem to be created with the properties and methods (like AddItem/New) and when I plop on a VB6 form it doesn't look like a combobox. Granted I am newbie working way over my head, by why would the ActiveX control wizard ask me which control to inherit from if it isn't going to give me _roughly_ the same functionality? Can anyone point me in a di...

subclassing CComboBox
compiler: VC++ 6.0 SP 6, running XP Pro SP 2. I subclassed CComboBox into CMyComboBox, then setup up event handlers for several of the reflected events -- one being CBN_CLOSEUP reflected event. I have an object of type CMyComboBox in an MFC program, which also needs to catch the CBN_CLOSEUP event. I used ClassWizard to create all event handlers. Problem: The event handler in CMyComboBox works ok, but the handler in the application program never gets called. Is there a way around this problem? I tried posting a message to the parent window but that didn't seem to work either (pare...