CListCtl Question
Gerry Sweeney -- gerry@hornbill.com
Tuesday, March 11, 1997
Environment: NT3.51 SP3, MSVC20, MFC
Dear Listers,
I have implemented a CListCtrl inside a view. I seem to be unable to get a
notification from the list box when I double-click on an item in the list.
What I need is
a) the double-click notification
b) the item that was double-clicked
Any help would be appreciated
Kind Regards
Gerry Sweeney
gerry@hornbill.com
Jason Healy -- jason@hkjcs.oz.au
Tuesday, March 18, 1997
Use class wizard to add the notification
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
and implement your function as follows:
void CMyListView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
// Need to find the co-ordinates of the message
const MSG * pmsg = GetCurrentMessage();
CPoint pt = pmsg->pt;
m_list.ScreenToClient(&pt);
pt.x = 0; // HitTest only works in first column - so lets pretend
thats where it is
CListCtrl& list = GetListCtrl();
UINT nFlags;
int nItem = list.HitTest(pt, &nFlags);
if (nItem != -1 && nFlags & LVHT_ONITEM) {
// Do want you want nItem is the 0 based index
}
*pResult = 0;
}
Jason
jason@hkjcs.oz.au
----------
> [Mini-digest: 7 responses]
>
> >I have implemented a CListCtrl inside a view. I seem to be unable to get
a
> >notification from the list box when I double-click on an item in the
list.
> >What I need is
> >
> >a) the double-click notification
> >b) the item that was double-clicked
>
> A view is a window derived object and you can handle window messages as
you
> seem fit.
> In your case, you can simply set a handler for ON_WM_LBUTTONDBLCLK() in
your
> msg map.
>
> In your handler implementation, you'll receive a CPoint as the second
> argument,
>
> yourview::Onxxx(UINT, CPoint point)
>
> To see if the control was hit, you can use
>
> LV_HITTEST lvh;
> lvh.pt = point;
> if(yourlistctl.HitTest(&lvh) != -1){
> // then your item is "lvh.iItem"
> }
>
> Mario
> mcontest@universal.com
>
> -----From: "Arkady Elterman"
>
> In order to achieve this, I had to capture WM_LBUTTONDBLCLK message in the
> list control's parent's PreTranslateMessage() function (making sure that
> the list control had focus at that time) and then use the control's
> HitTest() method to determine which item was clicked.
>
> Although it worked fine, I'm still curious, too, if there is a better
way.
> I was surprised not to find LVN_DBLCLK (similar to LBN_DBLCLK) among list
> control's notifications.
>
> ---
> Arkady Elterman
> arkady@neca.com
> http://www.neca.com/~arkady/spin.htm
>
> ----------
> : From: Gerry Sweeney
> : To: mfc-l
> : Subject: CListCtl Question
> : Date: Tuesday, March 11, 1997 5:52 AM
> :
> :
> : Environment: NT3.51 SP3, MSVC20, MFC
> :
> : Dear Listers,
> :
> : I have implemented a CListCtrl inside a view. I seem to be unable to get
> a
> : notification from the list box when I double-click on an item in the
> list.
> : What I need is
> :
> : a) the double-click notification
> : b) the item that was double-clicked
> :
> : Any help would be appreciated
> :
> :
> : Kind Regards
> :
> : Gerry Sweeney
> : gerry@hornbill.com
> :
> :
> :
> :
> :
> :
> -----From: "Anthony V. Paul"
>
> Gerry Sweeney wrote:
> >
> > Environment: NT3.51 SP3, MSVC20, MFC
> >
> > Dear Listers,
> >
> > I have implemented a CListCtrl inside a view. I seem to be unable to
get a
> > notification from the list box when I double-click on an item in the
list.
> > What I need is
> >
> > a) the double-click notification
> > b) the item that was double-clicked
> >
> > Any help would be appreciated
> >
> > Kind Regards
> >
> > Gerry Sweeney
> > gerry@hornbill.com
>
>
> If you generate your view from clistctrl (i.e. CMyView : CListView) you
> will be able to easily get the messages thru Class Wizzard.
>
> If it is to late to do this, the following code may help:
>
> I had a CListCtrl inside a CDialogBar, this code worked. Later I
> changed to a CTreeCtrl, and made my view class derived from CTreeView.
>
> Hope this helps
>
> avp
>
> BOOL CAlbum::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
> {
> LPNMHDR phdr = (LPNMHDR)lParam;
>
> switch( phdr->code )
> {
> case NM_DBLCLK:
> {
> POINT pt;
>
> GetCursorPos( &pt );
>
> ::ScreenToClient( phdr->hwndFrom, &pt );
>
> int nRet;
>
> if( ( nRet = ((CListCtrl*)GetDlgItem( IDC_ALBUM
> ))->HitTest( pt ) )
> != -1 )
> {
> // nRet is the index of the item we hit.
>
> CString strAlbum =
> ((CListCtrl*)GetDlgItem( IDC_ALBUM
> ))->GetItemText( nRet, 0 );
>
> if( ((CMainFrame*)AfxGetMainWnd())->bOpenAlbum(
> strAlbum ) )
> {
> // Set the icon to the open book
> LV_ITEM lv;
>
> lv.mask = LVIF_IMAGE;
> lv.iItem = nRet;
> lv.iSubItem = 0;
> lv.iImage = 1;
>
> ((CListCtrl*)GetDlgItem( IDC_ALBUM
> ))->SetItem( &lv );
> }
> }
> }
>
> break;
>
> case LVN_BEGINLABELEDIT:
> {
> LV_DISPINFO FAR* pdi = (LV_DISPINFO FAR*)lParam;
>
> LV_ITEM lv;
>
> lv.mask = LVIF_IMAGE;
> lv.iItem = pdi->item.iItem;
> lv.iSubItem = 0;
>
> // Only allow editing if the album is not open.
> if( ((CListCtrl*)GetDlgItem( IDC_ALBUM ))->GetItem( &lv
> ) )
> {
> // Is the icon not the open one?
> if( lv.iImage != 1 )
> {
> // Allow editing
> SetWindowLong( m_hWnd, DWL_MSGRESULT,
> TRUE );
> return TRUE;
> }
> else
> {
> // DO NOT allow
> MessageBox( _T("Please close the album
> before editing its name."),
> _T("Notice:") );
> SetWindowLong( m_hWnd, DWL_MSGRESULT,
> FALSE );
> return TRUE;
> }
> }
>
>
> }
> break;
>
> case LVN_ENDLABELEDIT:
> {
> LV_DISPINFO FAR* pdi = (LV_DISPINFO FAR*)lParam;
>
> // If the text is valid, there wasn't a cancel.
> if( pdi->item.pszText )
> {
> CString strCurrentLabel =
> ((CListCtrl*)GetDlgItem( wParam
> ))->GetItemText( pdi->item.iItem, 0 );
> long
> Id;
> BOOL
> Ret = FALSE;
>
> if(
> ((CMainFrame*)AfxGetMainWnd())->bDoesFolderExist(
> strCurrentLabel, lId ) )
> bRet =
> ((CMainFrame*)AfxGetMainWnd())->bEditAlbumLabel(
> pdi->item.pszText, strCurrentLabel );
> else
> // OK, lets try and create the album
> bRet =
> ((CMainFrame*)AfxGetMainWnd())->nCreateAlbum(
> pdi->item.pszText );
>
> // Change the item's label.
> if( bRet )
> ((CListCtrl*)GetDlgItem( wParam
> ))->SetItemText( pdi->item.iItem,
> 0, pdi->item.pszText );
> }
> }
> break;
>
> default:
> phdr = NULL;
> break;
> }
>
>
> return CDialogBar::OnNotify(wParam, lParam, pResult);
> }
> -----From: "Alcocer,Wagner"
>
> Add the LBS_NOTIFY style to the CListCtrl
>
> >----------
> >From: Gerry Sweeney[SMTP:gerry@hornbill.com]
> >Sent: Tuesday, March 11, 1997 5:52 AM
> >To: mfc-l
> >Subject: CListCtl Question
> >
> >
> >Environment: NT3.51 SP3, MSVC20, MFC
> >
> >Dear Listers,
> >
> >I have implemented a CListCtrl inside a view. I seem to be unable to get
a
> >notification from the list box when I double-click on an item in the
list.
> >What I need is
> >
> >a) the double-click notification
> >b) the item that was double-clicked
> >
> >Any help would be appreciated
> >
> >
> >Kind Regards
> >
> >Gerry Sweeney
> >gerry@hornbill.com
> >
> >
> >
> >
> >
> >
> >
> -----From: Oksana Lien
>
> It's a two step process:
>
> 1) Use notification message NM_DBLCLK in the view that contains the list
> control to catch the doubleclick;
> 2) While processing the double-click notification, use GetCurrentMessage()
> and HitTest() to get the index of the item that was double-clicked.
>
> Here's what the code would look like:
>
> BEGIN_MESSAGE_MAP(CYourView, CView)
> ...
> //}}AFX_MSG_MAP
> ON_NOTIFY(NM_DBLCLK, yourListId, OnYourListDblclk)
>
> END_MESSAGE_MAP()
>
> afx_msg void CYourView::OnYourListDblclk(NMHDR* pNMHDR, LRESULT* pResult)
> {
> const MSG* msg = GetCurrentMessage();
> int index;
> POINT pt = msg->pt;
>
> ScreenToClient(&pt);
> if ((index = m_YourListCtrl.HitTest(pt, NULL)) > -1)
> {
> // Do whatevere you need to do with the selected item
> }
> }
>
>
> At 10:52 AM 3/11/97 G, you wrote:
> >
> >Environment: NT3.51 SP3, MSVC20, MFC
> >
> >Dear Listers,
> >
> >I have implemented a CListCtrl inside a view. I seem to be unable to get
a
> >notification from the list box when I double-click on an item in the
list.
> >What I need is
> >
> >a) the double-click notification
> >b) the item that was double-clicked
> >
> >Any help would be appreciated
> >
> >
> >Kind Regards
> >
> >Gerry Sweeney
> >gerry@hornbill.com
> >
> >
> >
> >
> >
> >
> >
> >
> _________________________
> Oksana Lien
> Dimension Softek, Inc.
> lien@ares.csd.net
>
> -----From: ravi.swaminthan@midata.com (ravi swaminthan)
>
>
> Hi,
>
> If u see the documentation for the CListCtrl notification message there
> is no Double Click notification Actually u can directly process the
> LButtonDouble Click message of the CListCtrl. One of the parameters of
> this message handler function is the point where the mouse is
> clicked.From this point, the item on which the click was done can be
> found using the CListCtrl function CListCtrl::HitTest which returns the
> index to the clicked item.
>
> Hope this answers your question.
>
> I would like to know if your company's name is Hornbill Systems, based at
> Ruislip. London.
>
>
> You can reach me at
> Ravi.Swaminthan@midata.com
> (414)355 7637.
> 4363 W Dean Road, #258,
> Browndeer,Milwaukee
> Wisconsin, USA.
>
> ----------
> From: owner-mfc-l[SMTP:owner-mfc-l@majordomo.netcom.com]
> Sent: Tuesday, March 11, 1997 10:52 AM
> To: mfc-l
> Subject: CListCtl Question
>
>
> Environment: NT3.51 SP3, MSVC20, MFC
>
> Dear Listers,
>
> I have implemented a CListCtrl inside a view. I seem to be unable to get
> a
> notification from the list box when I double-click on an item in the
> list.
> What I need is
>
> a) the double-click notification
> b) the item that was double-clicked
>
> Any help would be appreciated
>
>
> Kind Regards
>
> Gerry Sweeney
> gerry@hornbill.com
>
>
>
>
>
>
>
> -----From: Amir Shoval
>
> Hi,
>
> You can solve problem a) by handling WM_LBUTTONDBLCLK. In your
> handler, you can solve problem b) by calling your listCtrl.HitTest,
> passing the
> point you got in the handler. That's it.
>
> Amir
>
> >----------
> >From: Gerry Sweeney[SMTP:gerry@hornbill.com]
> >Sent: =E9=E5=ED =F9=EC=E9=F9=E9 11 =EE=F8=F5 1997 12:52
> >To: mfc-l
> >Subject: CListCtl Question
> >
> >
> >Environment: NT3.51 SP3, MSVC20, MFC
> >
> >Dear Listers,
> >
> >I have implemented a CListCtrl inside a view. I seem to be unable to =
> get a
> >notification from the list box when I double-click on an item in the =
> list.
> >What I need is
> >
> >a) the double-click notification
> >b) the item that was double-clicked
> >
> >Any help would be appreciated
> >
> >
> >Kind Regards
> >
> >Gerry Sweeney
> >gerry@hornbill.com
> >
> >
> >
> >
> >
> >
> >
Become an MFC-L member
| Вернуться в корень Архива
|