Description: | Adds a custom context menu to any OfficeTalk data type. |
Syntax: | object.AddContextMenuItem(sDataType, sMenuText, sAppOrProgID [, sMethod] [,bThreaded]) |
Parameters: | |
object | Required, the Session object |
sDataType | The name of the data type, e.g. 'Contacts', 'Companies', 'UserTasks'. |
sMenuText | The text of the context menu item |
sAppOrProgID | The fully qualified path of the application to be run when the menu item is selected or the ProgID of the object whose method will be called. If the sMethod parameter of this function is not supplied then this parameter contains the fully qualified path of an application to be launched when the menu item is selected. If the sMethod parameter of this function is supplied then this parameter contains the progID of the object whose method will be invoked. An example of a progID is 'Word.Document' or 'OfficeTalk.Application' |
sMethod | The method to invoke in the object created or referenced by sAppOrProgID. The meaning of the sAppOrProgID parameter changes depending upon whether or not this optional parameter is supplied. |
bThreaded | By default, if you are specifying a ProgID rather than an application, when you select this command from a context menu item, control will not be returned back to OfficeTalk until the invoked method has completed. You can force OfficeTalk to return control immediately by passing in this optional parameter as True. |
Remarks: | By calling this function, you can install a custom menu item into a specific context menu. The menu item will be installed into the context menu of the data type specified by sDataType. The text of the menu item will be set to sText. Clicking on an item of the relevant data type using the right mouse button will show a context menu containing the menu item. Selecting the menu item from the context menu will do one of two things. If sMethod is not supplied, then selecting the menu item will start the application pointed to by sAppOrProgID. The following parameters will be passed to this application in the order listed. |
sItemID (String). This is the ID of the associated OfficeTalk object.
sWorkgroupName (String inside quote characters). This is the name of the OfficeTalk workgroup.
sCurrentUserID (String). This is the ID of the current OfficeTalk user.
The following is a list of valid data type strings which may be passed as the first parameter to this function:
UserTasks | Conversations | Projects | Meetings |
UserAppointments | Documents | ProjectTasks | MeetingMembers |
Contacts | ReceivedMail | Planners | Groups |
Companies | SentMail | PlannerKeys | Users |
Resources | Folders | ContactGroups | PlannerFolders |
ProjectFolders | MeetingFolders |
Returns: Nothing
Example:
Dim session As Object
Set session = CreateObject("OfficeTalk.Session")
Call session.AddContextMenuItem("Contacts", "Invoice Customer", "g:\apps\invoice.exe")
or
Dim session As Object
Set session = CreateObject("OfficeTalk.Session")
Call session.AddContextMenuItem("Contacts", "Invoice Customer", "myprog.application", "InvCustPressed")
Further Information:
In the case where sMethod is not supplied, parameters are passed to the application specified by sAppOrProgID. If the application is a Visual Basic application and you wish to get the parameters passed to the application by OfficeTalk, then you will need to parse the command line in order to retrieve the parameters. You can do this using a function similar to that shown below:
/////////////////////////////////////////////
// Parses the command line and returns the
// arguments in an array.
//
Function GetCommandLine(Optional MaxArgs)
Dim C, CmdLine, CmdLnLen, InArg, I,NumArgs
If IsMissing(MaxArgs) Then MaxArgs = 10
ReDim ArgArray(MaxArgs)
NumArgs = 0: InArg = False
CmdLine = Command()
CmdLnLen = Len(CmdLine)
For I = 1 To CmdLnLen
C = Mid(CmdLine, I, 1)
If (C <> " " And C <> vbTab) Then
If Not InArg Then
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
ArgArray(NumArgs) = ArgArray(NumArgs)& C
Else
InArg = False
End If
Next I
ReDim Preserve ArgArray(NumArgs)
GetCommandLine = ArgArray()
End Function
This function returns an array of arguments. You would use the function in the following way:
cml = GetCommandLine(6) 'We expect 6 arguments
sDataType = StripQuotes(cml(1))
sItemID = StripQuotes(cml(2))
sWorkgroupName = StripQuotes(cml(3))
sCurrentUserID = StripQuotes(cml(4))
sLoginName = StripQuotes(cml(5))
sPassword = StripQuotes(cml(6))
Remember that some of the arguments will be inside quotes and so you may need to check for these and remove them accordingly. A function to do this is shown below:
Private Function StripQuotes(sString As String)
iFirst = InStr(1, sString, """", vbTextCompare)
If (iFirst > 0) Then
iLast = InStr(iFirst + 1, sString, """")
If (iLast > 0) Then
sResult = Mid(sString, iFirst + 1)
sResult = Left(sResult, Len(sResult) - 1)
sString = sResult
End If
End If
StripQuotes = sString
End Function