|
|
|
date: Mon, 04 Aug 2008 01:31:45 -0700,
group: microsoft.public.win32.programmer.ui
back
TreeView - Second Hit on Same Selection.
Hi Folks:
Developing on XP Home, VS 2008 Pro, WIN32, no MFC.
This application uses a TreeView control to select text that
will be inserted into an edit box.
The TVN_SELCHANGED notification is received each time the
user selects a different piece of text from the TreeView.
The problem occurs when the user wants to repeat the same
piece of text. The second selection of the text isn't changing
the selection, so there is no TVN_SELCHANGED notification.
I've attempted to add
SendMessage(treeview_handle, TVM_SELECTITEM, TVGN_CARET, NULL);
to the end of the function that services the TVN_SELCHANGED,
but that causes another TVN_SELCHANGED to be received, and this
is for the first (top) visible TreeView item. So the app inserts
two pieces of text. The text selected by user, followed by the
text that would be selected if the user had clicked at the top
item.
So, what's the correct way to process two consecutive taps
on the same item in a TreeView?
Thanks
Larry
date: Mon, 04 Aug 2008 01:31:45 -0700
author: Larry Lindstrom
Re: TreeView - Second Hit on Same Selection.
"Larry Lindstrom" wrote in message
news:UZmdncmvhJblIwvVnZ2dnUVZ_v3inZ2d@comcast.com...
> Hi Folks:
>
> Developing on XP Home, VS 2008 Pro, WIN32, no MFC.
>
> This application uses a TreeView control to select text that
> will be inserted into an edit box.
>
> The TVN_SELCHANGED notification is received each time the
> user selects a different piece of text from the TreeView.
>
> The problem occurs when the user wants to repeat the same
> piece of text. The second selection of the text isn't changing
> the selection, so there is no TVN_SELCHANGED notification.
>
> I've attempted to add
>
> SendMessage(treeview_handle, TVM_SELECTITEM, TVGN_CARET, NULL);
>
> to the end of the function that services the TVN_SELCHANGED,
> but that causes another TVN_SELCHANGED to be received, and this
> is for the first (top) visible TreeView item. So the app inserts
> two pieces of text. The text selected by user, followed by the
> text that would be selected if the user had clicked at the top
> item.
>
> So, what's the correct way to process two consecutive taps
> on the same item in a TreeView?
Hi larry.
Firstly i must say i don't think your control use is a bit unappropriate.
Unless you have more than 1-2 tree-levels i would suggest a listbox and
above it either tabs or a dropdowncombo.
From your description i get the impressing that a single click cause the
text to be added somewhere. I would consider a double-click instead (not
sure do you get notified about it but you can have a counter that notice
when you have clicked it an even number of times) or have a default button
do it (click item + enter). Or maybe you should just add a Repeat button.
- Sten
date: Mon, 4 Aug 2008 12:19:15 +0300
author: Sten Westerback \(MVP SDK 2005-6 :\)
Re: TreeView - Second Hit on Same Selection.
Sten Westerback (MVP SDK 2005-6 :) wrote:
> "Larry Lindstrom" wrote in message
> news:UZmdncmvhJblIwvVnZ2dnUVZ_v3inZ2d@comcast.com...
>> Hi Folks:
>>
>> Developing on XP Home, VS 2008 Pro, WIN32, no MFC.
>>
>> This application uses a TreeView control to select text that
>> will be inserted into an edit box.
>>
>> The TVN_SELCHANGED notification is received each time the
>> user selects a different piece of text from the TreeView.
>>
>> The problem occurs when the user wants to repeat the same
>> piece of text. The second selection of the text isn't changing
>> the selection, so there is no TVN_SELCHANGED notification.
>>
>> I've attempted to add
>>
>> SendMessage(treeview_handle, TVM_SELECTITEM, TVGN_CARET, NULL);
>>
>> to the end of the function that services the TVN_SELCHANGED,
>> but that causes another TVN_SELCHANGED to be received, and this
>> is for the first (top) visible TreeView item. So the app inserts
>> two pieces of text. The text selected by user, followed by the
>> text that would be selected if the user had clicked at the top
>> item.
>>
>> So, what's the correct way to process two consecutive taps
>> on the same item in a TreeView?
>
> Hi larry.
>
> Firstly i must say i don't think your control use is a bit unappropriate.
> Unless you have more than 1-2 tree-levels i would suggest a listbox and
> above it either tabs or a dropdowncombo.
Thanks Sten:
The text the user can select is under different categories.
I use the top level TreeView items to display the category name,
with NULL lparams, and it's children that have lparams that point
to the text constants to insert.
There are more TreeView items than will fit on a page, and
though I initialize the TreeView with each category expanded, the
user has the option of collapsing categories that don't interest
them. This will allow them to have text that does interest them
available without scrolling to it.
> From your description i get the impressing that a single click cause the
> text to be added somewhere.
The receipt of the TVN_SELCHANGED causes the application to
replace the selected text in the edit box, this is usually the
point after the last entered text, but the user can select other
text with the usual Windows methods.
If I'm not sending TVM_SELECTITEM with a NULL item, the
TreeView doesn't send TVN_SELCHANGED when the same item is
clicked.
If I'm sending TVM_SELECTITEM with a NULL item after
processing each TVN_SELCHANGED, the control sends another
TVN_SELCHANGED notification. This wouldn't be a problem if
the item referred to in this second notification had a NULL
lparam, as one might expect when making no selection, but
instead the notification references the top visible TreeVeiw
item, which usually has valid data, which my code can't
recognize as being something to ignore.
After the TreeView's selection is added, the the edit box
selection is set to the character following the replacement. A
task MicroSoft also makes unnecessarily difficult.
> I would consider a double-click instead (not
> sure do you get notified about it but you can have a counter that notice
> when you have clicked it an even number of times) or have a default button
> do it (click item + enter). Or maybe you should just add a Repeat button.
My approach to a user interface is to provide something
quick and consistant. "Click on the selected text in order to
add it to your document". That's quick, and consistant.
It looks like the answer is a hit test. I don't like this
because it returns the item's handle, and there are so many
items I haven't saved each handle. I can save the handle for
each item, but I was hoping MicroSoft would offer something
besides a screwing of the programmer as a solution. Who am I
kidding?
Sten, I do appreciate your advice.
Thanks
Larry
date: Mon, 04 Aug 2008 09:03:12 -0700
author: Larry Lindstrom
Re: TreeView - Second Hit on Same Selection.
On Mon, 04 Aug 2008 01:31:45 -0700, Larry Lindstrom
wrote:
>Hi Folks:
>
> Developing on XP Home, VS 2008 Pro, WIN32, no MFC.
>
> This application uses a TreeView control to select text that
>will be inserted into an edit box.
>
> The TVN_SELCHANGED notification is received each time the
>user selects a different piece of text from the TreeView.
>
> The problem occurs when the user wants to repeat the same
>piece of text. The second selection of the text isn't changing
>the selection, so there is no TVN_SELCHANGED notification.
You seem to have solved this problem already, but here's my code
(including a couple of helper functions):
inline long PFWDWordToX( LPARAM lP ) { return
static_cast<DWORD>(LOWORD( lP )); }
inline long PFWDWordToY( LPARAM lP ) { return
static_cast<DWORD>(HIWORD( lP )); };
//
--------------------------------------------------------------------
// PFWGetCursorPos
// GetCursorPos works for HPC Pro, but not Pocket PC !!!!
// See 20 Aug 2002 contributions from Ashish Grover to thread called
// "CTreeCtrl + CheckBox +HitTest" in
microsoft.public.pocketpc.developer
// From 11 Sep 2000 contribution from Steve Maillet to thread called
// "Is GetCursorPos() function not useable for WinCE?" in
// microsoft.public.windowsce.embedded.vc:
// "There is no cursor on the Pocket PC therefore you won't get
valid
// information on that platform."
// A 27 Jan 03 contribution from Alexander Shargin to thread called
// GetCursorPos in microsoft.public.windowsce.app.development
suggests
// using WM_LBUTTONDOWN
inline void PFWGetCursorPos( LPPOINT pPt )
{
DWORD dHere = ::GetMessagePos();
ASSERT( dHere != 0 );
pPt->x = PFWDWordToX( dHere );
pPt->y = PFWDWordToY( dHere );
} // PFWGetCursorPos
// ... excerpt from notification handler for my TreeView class
case NM_DBLCLK:
// Rector and Newcomer start label edit from here, but BZ had
trouble
// with that approach and found it unnecessary
case NM_CLICK:
// NM_RETURN is not relevant (tried 2 Dec 03)
{
TVHITTESTINFO hInfo;
PFWGetCursorPos( &hInfo.pt );
#if ISDEBUG
// 12 May 04 (4.0.0.67)
// See 16-20 Aug 2002 contributions from Ashish Grover to
thread called
// " CtreeCtrl + CheckBox + HitTest" in
microsoft.public.pocketpc.developer
// (in c:\temp\ppcd1.html)
DWORD dw = ::GetMessagePos();
POINT pw;
pw.x = LOWORD( dw );
pw.y = HIWORD( dw );
ASSERT( pw.x == hInfo.pt.x );
ASSERT( pw.y == hInfo.pt.y );
#endif
VERIFY( ::ScreenToClient( GetHwnd(), &hInfo.pt ) );
HTREEITEM hItem = TreeView_HitTest( GetHwnd(), &hInfo );
if (hItem != NULL)
{
// This triggers TVN_SELCHANGING
VERIFY( TreeView_SelectItem( GetHwnd(), hItem ) );
ASSERT( static_cast<PFTreeNode>(hItem) == m_pfNode );
}
}
break;
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
http://catb.org/~esr/faqs/smart-questions.html
date: Tue, 12 Aug 2008 13:03:17 -0400
author: unknown
|
|