Biblioteca de Apis de Windows

Iniciado por alexander1712, Enero 26, 2013, 02:31:56 AM

Tema anterior - Siguiente tema

0 Miembros y 2 Visitantes están viendo este tema.

Nombre:
GetCursorPos

Declaracion:

Código: php
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


Explicacion:
Esta api sirve para obtener las coordenadas del mouse.

Ejemplo de uso:

Código: php
Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
   x As Long
   y As Long
End Type

Public Function Coordenadas() As String
Dim Coor As POINTAPI
   GetCursorPos Coor
   Coordenadas = "Coordenada en x: " & Coor.x & "Cordenada en y: " & Coor.y
End Function

Private Sub timer1_timer()
   Me.Caption = Coordenadas
End Sub

Nombre:
SetWindowText

Declaracion:

Código: php
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long


Explicacion:
Esta api sirve para cambiar el texto de una ventana

Ejemplo de uso:

Código: php
Option Explicit

Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Private Sub CmdCambiarTexto_Click()
   SetWindowText Me.hwnd, "Aca_va_el_texto"
End Sub

GetForegroundWindow

Declaracion:

Código: php
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long


Explicacion:
Devuelve el Handler de la ventana activa.

Ejemplo de uso:

Código: php
Option Explicit

Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()
   If GetAsyncKeyState(1) = -32767 Then
      MsgBox GetForegroundWindow
   End If
End Sub


En este caso hemos utilizado esta api en conjunto con GetAsyncKeyState(), para que en elmomento que se haga un click izquierdo, nos muestre el hWnd (Handler) de la ventana activa

Nombre:
mouse_event

Declaracion:

Código: php
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)


Explicacion:
simula las pulsaciones del mouse.

Ejemplo de uso:

Código: php
Option Explicit

Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Private Sub Command1_Click()
   Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub


Algunas constantes son:

Código: php
    * Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
    * Private Const MOUSEEVENTF_LEFTUP As Long = &H4
    * Private Const MOUSEEVENTF_MIDDLEDOWN As Long = &H20
    * Private Const MOUSEEVENTF_MIDDLEUP As Long = &H40
    * Private Const MOUSEEVENTF_MOVE As Long = &H1
    * Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    * Private Const MOUSEEVENTF_RIGHTUP As Long = &H10
    * Private Const MOUSEEVENTF_VIRTUALDESK As Long = &H4000
    * Private Const MOUSEEVENTF_WHEEL As Long = &H800
    * Private Const MOUSEEVENTF_XDOWN As Long = &H80
    * Private Const MOUSEEVENTF_XUP As Long = &H100