Solving Zero-Document State problem in VBA

Discussion in 'AutoCAD' started by Maksim Sestic, Feb 7, 2004.

  1. Dear all,

    After many tries to solve the Zero-Document State situation and custom menus
    visibility, I turned to the less practical but (seems) only possible
    solution. Here goes the "history" of the problem...

    I discarded all original ACAD menus and replaced them with my custom menus.
    Necessity, as there is no localized ACAD version for the market I'm
    distributing my application for. Alas, in Zero-Document State custom menus
    disappear and user gets the system-predefined menus (File, View, Window,
    Help) he/she cannot use (remember, my users can't read English). The other
    thingie is that my users run the ACAD-based application through startup EXE
    file which fixes ACAD up, like loading menus and toolbars, generating
    profiles, setting up registry entries, activating event schemes, _setting
    RegistryEntry.AppBeginClose to "No"_, etc.

    Here are the tips:

    1) ACAD application's close (X) button gets disabled and "Close" popup gets
    removed - to avoid the unpleasant system menu and other possible
    implications of mishandling the application...

    2) The special Registry entry named AcadBeginClose that is initially set to
    "No". It's purpose is to indicate if user implicitly wants out of ACAD. Good
    thing is that I can check against this entry every time user runs the
    application to see if it was shut down properly.

    3) My own ACAD exiting function with appropriate menu label in unsupported
    language (say, "The End" which runs Projects.TheEnd macro):

    (...Projects module...)
    Sub TheEnd()
    RegistryEntry.AppBeginClose = "Yes"
    ThisDrawing.SendCommand Chr(3) & Chr(3) & "QUIT" & vbCr
    End Sub

    (Note: "RegistryEntry" is a public class that deals with registry entries -
    you can download it from couple of Web sites)

    4) Event mechanism for closing the drawing:

    (...EventClassModule...)
    Private Sub acaddoc_BeginClose()
    If Application.Documents.Count = 1 Then
    If RegistryEntry.AppBeginClose = "No" Then
    Application.Documents.Add
    End If
    End If
    End Sub

    What happens then? When user tries to close the last active document, he
    gets a new one without getting into a Zero-Document State. In the same way,
    instead of launching a new document (Application.Documents.Add) I
    implemented a Form offering few possible solutions (like ACAD's form back in
    R14). But, this is just a short explanation of methods. On the other hand,
    when user implicitly runs TheEnd module then there's no new document
    generation and ACAD has a clean exit (I'm using SendCommand rather than
    Application.Quit as there are situations where ACAD process gets stuck and
    remains active in memory).

    I hope I helped even a bit with this workaround which may seem as an
    overkill to some of you, but, at least, it's all about VBA :)

    Regards,
    Maksim Sestic
     
    Maksim Sestic, Feb 7, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.