Cerrar
¿Te gusta hispacad? Compártelo
Llámenos: 668 83 00 83

Como hacer transparente un formulario

Al igual que otros muchos programas, AutoCAD® permite la utilización del lenguaje de programación Visual Basic para la programación de aplicaciones, que serán ejecutadas sobre AutoCAD®. De esta manera nos encontramos con otra posibilidad además de AutoLISP, para la personalización y desarrollo de nuevas aplicaciones que optimecen el trabajo diario. Plantee sus dudas y comparta sus conocimientos en este lenguaje de programación.

Moderadores: Jorge_BH, Yoland, SpeedCAD, Acad version

Como hacer transparente un formulario

Notapor Jorge_BH » Lun 28 Ene, 2008 20:01

Macro con funciones para modificar la apariencia y comportamiento de un userform:
Permite maximizar y minimizar el formulario, quitarle la barra de titulo, hacerlo transparente y otras cosas.

Lo de la transpariencia solo funciona con Windows 2000 y superiores
Jorge_BH
 
Mensajes: 1602
Registrado: Mié 07 Nov, 2007 03:31
Ubicación: 127.0.0.1

Re: Como hacer transparente un formulario

Notapor manuelpardo » Lun 11 Feb, 2008 08:16

Muchas gracias, me parece una cosa curiosa, la probaré.
manuelpardo
 
Mensajes: 41
Registrado: Vie 26 Nov, 2004 11:42

Notapor R&R » Sab 08 Mar, 2008 16:42

Muchas gracias por la información a Jorge_BH

Sobre el tema de transparencia de un formulario les envío algunas NOTAS que alclaran su utilización, donde también se incluye el uso API de windows para lograrlo.

Issue

How can I create a modeless VBA form in AutoCAD ?

Solution

Normally, you can do it as indicated below,

1. Start Acad and VBA.

2. Insert a user form, default name UserForm1.

3. Write a simple VBA sub routine to launch it as a modeless form

Código: Seleccionar todo
Sub test()
    Load UserForm1
    UserForm1.Show vbModeless
End Sub

You can run it and you can see that you have a modeless form floating there. However, you can't shift the focus to it. In another word, it can't keep focus on itself. The reason is that Acad has a custom message that is not handled by the VBA form.

There are two solutions, the first one works only in Acad 2002.

1. Within the VBA IDE, make sure the UserForm1 is visible and Toolbox toolbar is shown. Right mouse click on the Toolbox, click Additional Controls. In the Available Controls list, check AcFocusCtrl Class. Click OK. The AcFocusCtrl should show up in the Toolbox toolbar. Drag and insert it into anywhere inside the UserForm1. That's it. Now the Sub Test() routine above should work fine.

Note: You may have to manually register AcFocusCtrl.dll. To do that, run the following at the DOS prompt,

REGSVR32 "c:\program files\common files\autodesk shared\acfocusctrl.dll"

2. You can force the modeless form to keep the focus by specifying the WS_OVERLAPPED style. As this style isn't available to VBA, you have to use Win32 API function SetWindowLong(), and simply remove (XOR) the WS_POPUP style which is set by default (since WS_OVERLAPPED = 0). AutoCAD can't take the focus away from a dialog with this style, so the form and its controls keeps the focus properly. Also in VBA, you don't have access to the HWND of the dialog, but you can get it with EnumWindows().

Código: Seleccionar todo
' Declare Win32 functions needed...

Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Dim ThisHwnd As Long

Public Const GWL_STYLE = -16

Public Const WS_POPUP = &H80000000

' When the form is activated, find the dialog's HWND, and subclass the styles...

Private Sub UserForm_Activate()

    Call EnumWindows(AddressOf EnumWindowsProc, vbNull)

    Call SubClass

End Sub

' Here is the callback for Enumwindows...

Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Integer

    Dim title As String * 32

    Call GetWindowText(hWnd, ByVal title, 32)

    If InStr(title, "MyForm") Then

        ThisHwnd = hWnd ' Found our window...

        EnumWindowsProc = False' Cancel the search

    Else

        EnumWindowsProc = True ' Continue the search

    End If

End Function

Public Function SubClass() As Long

    Dim Flags As Long

    Flags = GetWindowLong(ThisHwnd, GWL_STYLE)' Get the current styles...

    Flags = Flags Xor WS_POPUP ' Get Rid of the POPUP style

    SetWindowLong ThisHwnd, GWL_STYLE, Flags ' Reset the Style

End Function


This does require the ShowModal property to be set to false, and the Show method is still called to invoke it as normal. This may yet be simplified as well. A sample DVB file is attached.
Un saludo para todos
R&R
 
Mensajes: 247
Registrado: Mié 22 Mar, 2006 21:52
Ubicación: Otavalo


Volver a VB/VB.NET para AutoCAD®

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados