NOTA: Esta página está traducida por un traductor de esos gratuitos, no es una página normal.

API of windows (2º)
any functions interestings OF API of Windows (16 and 32 bits)

Actualizado the 10-Abr-1997


Functions and examples: ( the entrega former)

  1. Search on a Combobox or Listbox using THE API
  2. SHFORMATDRIVE: Formatear a drive using THE API (and Getdrivetype for know than type of unit is)

 

 

1.- Search into one Combobox or Listbox using THE API (1/Sea)

the función than se encarga this task, like almost ever, is Sendmessage and se deben specify the nexts constantes like the message than queremos send, according to it than queramos do:

Const CB_FINDSTRINGEXACT = &H158        'search string completa into one  Combobox 
Const LB_FINDSTRINGEXACT = &H1 TO 2        'search string completa into one  Listbox 
Const CB_FINDSTRING = &H14C     'search string since  the starting  into one  Combobox 
Const LB_FINDSTRING = &H18F     'search string since  the starting  into one  Listbox

the declaration the Sendmessage, debe quedar of this manner , fijate than the parámetro lparam está definite like Any, of this shape , aceptará cualquier type of datum , Long or Byval...

#If Win32 Then 
    Declare Function Sendmessage Lib "User32" Alias "Sendmessagea" _ 
        (Byval hwnd As Long, Byval wmsg As Long, _ 
         Byval wparam As Long, lparam As Any) As Long 
#Else 
    Declare Function Sendmessage Lib "User" _ 
        (Byval hwnd As Integer, Byval wmsg As Integer, _ 
         Byval wparam As Integer, lparam As Any) As Long 
#End If 

the next example is a función than inserta a new elemento on a list or a combo, yes is than don't existe, clear.

Public Function Actualizarlista(stexto As String, clist As Control) As Long 
    'esta función comprobará yes  the text  indicado existe on  the list  
    'yes there is not  thus, it añadirá 
    'he boldness devuelto, será  the  posición inside of the list  ó -1 yes hay "fallos" 
    ' 
    'para search on  the  List/combo usaremos  a  llamada al API 
    '(yes already hay  a shape   of  hacerlo, ¿in order for  re-hacerla?) 
    ' 
    Const CB_FINDSTRINGEXACT = &H158        'message  the combos  
    Const LB_FINDSTRINGEXACT = &H1 TO 2        'message For the lists  
    Dim L As Long 
     
    If clist.Listcount = 0 Then 
        'safe than  don't  está, thus than añadirla 
        L = -1 
    Else 
        'yes  the  control is  a  Combo 
        If Typeof clist Is Combobox Then 
            L = Sendmessage(clist.hwnd, CB_FINDSTRINGEXACT, -1, Byval stexto) 
        'yes  the  control is  a  list 
        Elseif Typeof clist Is Listbox Then 
            L = Sendmessage(clist.hwnd, LB_FINDSTRINGEXACT, -1, Byval stexto) 
        Else 
            'don't is  a  control List or Combo, exiting 
            Actualizarlista = -1 
            Exit Function 
        End If 
    End If 
     
    'yes  don't  está, añadirla 
    If L = -1 Then 
        clist.Additem stexto 
        L = Actualizarlista(stexto, clist) 
    End If 
    Actualizarlista = L 
End Function 

this another example is for perform a búsqueda on the Combo/List, al style of the help of windows , is a version the on the tricks , but using Sendmessage.
for usarlo into one Listbox, debes indicate the constante LB_FINDSTRING, in lieu of CB_FINDSTRING

( this "truco" está sacado OF MSDN Library: Tip 115: Performing Smart Searches in Combo Box Controls)

Private Sub Combo1_Keypress(Keyascii As Integer) 
    Dim CB As Long 
    Dim Findstring As String 
    Const CB_ERR = (-1) 
    Const CB_FINDSTRING = &H14C 
     
     
    If Keyascii <32 Or Keyascii > 127 Then Exit Sub 
     
    If Combo1.Sellength = 0 Then 
        Findstring = Combo1.Text & Chr$(Keyascii) 
    Else 
        Findstring = Left$(Combo1.Text, Combo1.Selstart) & Chr$(Keyascii) 
    End If 
     
    CB = Sendmessage(Combo1.hwnd, CB_FINDSTRING, -1, Byval Findstring) 
     
    If CB <> CB_ERR Then 
        Combo1.Listindex = CB 
        Combo1.Selstart = Len(Findstring) 
        Combo1.Sellength = Len(Combo1.Text) - Combo1.Selstart 
    End If 
    Keyascii = 0 
End Sub 
 

 

 

2.- SHFORMATDRIVE: Formatear a drive using THE API, Getdrivetype for know than type of unit (10/Abr)

this función is the than Joe Levasseur ha used their utility of formatear and copiar drives.
the declaration is:

Declare Function SHFORMATDRIVE Lib "shell32" _ 
    (Byval hwnd As Long, Byval Drive As Long, Byval fmtid As Long, _ 
    Byval options As Long) As Long 

the shape of usarla:

    Dim Driveletter$, Drivenumber&, Drivetype& 
    Dim Retval&, Retfrommsg% 
    Driveletter = UCASE(Drive1.Drive) 
    Drivenumber = (Asc(Driveletter) - 65) ' Change  the  letra  to  número:  TO =0 
    Drivetype = Getdrivetype(Driveletter) 
    'if Drivetype = 2 Then  'disquetes, etc 
    Retval = SHFORMATDRIVE(Me.hwnd, Drivenumber, 0&, 0&) 

the declaration OF API for Getdrivetype:

Declare Function Getdrivetype Lib "kernel32" Alias "Getdrivetypea" _ 
        (Byval ndrive As String) As Long 

ir al índice