Context menu extension

Y

yxq

Hi
I am build vb6 Context menu extension, but how to determine which popup
menu item(popupItem1 and popupItem2) was clicked?

Thanks

The code
'
' IContextMenu::QueryContextMenu
'
' In this function you must add your items
' to the context menu
'
Friend Function QueryContextMenu(ByVal hMenu As Long, ByVal indexMenu As
Long, ByVal idCmdFirst As Long, ByVal idCmdLast As Long, ByVal uFlags As
Long) As Long
Dim hSubMenu As Long, lIdx As Long

' Create a popup menu
hSubMenu = CreatePopupMenu()

' Get the file count
lIdx = UBound(m_SelectedFiles)

InsertMenu hSubMenu, lIdx, MF_BYPOSITION, idCmdFirst, "popupItem1"
InsertMenu hSubMenu, lIdx, MF_BYPOSITION, idCmdFirst, "popupItem2"


' Add the items to the context menu
InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_SEPARATOR, 0, ByVal 0&
InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_POPUP, hSubMenu, ByVal
"Item"
InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_SEPARATOR, 0, ByVal 0&

' Return how many non separator
' menu items we were added
QueryContextMenu = UBound(m_Items) + 1

End Function


'
' Carries out the command associated with
' a context menu item.
'
Private Sub IContextMenu_InvokeCommand(lpici As shlext.CMINVOKECOMMANDINFO)
Dim Idx As Long, Verb As String, Total As Currency

On Error Resume Next

' Check if lpVerb is an string pointer
' or the ID

If (lpici.lpVerb \ &H10000) <> 0 Then

' lpVerb is a string so
' copy it from the pointer
Verb = StrFromPtrA(lpici.lpVerb)

' Search the items array for
' the command and convert
' it to the item index
For Idx = 0 To UBound(m_Items)
If m_Items(Idx).Verb = Verb Then
Exit For
End If
Next

Else
Idx = lpici.lpVerb
End If

Dim fileNames As String
' Do the action asociated
' with the menu item
Select Case Idx

Case 0

MsgBox ("popupItem1 clicked")
Case 1
MsgBox ("popupItem2 clicked")
End Select

End Sub
 
Y

yxq

Thanks

But i have some bemused question for a long time, please help me. Thank
you very much!
When i insert an item, and when click the item in Explorer, it works
well.
But i want to add another item, i hope the two items can respond
different command and get the selected files, but the code will not work.

****************************************************************************
******************
Friend Function QueryContextMenu(ByVal hMenu As Long, ByVal indexMenu As
Long, ByVal idCmdFirst As Long, ByVal idCmdLast As Long, ByVal uFlags As
Long) As Long
Dim hSubMenu As Long, idCmd As Long

InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_SEPARATOR, 0, ByVal
0&
InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_POPUP, idCmdFirst,
ByVal
"Item1"
InsertMenu hMenu, indexMenu + 1, MF_BYPOSITION Or MF_POPUP,
idCmdFirst +
1, ByVal "Item2"
InsertMenu hMenu, indexMenu, MF_BYPOSITION Or MF_SEPARATOR, 0, ByVal
0&

QueryContextMenu = UBound(m_Items) + 1
End Function

Private Sub IContextMenu_InvokeCommand(lpici As
shlext.CMINVOKECOMMANDINFO)
Dim Idx As Long, Verb As String, Total As Currency

On Error Resume Next

If (lpici.lpVerb \ &H10000) <> 0 Then

Verb = StrFromPtrA(lpici.lpVerb)

For Idx = 0 To UBound(m_Items)
If m_Items(Idx).Verb = Verb Then
Exit For
End If
Next

Else
Idx = lpici.lpVerb
End If

Select Case Idx
Case 0
For Idx = 0 To UBound(m_SelectedFiles)
Total = Total + FileLen(m_SelectedFiles(Idx))
Next

MsgBox ("Item1 clicked! The files " & Total)

Case 1

MsgBox ("Item2 clicked!)
End Select


End Sub
 
A

Armin Zingler

yxq said:
Hi
I am build vb6 Context menu extension, but how to determine which
popup
menu item(popupItem1 and popupItem2) was clicked?

Do you want to make the same code work in VB.NET? If not, you probably know
that this a VB.NET, not a VB6 group. => microsoft.public.vb.*
 
H

Herfried K. Wagner [MVP]

* "yxq said:
I am build vb6 Context menu extension, but how to determine which popup
menu item(popupItem1 and popupItem2) was clicked?

Post this question to one of the VB6 groups (microsoft.public.vb.*).

MsgBox ("popupItem1 clicked")
Case 1
MsgBox ("popupItem2 clicked")

Add a 'Call' in font of the 'MsgBox' or remove the "(", ")".
 
A

Armin Zingler

yxq said:
But i have some bemused question for a long time, please help me.
Thank
you very much!


Don't you have access to the microsoft.public.vb.* groups?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top