UserForm

Discussion in 'AutoCAD' started by David, Feb 18, 2004.

  1. David

    David Guest

    Hi NG;

    I have a couple of UserForm witin my VBA-project.
    All of these forms have a Cancel-button to allow
    the user to Cancel and hide the userform and return
    to ACAD. This button works fine.

    Each userform has a Cross in the upper-right corner
    and the user has the possibility to Cancel the form this way.
    The only problem is what is returned when using that button.
    Is it poosible to catch if the user has canceld it that way?

    ---5 minutes later after trying some more---
    I did manage to solve this using the Terminate-event.

    But is there another way to do it?


    TIA David
     
    David, Feb 18, 2004
    #1
  2. David

    Kevin Terry Guest

    probably, but the terminate event will be the easiest

    Kevin
     
    Kevin Terry, Feb 18, 2004
    #2
  3. David

    David Guest

    Thank you
     
    David, Feb 18, 2004
    #3
  4. Here are a couple of subs I use to remove the titlebar altogether or just disable the close cross & right clicking the titlebar and selecting close.
    Call the appropriate one from the userform Activate event.

    Watch out for wordwrap on the declare functions.

    **********************

    Option Explicit
    Private Declare Function GetActiveWindow Lib "user32" () As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal uPosition As Long, ByVal uFlags As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Public Sub DisableClose()
    Dim hwnd As Long
    Dim hMenu As Long
    hwnd = GetActiveWindow()
    hMenu = GetSystemMenu(hwnd, 0)
    Call RemoveMenu(hMenu, 6, &H400)
    Call RemoveMenu(hMenu, 5, &H400)
    Call DrawMenuBar(hwnd)
    End Sub

    Public Sub Remove()
    Dim hwnd As Long
    Dim dwNewLong As Long
    hwnd = GetActiveWindow()
    dwNewLong = GetWindowLong(hwnd, -16)
    dwNewLong = dwNewLong And Not &HC00000
    Call SetWindowLong(hwnd, -16, dwNewLong)
    DrawMenuBar hwnd
    End Sub

    **********************

    Regards - Nathan
     
    Nathan Taylor, Feb 18, 2004
    #4
  5. David

    David Guest

    Thank you.
    I will try them later.
     
    David, Feb 19, 2004
    #5
  6. David

    SpeedCAD Guest

    Hi David.

    You try do is the following thing:

    The code of button Cancel you copy it and paste in the Terminate event of the Form.

    Private Sub UserForm_Terminate()
    ...equal code to button Cancel...
    End Sub

    Un saludo de SpeedCAD... :)
    CHILE
    FORO: http://www.hispacad.com/foro
     
    SpeedCAD, Feb 19, 2004
    #6
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.