Page 1 of 1

COMatePLUS: How can i disable context menu after right click

Posted: Thu Oct 08, 2009 10:06 am
by CNESM
Hello,

i have one question:

How can i cancel the context menu when the user click right on the spreadsheet?

In normal situation, the user will see the OWC menu of the spreadsheet, when he click right on the spreadsheet, but i will show my own menu. The Spreadsheet support the specificated event "BeforeContextMenu" to catch the context menu event right click on the spreadsheet. To disable the standard right click context menu we have to set the cancel parameter #True ("Cancel = #True), but how did i do this? I try it with the easy callback, see code below, but it doesn't seems to work.

Code: Select all


IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

Global ExcelObject.COMateObject 
Global ExcelObject1.COMateObject 

Procedure myEventCallback(object.COMateObject, eventName.s, parameterCount)
  If eventName.s="BeforeContextMenu"
    object\Invoke("Cancel = #True") 
    object\Setproperty("Cancel = #True") 
  EndIf
EndProcedure

If OpenWindow(0,#PB_Ignore,#PB_Ignore,800,800,"COMate: OWC11.Spreadsheet-Demo",#PB_Window_Invisible|#PB_Window_SystemMenu) 
    
  ExcelObject=COMate_CreateActiveXControl(0,0,800,400,"OWC11.Spreadsheet") 
  
  If ExcelObject 
  
    ExcelObject\SetProperty("Cells(1,1) = 'Özgür'") 
    ExcelObject\SetProperty("Cells(1,2) = 'Levent'") 
    ExcelObject\SetProperty("Cells(2,1) = 10") 
    ExcelObject\SetProperty("Cells(2,2) = 20") 
    
    ExcelObject\SetProperty("Cells(1, 1)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(1, 2)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(2, 1)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(2, 2)\Interior\Color = 18915966") 
    
    ExcelObject\SetProperty("Cells(1, 1)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(1, 2)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(2, 1)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(2, 2)\Font\Color = 255255255") 
    
    ExcelObject\GetObjectProperty("Sheets('3')\Delete") 
    ExcelObject\GetObjectProperty("Sheets('2')\Delete") 
  
    ExcelObject\SetProperty("Cells(1, 1)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(1, 2)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(2, 1)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(2, 2)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    
    
    ExcelObject\SetProperty("Cells(1, 1)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(1, 2)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(2, 1)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(2, 2)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(1, 1)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(1, 2)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(2, 1)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(2, 2)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("DisplayToolbar = #False") 
    ExcelObject\SetProperty("ScreenUpdating = #True") 
    ExcelObject\SetProperty("ViewOnlyMode = #True") ;Schreibschutz 
    ExcelObject\SetProperty("DisplayOfficeLogo = #False") 
    ExcelObject\SetProperty("DisplayTitleBar = #False") 
    ExcelObject\SetProperty("ActiveWindow\DisplayWorkbookTabs = #False") 
    
    HRESULT=ExcelObject\SetEventHandler(#COMate_CatchAllEvents,@myEventCallback())
  Else 
    
    Debug "!mySpreadsheet" 
      
  EndIf 
 
  HideWindow(0,0) 
  
  If ExcelObject 
    Repeat 
    Until WaitWindowEvent()=#PB_Event_CloseWindow 
    ExcelObject\Release() 
  EndIf 
  CloseWindow(0) 
EndIf 

Re: COMate: How can i disable context menu after right click?

Posted: Thu Oct 08, 2009 11:03 am
by srod
Well, investigation reveals that first two parameters sent to this event are the x and y coords respectively - which is fine.

However, the 3rd and 4th parameters are both iDispatch objects which seems to contradict some of the info I read on the web. You'll need to figure out what these objects are. I presume one of them allows you to customise the menu. What the other one does is anyone's guess at this stage? :)

Re: COMate: How can i disable context menu after right click?

Posted: Thu Oct 08, 2009 11:12 am
by srod
Got it.

Code: Select all

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

Global ExcelObject.COMateObject 
Global ExcelObject1.COMateObject 

Procedure myEventCallback(object.COMateObject, eventName.s, parameterCount)
  Protected canceliDisp.iDispatch, cancelObj.COMateObject
  If eventName.s="BeforeContextMenu"
    canceliDisp = object\GetObjectEventParam(4)
    If canceliDisp
      cancelObj = COMate_WrapCOMObject(canceliDisp)
      If cancelObj 
        cancelObj\SetProperty("Value=#True")
        cancelObj\Release()
      EndIf
      
      canceliDisp\Release()
    EndIf
  EndIf
EndProcedure

If OpenWindow(0,#PB_Ignore,#PB_Ignore,800,800,"COMate: OWC11.Spreadsheet-Demo",#PB_Window_Invisible|#PB_Window_SystemMenu) 
    
  ExcelObject=COMate_CreateActiveXControl(0,0,800,400,"OWC11.Spreadsheet") 
  
  If ExcelObject 
    ExcelObject\SetProperty("Cells(1,1) = 'Özgür'") 
    ExcelObject\SetProperty("Cells(1,2) = 'Levent'") 
    ExcelObject\SetProperty("Cells(2,1) = 10") 
    ExcelObject\SetProperty("Cells(2,2) = 20") 
    
    ExcelObject\SetProperty("Cells(1, 1)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(1, 2)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(2, 1)\Interior\Color = 18915966") 
    ExcelObject\SetProperty("Cells(2, 2)\Interior\Color = 18915966") 
    
    ExcelObject\SetProperty("Cells(1, 1)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(1, 2)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(2, 1)\Font\Color = 255255255") 
    ExcelObject\SetProperty("Cells(2, 2)\Font\Color = 255255255") 
    
    ExcelObject\GetObjectProperty("Sheets('3')\Delete") 
    ExcelObject\GetObjectProperty("Sheets('2')\Delete") 
  
    ExcelObject\SetProperty("Cells(1, 1)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(1, 2)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(2, 1)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    ExcelObject\SetProperty("Cells(2, 2)\HorizontalAlignment = -4152") ;-4152 = xlRight 
    
    
    ExcelObject\SetProperty("Cells(1, 1)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(1, 2)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(2, 1)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(2, 2)\Borders(7)\LineStyle = 1") ;7 = xlEdgeLeft ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(8)\LineStyle = 1") ;8 = xlEdgeTop ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(9)\LineStyle = 1") ;9 = xlEdgeBottom ; 1 = xlContinuous 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(10)\LineStyle = 1") ;10 = xlEdgeRight ; 1 = xlContinuous 
    
    ExcelObject\SetProperty("Cells(1, 1)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 1)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(1, 2)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(1, 2)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(2, 1)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 1)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("Cells(2, 2)\Borders(7)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(8)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(9)\Weight = 2") ;2 = xlThin 
    ExcelObject\SetProperty("Cells(2, 2)\Borders(10)\Weight = 2") ;2 = xlThin 
    
    ExcelObject\SetProperty("DisplayToolbar = #False") 
    ExcelObject\SetProperty("ScreenUpdating = #True") 
    ExcelObject\SetProperty("ViewOnlyMode = #True") ;Schreibschutz 
    ExcelObject\SetProperty("DisplayOfficeLogo = #False") 
    ExcelObject\SetProperty("DisplayTitleBar = #False") 
    ExcelObject\SetProperty("ActiveWindow\DisplayWorkbookTabs = #False") 

    HRESULT=ExcelObject\SetEventHandler(#COMate_CatchAllEvents,@myEventCallback())
  Else 
    
    Debug "!mySpreadsheet" 
      
  EndIf 

  HideWindow(0,0) 
  
  If ExcelObject 
    Repeat 
    Until WaitWindowEvent()=#PB_Event_CloseWindow 
    ExcelObject\Release() 
  EndIf 
  CloseWindow(0) 
EndIf 
You do realise that OWC is no longer supported by Microsoft? It no longer ships with MS Office for example.

Re: COMate: How can i disable context menu after right click?

Posted: Thu Oct 08, 2009 2:54 pm
by CNESM
When i see your solutions its so easy, but the time before i didnt come to it :-D Now is clear.
Thanks scrod for your quick help!
You do realise that OWC is no longer supported by Microsoft? It no longer ships with MS Office for example.
Yes, i heard it, but do you know if there a follow-up projekt to replace the owc?

Re: COMate: How can i disable context menu after right click?

Posted: Thu Oct 08, 2009 3:04 pm
by srod
My understanding is that the 'replacement', if it can be called that, is a server side implementation to give web pages access to Office components without embedding through ActiveX etc.

http://blogs.msdn.com/excel/archive/200 ... 68544.aspx