Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to override this dialog easily?

The custom message is already there, but I'm guessing that my client will be more annoying and will want a translated message.

Can I replace that dialog? This dialog is the one that appear if you thrown an exception from inside a class extension.

enter image description here

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Since this has gone unanswered and it looks like a similar issue I had when aborting a delete feature operation, I'll offer my workaround (which I based on something I found on the old Esri forums). It's hacky and you may already be doing this and were looking for a less-hacky method.

Add FindWindow and EndDialog to a class (you might already have a PInvoke class):

public class PInvoke
{
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(String lpszClass, String lpszWindow);

    [DllImport("user32.dll")]
    public static extern int EndDialog(IntPtr hDlg, IntPtr nResult);
 }

Add a timer to your extension class:

private Timer timerDeleteEsriDeleteMessage;

And a property for the timer:

    private Timer TimerRemoveEsriDeleteMessage
    {
        get
        {
            if (timerDeleteEsriDeleteMessage == null)
            {
                timerDeleteEsriDeleteMessage = new Timer();
                timerDeleteEsriDeleteMessage.Interval = 1;
                timerDeleteEsriDeleteMessage.Tick += new EventHandler(OnTimerDeleteEsriDeleteMessageTick);
            }

            return timerDeleteEsriDeleteMessage;
        }
    }

Add the method that actually shuts down the window:

    private void OnTimerDeleteEsriDeleteMessageTick(object timerObject, EventArgs myEventArgs)
    {
        if (((Timer)timerObject).Tag.ToString().Equals("AbortOperation"))
        {
            // Close the dialog with the caption 'Delete'
            IntPtr textBoxHandle = PInvoke.FindWindow(null, "Delete");
            PInvoke.EndDialog(textBoxHandle, (IntPtr)DialogResult.OK);
        }

        this.TimerRemoveEsriDeleteMessage.Stop();
    }

Now the timer can be started just before a delete operation.

            // I show my dialog here (if I want one)

            // then start the timer, then abort the operation
            this.TimerRemoveEsriDeleteMessage.Start();
            this.TimerRemoveEsriDeleteMessage.Tag = "AbortOperation";
            ArcMap.Editor.AbortOperation();

I'm thinking this approach may work for the Create Feature Task could not be completed. message (maybe by replacing Delete with Create in the OnTimerDeleteEsriDeleteMessageTick method).

share|improve this answer
    
Very hacky indeed. I'll give it a try and see how everything comes along. This should work for the save edits dialog too. Nice! –  George Jul 19 '11 at 22:36

Officially, I think there's no way you can do that. I was confronted to the same problem while developping a class extension and decided to do it "ESRI official way" and just raise an error. You can always do a hack like Jay described, but since your class extension can be loaded by other clients than ArcMap, you can't know how the client application will handle the error so you should just raise an exception and let the client application handle it.

Quote from http://help.arcgis.com/en/sdk/10.0/arcobjects_cpp/componenthelp/index.html#/IObjectClassEvents_Interface/000s00000610000000/

If you are using the OnCreate, OnDelete or OnChange methods in a class extension to validate edit operations, you should not call AbortEditOperation on the workspace if your logic indicates that the edit operation is invalid. Instead, raise an error which will be propagated to the application that is performing the edit on the class.

It is the responsibility of the editing application that receives the error to abort the edit operation. This is especially true when editing with ArcMap. If you call AbortEditOperation from within the class extension, the ArcMap undo/redo edit stack will become out of sync

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.