PDA

Ver la Versión Completa Con Imagenes : Ayuda con Excel y las APIs de Windows


Ayudante De Santa
06-11-2015, 22:19:08
Los mejores licores
enzomatrix
08-04-2009, 10:48:18
Parceros el escenario es el siguiente:

Tego una hoja de excel en la cual he programado unas macros con el editor de VB, pero necesito que se ejecute un comando de guardar cuando la hoja o el Excel se encuentre minimizada y se maximice, me comentaron que puedo usar una API de windows llamada GetWindowPlacement, no se como deberia de programarla, alguno de ustedes ha usado APIS de window en el visual de EXCEL???? o saben alguna manera de hacer esto que quiero???, el VB de excel es limitado asi que no hay eventos como onminimize, windowsstate, ni nada que se le parezca.

Ayudante De Santa
06-11-2015, 22:19:08
Los mejores licores
DAROGAS
29-04-2009, 14:53:28
Yo he usado algo asi pero lo tengo en un programa en vb, detecto ciertas ventanas y su estado (min, max).

DAROGAS
29-04-2009, 15:09:45
dim hwnd_Ventana as long

Private Declare Function GetForegroundWindow Lib "user32" () As Integer
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long


if Titulo_Ventana="X" then ' llamo a esta funcion para obtener el nombre de la ventana y el hwnd
_ventana
end if

hwnd_Ventana = GetForegroundWindow()

If ESTADOVENTANA(hwnd_Ventana)<>3 THEN ' SI ES <> DE MAXIMIZADO

End if


Function Titulo_Ventana() As String
'Dim hwnd_Ventana As Long
Dim Length As Long

hwnd_Ventana = GetForegroundWindow()
Phandle = hwnd_Ventana
'Crea un Buffer para el caption del title bar
caption_ventana = Space$(1024)

' Retorna la cantidad de caracteres
Length = GetWindowText(hwnd_Ventana, caption_ventana, Len(caption_ventana))

' Obtiene solo el caption sin los espacios nulos de la cadena
caption_ventana = Left$(caption_ventana, Length)
Titulo_Ventana = caption_ventana
If caption_ventana <> Ventanaanterior Then
Ventanaanterior = caption_ventana
End If
End Function

Private Function ESTADOVENTANA(hwn As Long) As Byte
'Variable para usar la estructura WINDOWPLACEMENT
Dim T_WINDOWPLACEMENT As WINDOWPLACEMENT
Dim Ret As Long 'Valor de retorno de la función

'Para este ejemplo solo necesitamos enviarle el tamaño de la estructura
'en la variable Lenght
T_WINDOWPLACEMENT.Length = Len(T_WINDOWPLACEMENT)

'Llamamos a la función
Ret = GetWindowPlacement(hwn, T_WINDOWPLACEMENT)
' Form1.Cls
Select Case T_WINDOWPLACEMENT.showCmd

Case 1
'MsgBox "Form2 en estado Normal "
ESTADOVENTANA = 1
Case 2
' MsgBox "Form2 Minimizado "
ESTADOVENTANA = 2
Case 3
' MsgBox "Form2 Maximizado "
ESTADOVENTANA = 3
End Select
'Label3.Caption = T_WINDOWPLACEMENT.showCmd

End Function


espero te sirva