Select to view content in your preferred language

Invoking arcmap application using C#

3476
3
09-22-2010 11:14 PM
ShreyPrasad
Deactivated User
Hello,

   I want to start  the arcmap 9.3.1 after the user loginID has been verifed .I am developing in C# (VS 2008) .

I am able to  find the code for invoking arcmap in VB.net i.e as mentioned below
Shell( "C:\\programfile\ESRI\\bin\arcmap.exe", AppWinStyle.MaximizedFocus, True, -1)

How can i invoke it in C# please help me in this.
I also want to load my custom toolbars after after the arcmap opens .
0 Kudos
3 Replies
HeribertoMantilla_Santamaría
Deactivated User
Hi.

You can use the API ShellExecute.

/* VB DECLARED */

Public Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long


/* C# Equivalent */
[System.Runtime.InteropServices.DllImport("shell32.dll", EntryPoint = "ShellExecute")]
public static extern int ShellExecuteA(int hwnd, string 
lpOperation, string lpFile, string lpParameters, string lpDirectory,
int nShowCmd);


ShellExecuteA(hWnd, "OPEN", "YOURFILE", Parameters, "", 0); // SW_HIDE
ShellExecuteA(hWnd, "OPEN", "YOURFILE", Parameters, "", 1); // SW_SHOW


Here the article in MSDN: http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx
0 Kudos
AlexanderSedykh
Emerging Contributor
🙂 
System.Diagnostics.Process.Start(@"C:\Program Files\ESRI\bin\arcmap.exe");
0 Kudos
ShreyPrasad
Deactivated User
🙂 
System.Diagnostics.Process.Start(@"C:\Program Files\ESRI\bin\arcmap.exe");


Thank You all friend I found a solution for this i am using the following codes :

  public void StartArcMap()
        {

            try
            {
                if (m_pDoc == null)
                {
                    // Cursor.Current = Cursors.WaitCursor;

                    //Start arcmap
                    CheckLicence();
                    //m_pDoc = new MxDocumentClass();

                    ////Get a reference to the application
                    //m_application = m_pDoc.Parent;


                    m_pDoc  = new MxDocument() ;
                    m_application = m_pDoc.Parent;
                 //   m_application.OpenDocument("ur mxd file path ");

                    m_appHWnd = m_application.hWnd;
                    m_application.Caption = "Wht Ever u want to give here ";
                    m_pMxdocument = m_application.Document as IMxDocument;


                    //Show arcmap
                    m_application.Visible = true;

                  
                    //Hide All toolbars of Arcmap
                     m_application.Document.CommandBars.HideAllToolbars();


                     //Get the commandbars collection
                     ICommandBars pCmdBars;
                     pCmdBars = m_application.Document.CommandBars;
                     pCmdBars.Create("Adminstrator", ESRI.ArcGIS.SystemUI.esriCmdBarType.esriCmdBarTypeToolbar);
                     ICommandBar pAdminstrator;
                   
                     // The identifier for the Select Graphics Tool
                     UID uidAdmin= new UIDClass();
                     uidAdmin.Value = "Tools.Administrator";
                     //Find the Select Graphics Tool
                    // pNewBar = pCmdBars.Create("Adminstrator", ESRI.ArcGIS.SystemUI.esriCmdBarType.esriCmdBarTypeToolbar);
                     pAdminstrator = (ICommandBar)pCmdBars.Find(uidAdmin, false, false);
                     pAdminstrator.Dock(ESRI.ArcGIS.Framework.esriDockFlags.esriDockHide, null);


                    //Adding the Tool Item
                     UIDClass uid= new UIDClass();
                     uid.Value = "Tools.clsSearch";
                     int intSearch = pAdminstrator.Count;
                     object objSearch = intSearch;
                     ICommandItem cmdSearch;
                     cmdSearch = m_pDoc.CommandBars.Find(uid, true, true);
                     pAdminstrator.Add(uid, ref objSearch); 
                       
                     //Set the current tool of the application to be the Select Graphics Tool
                     

                 


                    //disable and enable buttons
                    // Cursor.Current = Cursors.Default;
                }//End  IF statement

                //Calling to Add The Shape File
                AddShapefile();

            }//Try
            catch (Exception ex)
            {
                MessageBox.Show("" + ex);
            }



        }//Start the Arcmap Application


I am not sure about the Command bars but the Arcmap is definitely invoking
Thank You once again guys for ur help
0 Kudos