Right clicking on a CListCtrl item

I have a TreeCtl object in a dialog box. I created an OnNMRclick.. override 
function to capture a right clicks. The problem I can't figure out is how to 
find the tree item that the user has right clicked on. 

Here's what I tried:
void CRestoreFiles::OnNMRclickXYZ(NMHDR *pNMHDR, LRESULT *pResult)
	POINT CurPos;
	TVHITTESTINFO lpht;
	HTREEITEM RightClickItem;
	GetCursorPos(&CurPos);
	lpht.pt = CurPos;
	RightClickItem = TreeView_HitTest(pNMHDR->hwndFrom,&lpht);
                ...

I figured that GetCursorPos would give me the position of the cursor where I 
had right clicked. Then, I would use TreeView_HitTest() to give me the 
HTREEITEM that I had right clicked on.

Unfortunately, this doesn't work RightClickItem appears to give me random 
items in the tree.

Any help?

Thank-you, Howard


0
Howard5145 (82)
10/20/2004 10:29:05 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1322 Views

Similar Articles

[PageSpeed] 1

"Howard" <Howard@discussions.microsoft.com> wrote in message
news:5C76DF85-36E7-460A-85FC-A8F0E4DE9F0E@microsoft.com...
> I have a TreeCtl object in a dialog box. I created an OnNMRclick..
override
> function to capture a right clicks. The problem I can't figure out is how
to
> find the tree item that the user has right clicked on.
>
> Here's what I tried:
> void CRestoreFiles::OnNMRclickXYZ(NMHDR *pNMHDR, LRESULT *pResult)
> POINT CurPos;
> TVHITTESTINFO lpht;
> HTREEITEM RightClickItem;
> GetCursorPos(&CurPos);
> lpht.pt = CurPos;
> RightClickItem = TreeView_HitTest(pNMHDR->hwndFrom,&lpht);
>                 ...
>
> I figured that GetCursorPos would give me the position of the cursor where
I
> had right clicked. Then, I would use TreeView_HitTest() to give me the
> HTREEITEM that I had right clicked on.
>
> Unfortunately, this doesn't work RightClickItem appears to give me random
> items in the tree.
>
> Any help?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/structures/tvhittestinfo.asp

"...Client coordinates..."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/getcursorpos.asp

"...screen coordinates ..."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/cordspac_5oxg.asp

-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
10/20/2004 11:21:43 PM
>I have a TreeCtl object in a dialog box. I created an OnNMRclick.. override 
>function to capture a right clicks. The problem I can't figure out is how to 
>find the tree item that the user has right clicked on. 

Howard,

Here's an example:

void CMyTreeView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CTreeCtrl & tc = GetTreeCtrl();

	/* Get the cursor position for this message */
	DWORD dwPos = GetMessagePos();

	/* Convert the co-ords into a CPoint structure */
	CPoint pt( GET_X_LPARAM( dwPos ), GET_Y_LPARAM ( dwPos ) );
	CPoint spt;

	spt = pt;

	/* convert to screen co-ords for the hittesting to work */
	tc.ScreenToClient( &spt );

	UINT test;
	HTREEITEM hti = tc.HitTest( spt, &test );

	if ( hti != NULL  )
	{
		/* Is the click atcually *on* the item? */
		if ( test & TVHT_ONITEM )
		{
			/* Do the normal context menu stuff */
			OnContextMenu( this, pt );
		}
	}
	
	*pResult = 0;
}

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
10/20/2004 11:24:49 PM
This works beautifully! Thanks, Howard.

"David Lowndes" wrote:

> >I have a TreeCtl object in a dialog box. I created an OnNMRclick.. override 
> >function to capture a right clicks. The problem I can't figure out is how to 
> >find the tree item that the user has right clicked on. 
> 
> Howard,
> 
> Here's an example:
> 
> void CMyTreeView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
> {
> 	CTreeCtrl & tc = GetTreeCtrl();
> 
> 	/* Get the cursor position for this message */
> 	DWORD dwPos = GetMessagePos();
> 
> 	/* Convert the co-ords into a CPoint structure */
> 	CPoint pt( GET_X_LPARAM( dwPos ), GET_Y_LPARAM ( dwPos ) );
> 	CPoint spt;
> 
> 	spt = pt;
> 
> 	/* convert to screen co-ords for the hittesting to work */
> 	tc.ScreenToClient( &spt );
> 
> 	UINT test;
> 	HTREEITEM hti = tc.HitTest( spt, &test );
> 
> 	if ( hti != NULL  )
> 	{
> 		/* Is the click atcually *on* the item? */
> 		if ( test & TVHT_ONITEM )
> 		{
> 			/* Do the normal context menu stuff */
> 			OnContextMenu( this, pt );
> 		}
> 	}
> 	
> 	*pResult = 0;
> }
> 
> Dave
> -- 
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> 
0
Howard5145 (82)
10/21/2004 2:15:10 PM
Reply:

Similar Artilces:

Why are the two codes below not getting the right formula for my worksheet event change formula?
Why are the two codes below not getting the right formula for my worksheet event change formula? The remaining ones do work, but these two are not getting the right results. Target.Offset(0, 6).FormulaR1C1 = "=RC[-2]&RC[-5]" Target.Offset(0, 7).FormulaR1C1 = "=RC[-2]&RC[-5]" I'm trying to get both column G & H to show a combined value of data in other columns. Column G should show result by combining data from column E & B, while column H should show result by combining data from column F & C. Column G is showing: =RC[-2]&RC[-5] ...

shortcut mouse right side key
the shortcut key on the right side no longer works in Excel. This is after installing a software inventory control in developed in Excel and removed for free on the Internet. Could anyone help me to run down the right side to link the mouse when using Excel? -- cslgh No menu when you right-click on a cell? Perhaps code from the inventory control program you installed disabled it. Alt + F11 to open VBE. View>Immediate Window. Copy this into that window and hit ENTER key. Application.CommandBars("Cell").Enabled = True Alt + q to return to Excel.............

Giving rights to a user's mailbox
I have a number of users that I have created in my Windows2003 domain that are giving me greif. I have been unable to assign permissions to their mailboxes to give other users the full mailbox right. When I go through the motions of giving the correct rights and then I try to open the mailbox in Outlook by telling it to open an aditional mailbox under the advanced tab I get an error of: Unable to expand the folder. The operation failed. An object could not be found. Any ideas? Thanks Mike Aditional: This is Exchange 2003 and Outlook 2003. I have also tried creating a new profile with t...

How do I get the names of the sender in my sent box without click.
In Outlook Today, I added the column "to" in my sent boxes. The names of the senders however are not placed there, unless I click the message. Is it possible to fill in the names of the senders automatically?. ...

Hidden Items still show up in GAL
Hi, We just migrated from Exchange 2003 to 2007 and have started noticing this issue. When we chose the option in a user's mailbox to "Hide from Exchange Address Lists", it will still show up in the GAL. It doesn't matter whether this is done through the new Exchange Management Console or through AD Users and Computers. It appears selected in both instances. It isn't just the OAB causing a problem either because checking through webmail shows the mailboxes still in the online GAL. Any ideas? Is your RUS working as expected? "Peter Venkman" ...

How do I: enter a checkmark symbol in a cell by clicking on it
This is what I am trying to do.... 1. When someone clicks on cell, the checkmark symbol is entered into the cell 2. When someone clicks on the same cell again, they cell becomes blank (ie toggle between checkmark and blank) 3. Then how do I count the number of checkmarks in a column. Thanks, -- prsII ------------------------------------------------------------------------ prsII's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=32166 View this thread: http://www.excelforum.com/showthread.php?threadid=519157 How about a double-click?: Enter the following in ...

finding an item in a list control?
hi all, how to find an item in a list control, just like the find and replace dialog doing.(ie) i have a menu named "Edit" in that menu "Find" is a menu item. if i click "Find" a dialog box like the traditional find and replace should pop up and if i enter an item name the item name should be highlighted in the list control. how to do that? thanks and regards james Take a look at the following member functions. FindItem() SetItemState() -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "james" <...

Very Easy...Right?
How do I change an existing code from... mynum = Application.InputBox("Select Submission_ID") ....to mynum is located in cell A4 on sheet 1 (ie use the number already located in A4) with no InputBox I've tried.... mynum = Worksheets("Sheet1").Cells(R4,C1) mynum = Worksheets("Sheet1").Cells(4,1).Value mynum = Range("A4") I've even tried... Range("A4").Select mynum = ActiveCell I just don't know how to tell it to input the number already contained in A4 as the input for the already existing code. i'd use ...

Setting Item Tax and barcode type on items
I imported inventory from another POS, but I need to set the barcode type and item taxes after already importing? Reimporting is not an option. Thanks in advance. Phil If you can find out the values for the ItemTax ID and the barcode type you want to use, you could use the following SQL script substituting the values in the declared variables. DECLARE @BarcodeType int DECLARE @ItemTaxID int /*Change the variables below*/ SET @BarcodeType = 0 --The type of the barcode SET @ItemTaxID = 0 --The ID of the ItemTax /*Leave code below this line alone*/ UPDATE ITEM SET BarcodeFormat = @B...

how to edit the access right of C:\Windows\assembly\GAC_32\
I test website, ant get Compiler error: CS0016 Access is denied Compiler need read files from C:\Windows\assembly\GAC_32\ I could not see the folders under C:\Windows\assembly\GAC_32\ in explorer. and I can access these file from Command window so these files are there I try to set the security let NETWORK SERVICE and IIS_IUSER have read right but perperty window of assembly folder does not have security tab. help and suggestion needed. Thanks "MXC" <mxchen100@hotmail.com> wrote: >I test website, ant get Compiler error: CS0016 Access is denied > &g...

Administrative rights
I'm fairly new to Exchange 2003. I have it running on Server 2000. (I inherited this setup.) I'm trying to enable another user to create IDs and have the AD automatically create the Exchange mailbox at the same time. Whenever they create a user, they are NOT prompted to create the Echange info. That form never appears. I thought the solution was to delegate control to them at the Administrative group level. I set up a group and given it View and Full control. I have set up the user specifically with View and Full Control. Nothing seems to allow him to create mailboxes. ...

Where's the bug in ClistCtrl ?
I have written a small test dialog based application with CListCtrl, and found very unusual behaviour when I delete all columns and items and then re-populate the list, it doesn't show up anything! Example : BOOL CMyDlg::OnInitDialog() { .... // standard lines m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT ); return TRUE; } void CMyDlg::OnButton1() { // Filling the list with two columns CRect rect; LV_ITEM lvitem; m_list.GetWindowRect(&rect); m_list.InsertColumn(0, "Column1", LVCFMT_LEFT, rect.Width() * 1/3, 0); m_list.I...

RIGHT-Return 10th characters to right
I have an Excel spreadsheet with 25 or more digits in column A. I want to put the 10th digits to the last digit in column B. Is there a way to do this? Thanks in advance. =RIGHT(A1,10) Regards, Felipe >-----Original Message----- >I have an Excel spreadsheet with 25 or more digits in >column A. I want to put the 10th digits to the last digit >in column B. > >Is there a way to do this? > >Thanks in advance. >. > Jh, =RIGHT(H8,LEN(H8)-9) Dan E "jh" <anonymous@discussions.microsoft.com> wrote in message news:00cf01c398c6$e9f044d0$a5012...

Auto-empty Deleted Items folder on exit
I cannot seem to get the deleted items folder to auto empty when I close the Windows Mail program. I have the auto-empty option selected under the tools/options/maintenance tab; I have no trouble permanently deleting items in this folder manually (either one-by-one or in groups); I have tried all the diffrerent ways of exiting Windows Mail to no avail; I have tried disabling the email scanning feature of my Norton Internet Security program -- made no difference; and, this feature used to work just fine -- for some reason a couple of months ago it just stopped working. Any ideas...

Limit in exchange 2003 250 item at a time
I have outlook post form that reads items from a public folder that import the data to excel. I noticed that this outlook form works for only only to 250 items in WinXP but works fine in Windows 2000. Any idea how I can make it work in Win XP? I have tried setting my objects to nothing with no luck in my for loop.. Thank-you ...

Item Bin Transfer Entry report
Client is using the Item Bin Transfer Entry window (Transactions >> Inventory >> Bin Transfer Entry) and there is no existing report in Dynamics GP that will track what happened on the transfers. When you select Transfer, the record does not move to a history table and it does not stay in the IV10004 table. The quantities will get updated in the IV00112 (Item Site Bin Master) table. Since the data is not kept in any table there is no way to report this transaction after it has taken place. Client would like Dynamics GP to have a report that will track MultiBin transfers. T...

I want to delete a large attachment from a meeting item.
I have a meeting item in my calendar that has a large attachment. I want to delete the attachment and keep the meeting item. I can't edit the meeting item. Office 2007. Thanks. What happens when you select the attachment and hit Delete? Save & Close to keep the change or cancel the save if you change your mind of deleting the attachment. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net ...

Public folder right is missing!
Hi ou there, Permissions on Public folder tree is missing, users with right to modify or edit folder content are dinied access to the folder tree where they have permission. I used pfdavadmin to see and edit the permission but still the right are not retained. Help! ...

Execution time of several minutes
Hello group! A couple of weeks ago, Bob Phillips helped me with a function that rearranges and sorts my list of run times (for different courses when I've been out running). Now, I'm just wondering, is such a function supposed to take 3-4 minutes to execute (on a slow, 800MHz/384RAM (not the newer, faster type))? For each course that I've run (currently about 15 in the "course list"), the function runs through my list of runs (which consists of results from about 90 runs) so that the script can make a new listing of all runs, but this time grouped by course. Thereafter,...

Making the "add item" option available to VBA
I'd like to add VBA code to the Project PO Window that automatically checks the "add item" option from the toolbar when the window is opened. Anyone know how to get that menu option available to VBA? thanks! Martha That really isn't possible (directly) with VBA because VBA cannot see menus. About the only thing you can do is record a macro that checks this option. Then run the macro from VBA. that isn't directly available from vba either but there is a TK that tells you how to work around it. "Martha" <Martha@discussions.microsoft.com> wrote in messa...

OL2007, Word as editor, right mouse button not showing autocorrection
Normally when using Word and the cursor is over a misspelt word, the right mouse button shows alternative words and various other options. However, when creating a new email in OL, the Word editor uses the right button for Work | Signatures. Can I get it back to the normal Word modality? TIA, Bill "Bill Davy" <Bill@SynectixLtd.com> wrote in message news:OV4P7gdEKHA.1248@TK2MSFTNGP04.phx.gbl... > Normally when using Word and the cursor is over a misspelt word, the right > mouse button shows alternative words and various other options. > > However, whe...

Item Messages not Printing RMS 1.3
I have RMS 1.3, the instructions for Item Messages say that they are supposed to pop up on the POS and print on the Receipt. Ours Pop Up but do not print. The Help screen says it is only a Pop Up remeinder, so .... Is there a Option to select to get Item Messages to Print? or do I have to make a special receipt? -- RMS 1.3, MSDE 3 Lanes, 5 Back Office Clients XP sp2 Server 2003 sp1 Domain Static IP HI you have some misunderstading, the item message is basically develop to remind the cashier on POS transaction screen when certain items are purchased, this item message you can attached ...

Rights required to access Exchange 'Mailbox Rights' in ADUC #2
*I believe I'm posting as a a manged newsgroup user with alias, but so far I'm not getting a response. This is my third try to see if I can get it to work.* Is it possible to provide IT staff access to manipulate Mailbox Rights under the Exchange Advanced tab in ADUC without giving them Exchange Administrator rights? We'd like our staff to be able to manipulate all aspects of users using ADUC, but not the back-end Exchange stuff in System Manager. However it appears to be an all-or-nothing situation, at least where access to the mailbox rights are concerned. The message...

In right scroll bar can you change the page # in view box to sect.
The scroll bar on the right show in the view box the page number and then text from the document, can you change what the view box shows from page number to sections? Sueann wrote: > The scroll bar on the right show in the view box the page number and > then text from the document, can you change what the view box shows > from page number to sections? No, there is no option to control that display. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benef...

Linking service with inventory item
In Microsoft Money 2006 Small Business, is it possible to link an inventory item I might use in a particular service? This way I can keep track of the number of items available to me for that particular service. -- Christopher J. Fazio, V.M.D. Hope, New Jersey ...