Toon posts:

[VB.NET + Office 2003] Context menu button

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb een add-in geschreven in VB.NET (outlook add-in template in VS2005). Deze plugin voegt items (als email, contacten, tasks etc.) toe aan mijn CRM systeem.

Om een item toe te voegen moet er nu op een button in een menu geclicked worden. Ik wil gebruikers echter de mogelijkheid geven om gebruik te maken van het "rechtermuisklik contextmenu". Dus moet ik daar minstens één button toevoegen.

Helaas schrijf ik normaal nooit voor office... buiten deze plug-in dan. Het menu toevoegen aan outlook was gemakkelijk (staat een goed gedocumenteerd voorbeeld op MSDN). Maar voor het toevoegen van een button aan het context menu heb ik te weinig kaas gegeten van office om het volledig zelf te schrijven. Daarom heb ik een voorbeeld nodig en dat heb ik hier gevonden.

Probleem is dat dit een VBA voorbeeld is, en ik gebruik (en wil dat ook niet) geen VBA. Nu kan ik met een paar imports wel alle gebruikte classes in het script gebruiken... Alleen werkt het niet.

Ik denk dat dit komt omdat "Private Sub ActiveExplorerCBars_OnUpdate()" in mijn plugin applicatie geen speciaal event is, is er een manier om dit te omzeilen? En ik heb geen ThisOutlookSession. Of heeft iemand een beter voorbeeld voor mij?

  • DoDo
  • Registratie: Juli 2001
  • Laatst online: 21:41
Ik heb even de reaties doorgespit op die site, en daar ook een voorbeeld voor vb.net gevonden:

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Friend Function ButtonCreate(ByVal oCommandBar As CommandBar, ByVal sNewButtonTag As String) As CommandBarButton
        Dim oNewButton As CommandBarButton
        Dim oRM As New Resources.ResourceManager("ReportSpam.ReportSpamButtonIcons", System.Reflection.Assembly.GetExecutingAssembly())
        Dim oImage As System.Drawing.Image
        Dim ipdButtonPicture As stdole.IPictureDisp
        Dim ipdButtonMask As stdole.IPictureDisp
        Dim ax As New ActiveXHost

        Try

            'Get the bitmap for the button picture and mask from the resource file and convert it to an IPictureDisp.
            oImage = CType(oRM.GetObject("PostiniReportSpamButtonBmp"), System.Drawing.Image)
            ipdButtonPicture = ax.IPictureDisp(oImage) 'Convert from image to stdole.IPictureDisp
            oImage = CType(oRM.GetObject("PostiniReportSpamButtonMaskBmp"), System.Drawing.Image)
            ipdButtonMask = ax.IPictureDisp(oImage) 'Convert from image to stdole.IPictureDisp

            'Create the button on the command bar. 
            oNewButton = CType(oCommandBar.Controls.Add(Type:=MsoControlType.msoControlButton, Temporary:=True), CommandBarButton)

            'Configure the button
            With oNewButton
                .Tag = sNewButtonTag
                .DescriptionText = "test"
                .BeginGroup = True
                .Caption = "&Test Button"
                .FaceId = 0
                .Picture = ipdButtonPicture
                .Mask = ipdButtonMask 'White=transparent Black=image
                .Style = MsoButtonStyle.msoButtonIconAndCaption
            End With

            Return oNewButton

        Catch ex As Exception
            DebugWriter("ButtonCreate Exception: ", ex.Message)
        End Try

    End Function

Friend Class ActiveXHost
    'See 824017 for a description of this class.
    Inherits System.Windows.Forms.AxHost

    Public Sub New()
        MyBase.New("59EE46BA-677D-4d20-BF10-8D8067CB8B33")

    End Sub

    Public Shared Function IPictureDisp(ByVal Image As System.Drawing.Image) As stdole.IPictureDisp
        IPictureDisp = CType(System.Windows.Forms.AxHost.GetIPictureDispFromPicture(Image), stdole.IPictureDisp)

    End Function

End Class

Verwijderd

Topicstarter
Heb je mischien een URL naar de post? Want ik heb toch wat comments bij nodig om het aan de gang te krijgen zo te zien.

Verwijderd

Topicstarter
Dodo? Iemand, ben er nog steeds niet uit...

  • BertS
  • Registratie: September 2004
  • Laatst online: 08:33
Probeer eens wat concreter te zijn, waar loop je tegen aan? Wat lukt er niet? niet alleen 'ik heb toch wat comments nodig'...

Verwijderd

Topicstarter
Heb dit script niet aan het werken gekregen, onderstaand werkt wel:

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    ' Variablen voor de context menu button
    Private _Explorer As Outlook.ExplorerClass = Nothing
    Private _CommandBars As Office.CommandBars = Nothing
    Private _Missing As Object = System.Reflection.Missing.Value
    Private _ContextMenuButtonStart As Office.CommandBarButton = Nothing
    Private _ContextMenuButton As Office.CommandBarButton = Nothing

    ' Buttons toevoegen aan het context menu
    Sub _CommandBars_OnUpdate()
        For Each bar As Office.CommandBar In _CommandBars
            If bar.Name = "Context Menu" Then
                Dim oldProtection As Office.MsoBarProtection = bar.Protection
                bar.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoProtection

                ' Overeenkomstige properties van de buttons
                _ContextMenuButtonStart = CType(bar.Controls.Add(Office.MsoControlType.msoControlButton, 1, _Missing, _Missing, True), Office.CommandBarButton)
                _ContextMenuButtonStart.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
                _ContextMenuButton = CType(bar.Controls.Add(Office.MsoControlType.msoControlButton, 1, _Missing, _Missing, True), Office.CommandBarButton)
                _ContextMenuButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
                _ContextMenuButton.Visible = True
                _ContextMenuButtonStart.Visible = True
                _ContextMenuButtonStart.BeginGroup = True
                _ContextMenuButton.BeginGroup = True

                If boolAppActief = True Then
                    _ContextMenuButtonStart.TooltipText = ""
                    _ContextMenuButtonStart.Caption = ""
                    _ContextMenuButtonStart.Enabled = True
                    AddHandler _ContextMenuButtonStart.Click, AddressOf _ContextMenuButtonStart_Click

                    ' Item toevoegen aan CRM button
                    _ContextMenuButton.TooltipText = ""
                    _ContextMenuButton.Caption = ""
                    _ContextMenuButton.Enabled = True
                    AddHandler _ContextMenuButton.Click, AddressOf _ContextMenuButton_Click
                Else
                    ' CRM aan/uit button
                    _ContextMenuButtonStart.TooltipText = ""
                    _ContextMenuButtonStart.Caption = ""
                    _ContextMenuButtonStart.Enabled = True
                    AddHandler _ContextMenuButtonStart.Click, AddressOf _ContextMenuButtonStart_Click

                    ' Item toevoegen aan CRM button
                    _ContextMenuButton.TooltipText = ""
                    _ContextMenuButton.Caption = ""
                    _ContextMenuButton.Enabled = False
                    AddHandler _ContextMenuButton.Click, AddressOf _ContextMenuButton_Click
                End If

                bar.Protection = oldProtection
            End If
        Next
    End Sub

    Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        _Explorer = CType(Me.ActiveExplorer, Outlook.ExplorerClass)
        _CommandBars = _Explorer.CommandBars
        AddHandler _CommandBars.OnUpdate, AddressOf _CommandBars_OnUpdate
    End Sub


Waar je dat stukje met die if boolActief eruit kunt laten natuurlijk! Te lui om het eruit te knippen voor het voorbeeld :P Als je helemaal netjes bent kun je per button with gebruiken om hem in te stellen etc.
Pagina: 1