15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Dynamic spin controls on tree ctrl label editing?

Deepak Saxena -- Deepak_Saxena@ccm.ch.intel.com
Tuesday, February 20, 1996

Environment: VC++ 4.0 / Win NT 3.51

I have a treeview in which I am allowing label editing for 
certain tree items, and I want to create a spin control 
dynamically when the user begins editing an item that contains 
an integer only value.  Here is my current code snipet that 
tries to do this(Taken from CMyTreeView::OnBeginLabelEdit()):

// Have already validated that item is editable, etc, etc
//Get edit ctrl
CEdit *pEdit = GetTreeCtrl().GetEditControl();

// Subclass it...CIntEdit accepts only digits
m_wndIntEdit.SubclassWindow(pEdit->m_hWnd);

// Get edit rectangle, find spin ctrl rectangle
CRect rectEdit;
pEdit->GetWindowRect(&rectEdit);
ScreenToClient(&rectEdit);
rectEdit.left = rectEdit.right;
rectEdit.right = rectEdit.left + 16;

//Create spin control
m_wndSpin.Create(UDS_SETBUDDYINT | UDS_WRAP | UDS_ARROWKEYS, 
	rectEdit, &GetTreeCtrl(), IDC_SPIN_INTPROP );

// Set buddy window
m_wndSpin.SetBuddy(pEdit);

// Show spin control
m_wndSpin.ShowWindow(SW_SHOW);

Now...the above does not work.  The spin control never shows up.
I've also tried to change the &GetTreeCtrl() parameter to this,
so that the view is the parent of the ctrl instead of the 
treectrl. Still no luck.  My current option I am looking at if 
this is not possible is to just dump the standard edit box that 
CTreeCtrl creates and create my own edit box and spin control by 
overiding OnSelChange().  Is there an easier way?

Tnx,
Deepak



Mike Blaszczak -- mikeblas@interserv.com
Thursday, February 22, 1996

On Tue, 20 Feb 1996, Deepak Saxena  wrote:
>Environment: VC++ 4.0 / Win NT 3.51

Thanks.

>// Get edit rectangle, find spin ctrl rectangle
>CRect rectEdit;
>pEdit->GetWindowRect(&rectEdit);
>ScreenToClient(&rectEdit);
>rectEdit.left = rectEdit.right;
>rectEdit.right = rectEdit.left + 16;

>//Create spin control
>m_wndSpin.Create(UDS_SETBUDDYINT | UDS_WRAP | UDS_ARROWKEYS, 
>	rectEdit, &GetTreeCtrl(), IDC_SPIN_INTPROP );

Does Create() return TRUE or FALSE?  You should check return codes, you know.

You're making the new up/down control a child of the edit control without 
using the WS_CHILD style.  You're also positioning the control in client 
coordinates relative to the list view rather than the edit control, though 
you've made it a child of the edit control.  If its a child window, it should 
be positioned relative to the parent, not relative to the parent's parent.

Even if you positioned the control correctly, it wouldn't show up because, as 
a child window, it would be clipped--it's being created outside of the area 
of the edit control.

>// Set buddy window
>m_wndSpin.SetBuddy(pEdit);
>
>// Show spin control
>m_wndSpin.ShowWindow(SW_SHOW);

Why not just use the WS_VISIBLE style?

>Now...the above does not work.  The spin control never shows up.
>I've also tried to change the &GetTreeCtrl() parameter to this,
>so that the view is the parent of the ctrl instead of the 
>treectrl. Still no luck.  My current option I am looking at if 
>this is not possible is to just dump the standard edit box that 
>CTreeCtrl creates and create my own edit box and spin control by 
>overiding OnSelChange().  Is there an easier way?

I think that if you get your window positioning and child-parent relationship 
in order, you'll have less trouble.

I don't have time to research it for you, but I suppose it is possible that 
this edit control is similar to the drop-down box of a combo box. That is, 
Windows might create the control as a top-level window so that it can appear 
anywhere, over anything, across any window border.  You might neeed to use a 
similar technique for your up-down control.

.B ekiM
--
TCHAR szDisc[] = _T("These words are my own; I do not speak for Microsoft.");





| Вернуться в корень Архива |