Hello everyone,

As you might know from my previous postings, I've been trying to wrap the
IRichEditOleCallback interface in my own class and substitute this for the
OleCallback which MS returns by default in CreateRichEditOleCallback.
Using the Refector tool, I found that MS implemented the GetContextMenu in
the following manner:
Public Function GetContextMenu(ByVal seltype As Short, ByVal lpoleobj As
IntPtr, ByVal lpchrg As CHARRANGE, <Out> ByRef hmenu As IntPtr) As Integer
      Dim num1 As Integer
      If (Me.owner.ContextMenu Is Nothing) Then
            hmenu = IntPtr.Zero
            goto Label_00C1
      End If
      Me.owner.ContextMenu.OnPopup(EventArgs.Empty)
      Dim ptr1 As IntPtr = Me.owner.ContextMenu.Handle
      Dim menu1 As Menu = Me.owner.ContextMenu
Label_0050:
      num1 = 0
      Dim num2 As Integer = menu1.itemCount
      Do While (num1 < num2)
            If (menu1.items(num1).handle <> IntPtr.Zero) Then
                  menu1 = menu1.items(num1)
                  Exit Do
            End If
            num1 += 1
      Loop
      If (num1 <> num2) Then
            goto Label_0050
      End If
      menu1.handle = IntPtr.Zero
      menu1.created = False
      If (Not menu1 Is Me.owner.ContextMenu) Then
            menu1 = CType(menu1, MenuItem).menu
            goto Label_0050
      End If
      hmenu = ptr1
Label_00C1:
      Return 0
End Function

Can someone explain why they do this - what's with the Do While loop?
Dim menu1 As Menu = Me.owner.ContextMenu
Label_0050:
      num1 = 0
      Dim num2 As Integer = menu1.itemCount
      Do While (num1 < num2)
            If (menu1.items(num1).handle <> IntPtr.Zero) Then
                  menu1 = menu1.items(num1)
                  Exit Do
            End If
            num1 += 1
      Loop
      If (num1 <> num2) Then
            goto Label_0050
      End If
      menu1.handle = IntPtr.Zero
      menu1.created = False

Why don't they simply do something like the following:
      If (Me.owner.ContextMenu Is Nothing) Then
            hmenu = IntPtr.Zero
            Else
            hmenu = Me.owner.ContextMenu.Handle
      End If
      Return 0

Regards and thanks in advance for your consideration,
John Whattam.

P.S. In my previous posting on GetNewStorage I erroneously referred to
another question on GetNewStorage, but in reality it was GetContextMenu -
as you may have guessed by now.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to