AcadDocument_Activate

Discussion in 'AutoCAD' started by Allen Johnson, Jun 23, 2004.

  1. I use the following to toggle a UCS Follow indicator button. (The SBBUCSFollow is a class object.)

    Private Sub AcadDocument_Activate()
    On Error Resume Next
    If Documents.Count = 1 Then AddButtons
    SBBUCSFollow.SetCurrentState
    If Err.Number > 0 Then AddButtons: Err.Clear
    End Sub

    Since UCS Follow can be different for each drawing, I check the current state of the UCSFollow
    using:

    Public Sub SetCurrentState()
    SBButton.Pressed = ThisDrawing.GetVariable("UCSFollow") = 1
    End Sub


    When switching from one drawing to the next, it seems like I have to click in the drawing window, in
    order to begin typing commands.
    Say I switch from one drawing to the next and immediately start typing "Line". Nothing happens
    until I click in the drawing window, which then starts the implied selection window and now I have
    to hit escape to get out of it.

    The problem seems to be in the SetCurrentState, because if I remove the call to it in
    AcadDocument_Activate, you can start typing with having to click the window.

    Is there a way to allow one to start typing immediately without clicking in the drawing area?
     
    Allen Johnson, Jun 23, 2004
    #1
  2. Tony Tanzillo, Jun 23, 2004
    #2
  3. I thought I did.
     
    Allen Johnson, Jun 23, 2004
    #3
  4. Sorry, didn't see it.

    Other than sticking a call to DoEvents in there, I don't
    know if there is any other way, short of PostMessage().
    Using one of the BM_XXXX messages.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 24, 2004
    #4
  5. Perhaps removing the call to setcurrentstate avoids the addbuttons sub
    What does the AddButtons do ?
    Post the code.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


    SBBUCSFollow is a class object.)
    selection window and now I have
     
    Jorge Jimenez, Jun 24, 2004
    #5
  6. Removing the call to SetCurrentState sort of defeats the whole purpose, i.e. to set the state of the
    button to the proper setting based upon the UCSFollow variable, which can be different between
    drawings.

    The AddButtons adds the buttons to the status bar . I'm using Manusoft's

    AcadStatButton.zip 70 k 2004-06-14 Win R14-
    R2005 Freeware C++ library for adding your own status bar button to the right edge of the
    AutoCAD status bar. Includes ActiveX interface for use in VBA and Visual Lisp.
     
    Allen Johnson, Jun 24, 2004
    #6
  7. So, if you don't call the AddButtons, do you still have the problem ??
     
    Jorge Jimenez, Jun 24, 2004
    #7
  8. It looks like a thread state problem. I'd suggest you ask Owen
    if he's using PostMessage() under the hood. If not, changing to
    it may solve the problem, but I don't think there is any solution
    at the client code level.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 25, 2004
    #8
  9. Check that. It looks like the SetCurrentState method is taking the
    focus away from the drawing view window. You can try using the
    WinAPI SetFocus() and the HWND property of the active document.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 25, 2004
    #9
  10. If you rem out the line

    SBButton.Pressed = ThisDrawing.GetVariable("UCSFollow") = 1

    you can type immediately. (But that sort of defeats the whole purpose of this exercise!)
    I'm suspecting your first reply (PostMessage?) may be the problem.
    But I'll try the SetFocus. Thanks.
     
    Allen Johnson, Jun 25, 2004
    #10
  11. Yes, the problem is most likely that when the button's
    pushed state changes, it takes the focus from the AutoCAD
    view window.

    These types of buttons should not be able to get
    focus to begin with.




    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 25, 2004
    #11
  12. The SetFocus fixed the problem.
    Thanks for your help.
    -------------------------------------------------------------------------------------
    Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long

    Public Sub SetCurrentState()
    SBButton.Pressed = ThisDrawing.GetVariable("UCSFollow") = 1
    SetFocus ThisDrawing.hwnd
    End Sub
     
    Allen Johnson, Jun 25, 2004
    #12
  13. Allen Johnson

    Owen Wengerd Guest

    Yes, the problem is most likely that when the button's
    By design, the button's window message handler stores the handle of the
    window losing focus during WM_SETFOCUS, then restores focus to that window
    when the button is released (BM_SETSTATE with wParam == FALSE). I'll
    investigate this further when I get some free time. Ignoring WM_SETFOCUS
    would make everything simpler, but I know I originally added this kludge for
    a reason (I just don't remember the reason). :)
     
    Owen Wengerd, Jun 25, 2004
    #13
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.
Similar Threads
There are no similar threads yet.
Loading...