excontextmenu - sample code |
How can I display a context menu? VBA (MS Access, Excell...) Set contextMenu = CreateObject("Exontrol.ContextMenu") With contextMenu .Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" & _ "b Sub Item B,Sub Sub Item C))" iSelect = .Select() Debug.Print( .Items.item(iSelect).Caption ) End With VB6 Set contextMenu = CreateObject("Exontrol.ContextMenu") With contextMenu .Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" & _ "b Sub Item B,Sub Sub Item C))" iSelect = .Select() Debug.Print( .Items.item(iSelect).Caption ) End With VB.NET Dim contextMenu,iSelect ' Add 'exontrol.excontextmenu.dll' reference to your project. contextMenu = New exontrol.EXCONTEXTMENULib.excontextmenu() With contextMenu .Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" & _ "b Sub Item B,Sub Sub Item C))" iSelect = .Select() Debug.Print( .Items.get_item(iSelect).Caption ) End With VB.NET for /COM Dim contextMenu,iSelect contextMenu = CreateObject("Exontrol.ContextMenu") With contextMenu .Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" & _ "b Sub Item B,Sub Sub Item C))" iSelect = .Select() Debug.Print( .Items.item(iSelect).Caption ) End With C++ /* Includes the definition for CreateObject function like follows: #include <comdef.h> IUnknownPtr CreateObject( BSTR Object ) { IUnknownPtr spResult; spResult.CreateInstance( Object ); return spResult; }; */ /* Copy and paste the following directives to your header file as it defines the namespace 'EXCONTEXTMENULib' for the library: 'ExContextMenu 1.0 Type Library' #import <ExContextMenu.dll> using namespace EXCONTEXTMENULib; */ EXCONTEXTMENULib::IExContextMenuPtr contextMenu = ::CreateObject(L"Exontrol.ContextMenu"); contextMenu->GetItems()->PutToString(_bstr_t("Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su") + "b Sub Item B,Sub Sub Item C))"); long iSelect = contextMenu->Select(vtMissing,vtMissing,vtMissing); OutputDebugStringW( contextMenu->GetItems()->Getitem(iSelect)->GetCaption() ); C++ Builder /* Select the Component\Import Component...\Import a Type Library, to import the following Type Library: ExContextMenu 1.0 Type Library TypeLib: C:\Windows\system32\ExContextMenu.dll to define the namespace: Excontextmenulib_tlb */ //#include "EXCONTEXTMENULIB_TLB.h" Excontextmenulib_tlb::IExContextMenuPtr contextMenu = Variant::CreateObject(L"Exontrol.ContextMenu"); contextMenu->Items->ToString = TVariant(String("Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su") + "b Sub Item B,Sub Sub Item C))"); long iSelect = contextMenu->Select(TNoParam(),TNoParam(),TNoParam()); OutputDebugString( contextMenu->Items->get_item(TVariant(iSelect))->Caption ); C# // Add 'exontrol.excontextmenu.dll' reference to your project. // Add 'ExContextMenu 1.0 Type Library' reference to your project. exontrol.EXCONTEXTMENULib.excontextmenu contextMenu = new exontrol.EXCONTEXTMENULib.excontextmenu(); contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" + "b Sub Item B,Sub Sub Item C))"; int iSelect = contextMenu.Select(null,null,null); System.Diagnostics.Debug.Print( contextMenu.Items[iSelect].Caption ); JavaScript <SCRIPT LANGUAGE="JScript"> var contextMenu = new ActiveXObject("Exontrol.ContextMenu"); contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" + "b Sub Item B,Sub Sub Item C))"; var iSelect = contextMenu.Select(null,null,null); alert( contextMenu.Items.item(iSelect).Caption ); </SCRIPT> C# for /COM // Add 'ExContextMenu 1.0 Type Library' reference to your project. EXCONTEXTMENULib.ExContextMenu contextMenu = new EXCONTEXTMENULib.ExContextMenu(); contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Su" + "b Sub Item B,Sub Sub Item C))"; int iSelect = contextMenu.Select(null,null,null); System.Diagnostics.Debug.Print( contextMenu.Items[iSelect].Caption ); X++ (Dynamics Ax 2009) public void init() { COM com_Items; anytype contextMenu,var_Items; int iSelect; str var_s; ; super(); // Add 'excontextmenu.dll' reference to your project. // Add 'ExContextMenu 1.0 Type Library' reference to your project. contextMenu = COM::createFromObject(new EXCONTEXTMENULib.excontextmenu()); contextMenu = contextMenu; var_Items = COM::createFromObject(contextMenu.Items()); com_Items = var_Items; var_s = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub"; var_s = var_s + " Sub Item B,Sub Sub Item C))"; com_Items.ToString(var_s); iSelect = contextMenu.Select(); print( contextMenu.Items().item(iSelect).Caption() ); } Delphi 8 (.NET only) contextMenu := (ComObj.CreateComObject(ComObj.ProgIDToClassID('Exontrol.ContextMenu')) as EXCONTEXTMENULib.ExContextMenu); with contextMenu do begin Items.ToString := 'Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub' + ' Sub Item B,Sub Sub Item C))'; iSelect := Select(Nil,Nil,Nil); OutputDebugString( Items.item[TObject(iSelect)].Caption ); end; Delphi (standard) contextMenu := (IUnknown(ComObj.CreateComObject(ComObj.ProgIDToClassID('Exontrol.ContextMenu'))) as EXCONTEXTMENULib_TLB.ExContextMenu); with contextMenu do begin Items.ToString := 'Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub' + ' Sub Item B,Sub Sub Item C))'; iSelect := Select(Null,Null,Null); OutputDebugString( Items.item[OleVariant(iSelect)].Caption ); end; VFP contextMenu = CreateObject("Exontrol.ContextMenu") with contextMenu var_s = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub" var_s = var_s + " Sub Item B,Sub Sub Item C))" .Items.ToString = var_s iSelect = .Select() DEBUGOUT( .Items.item(iSelect).Caption ) endwith dBASE Plus local contextMenu,iSelect contextMenu = new OleAutoClient("Exontrol.ContextMenu") contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" iSelect = contextMenu.Select() ? contextMenu.Items.item(iSelect).Caption XBasic (Alpha Five) Dim contextMenu as P Dim iSelect as contextMenu = OLE.Create("Exontrol.ContextMenu") contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" iSelect = contextMenu.Select() ? contextMenu.Items.item(iSelect).Caption Visual Objects local contextMenu as IExContextMenu local iSelect as USUAL // Generate Source for 'ExContextMenu 1.0 Type Library' server from Tools\Automation Server... contextMenu := IExContextMenu{"Exontrol.ContextMenu"} contextMenu:Items:ToString := "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" iSelect := contextMenu:Select(nil,nil,nil) OutputDebugString(String2Psz( contextMenu:Items:[item,iSelect]:Caption )) PowerBuilder OleObject contextMenu any iSelect contextMenu = CREATE OLEObject contextMenu.ConnectToNewObject("Exontrol.ContextMenu") contextMenu.Items.ToString = "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" iSelect = contextMenu.Select() MessageBox("Information",string( contextMenu.Items.item(iSelect).Caption )) Visual DataFlex Procedure OnCreate Forward Send OnCreate Variant contextMenu Get Comcreateobject "Exontrol.ContextMenu" to contextMenu Variant voItems Get ComItems to voItems Handle hoItems Get Create (RefClass(cComItems)) to hoItems Set pvComObject of hoItems to voItems Set ComToString of hoItems to "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" Send Destroy to hoItems Variant iSelect Get ComSelect Nothing Nothing Nothing to iSelect Variant v Variant voItems1 Get ComItems to voItems1 Handle hoItems1 Get Create (RefClass(cComItems)) to hoItems1 Set pvComObject of hoItems1 to voItems1 Variant voitem Get Comitem of hoItems1 iSelect to voitem Handle hoitem Get Create (RefClass(cComitem)) to hoitem Set pvComObject of hoitem to voitem Get ComCaption of hoitem to v Send Destroy to hoitem Send Destroy to hoItems1 Showln v End_Procedure XBase++ #include "AppEvent.ch" #include "ActiveX.ch" PROCEDURE Main LOCAL oForm LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL LOCAL contextMenu LOCAL iSelect oForm := XbpDialog():new( AppDesktop() ) oForm:drawingArea:clipChildren := .T. oForm:create( ,,{100,100}, {640,480},, .F. ) oForm:close := {|| PostAppEvent( xbeP_Quit )} contextMenu := CreateObject("Exontrol.ContextMenu") contextMenu:Items():ToString := "Item A,Item B,Item 3,[sep],Popup(Sub Item A,Sub Item B,Sub Item C,[sep],Popup(Sub Sub Item A,Sub Sub Item B,Sub Sub Item C))" iSelect := contextMenu:Select() DevOut( contextMenu:Items:item(iSelect):Caption() ) oForm:Show() DO WHILE nEvent != xbeP_Quit nEvent := AppEvent( @mp1, @mp2, @oXbp ) oXbp:handleEvent( nEvent, mp1, mp2 ) ENDDO RETURN |