Accueil > > > QUELQUES API TRÉS SIMPLE ET UTILE
QUELQUES API TRÉS SIMPLE ET UTILE
Information sur la source
Description
Slt Ci joint qq api avec Exemple d'utilisation (commenté..) Elle sont trés simple et peuvent étre utilie : - Flash Windows : Fait Clignoter la caption de la form - Beep : Emet des sons par le speaker du Pc (Beep de vb marche po!!) - Sleep : Fait attendre l'execution du code - BlockInput : Desactive le clavier et la souris - FindExecutable : Trouve le programme associé au fichier - GetUserName : Donne le nom d'utilisateur de la session - GetCursorPos : Donne la position de la souris - SetCursorPos : Modifie la position de la souris - PlaySound : Joue un fichier son - SetComputerName : Change le nom de l'ordinateur - SetVolumeLabel : Change le nom de volume d'un disque - InetIsOffline : L'odi est il connecter a internet??? - GetDiskFreeSpace : Info Espace Disque - GetTickCount : Donne le temps en sec depuis lequelle windows a démmarer (GetTickcount peu etre utile pour calculer le temps qu'a pris une tache : on releve le temp T1 avant de lancer la procedure, et le temp T2 une fois la procedure fini. T2-T1 donne le temp écouler en secondes!!!) Voila ce sont des api qui peuvent etre utile, mais ce sont vraiment des apis facile a utiliser (ideal pour debutant!!!)
Source
- 'Déclaration api SetVolumeLabel
- Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
- 'Déclaration api SetCursorPos
- Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
- 'Déclaration api SetComputerName
- Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long
- 'Déclaration api PlaySound
- Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
- 'Déclaration api InetIsOffline
- Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
- 'Déclaration api GetTickCount
- Private Declare Function GetTickCount& Lib "kernel32" ()
- 'Déclaration api GetDiskFreeSpaceEx
- Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
- 'Déclaration api GetCursorPos
- Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Type POINTAPI
- x As Long
- y As Long
- End Type
- 'Déclaration api GetUserName
- Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
- Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
- 'Déclaration api FindExecutable
- Const MAX_FILENAME_LEN = 260
- Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
- 'Déclaration api blockinput (clavier souris)
- Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
- 'Décaration api Sleep
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- 'Déclaration api flash de la fenetre
- Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
- Const Invert = 1
- 'Déclaration Api Beep
- Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
- 'Api Flahwindows
- Private Sub Command1_Click()
- Me.WindowState = 1
- Me.Caption = "Api FlashWindow"
- If Timer1.Enabled = False Then Timer1.Enabled = True Else Timer1.Enabled = False
- End Sub
-
- Private Sub Command10_Click()
- MsgBox "Etes vous connecté a internet? " + CStr(CBool(Not (InetIsOffline(0)))), vbInformation
-
- End Sub
-
-
-
-
- Private Sub Command11_Click()
- PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
-
- End Sub
-
- Private Sub Command12_Click()
- NvNom$ = InputBox("Nouveau nom du Pc ?", "SetComputerName...")
- SetComputerName (NvNom$)
- MsgBox "Au prochain redémarrage le nom de l'ordinateur sera : " & NvNom$
- End Sub
-
- Private Sub Command13_Click()
- 'recupére la position du pointeur avec api GetCursorPos
- Dim Point As POINTAPI
- GetCursorPos Point
- 'Repositionne le pointeur de la souris
- SetCursorPos Point.x + 300, Point.y + 300
- End Sub
-
- Private Sub Command14_Click()
- NvNom$ = InputBox("Nouveau nom pour le lecteur c: ?", "SetVolumeLabel")
- SetVolumeLabel "c:\", NvNom$
- End Sub
-
- 'Api Beep
- Private Sub Command2_Click()
- Dim Cnt As Long
- For Cnt = 0 To 500 Step 10
- '0 a 500Hrz pendant 50ms
- Beep Cnt, 50
- DoEvents
- Next Cnt
- End Sub
-
- Private Sub Command3_Click()
- MsgBox "L'api sleep va faire attendre le code pendant 5sec", vbInformation
- Sleep 5000
- MsgBox "Voila 5 secondes se sont écoulées...", vbExclamation
- End Sub
-
- Private Sub Command4_Click()
-
- DoEvents
- 'bloque le clavier et la souris
- BlockInput True
-
- 'Attent 10 sec
- Sleep 10000
-
- 'débloque le clavier et la souris
- BlockInput False
-
- End Sub
-
-
- Private Sub Command5_Click()
- Dim i As Integer, s2 As String
- Const sFile = "C:\Windows\system.ini"
-
- 'Verification de l'existance du fichier
- If Dir(sFile) = "" Or sFile = "" Then
- MsgBox "fichier non trouvé", vbCritical
- Exit Sub
- End If
- 'Creer un buffer
- s2 = String(MAX_FILENAME_LEN, 32)
- 'recherche le nom et le handle del' executable, associé avec ce fichier
- i = FindExecutable(sFile, vbNullString, s2)
- If i > 32 Then
- MsgBox Left$(s2, InStr(s2, Chr$(0)) - 1)
- Else
- MsgBox "Pas de programme associé!!!"
- End If
- End Sub
-
- Private Sub Command6_Click()
- Dim dwLen As Long
- Dim strString As String
- 'Creer un buffer
- dwLen = MAX_COMPUTERNAME_LENGTH + 1
- strString = String(dwLen, "X")
- 'prend le nom
- GetUserName strString, dwLen
- 'Affiche le nom utilisateur
- MsgBox strString
-
- End Sub
-
- Private Sub Command7_Click()
- Dim Point As POINTAPI
- GetCursorPos Point
- MsgBox "Le curseur se trouve :" & Point.x & "," & Point.y
-
- End Sub
-
- Private Sub Command8_Click()
- Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
- Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
- 'Le disque
- Const RootPathName = "C:\"
- Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
- Me.Print
- Msg = "Espace Total: " & Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
- "Espace Libre :" & Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
- "Espace Utilisable :" & Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
- "Espace Utilisé :" & Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
- 'Affichage
- MsgBox Msg
-
- End Sub
-
- Private Sub Command9_Click()
- Dim Mn As Long
- Mn = GetTickCount / 60000
- MsgBox "Windows est démarrer depuis " & Mn & " minutes."
-
- End Sub
-
- Private Sub Form_Load()
-
- End Sub
-
- Private Sub Timer1_Timer()
- Static Sec As Integer
- Sec = Sec + 1
- If Sec = 10 Then Timer1.Enabled = False: Me.WindowState = 0: Me.Caption = "Quelques Api..."
- FlashWindow Me.hwnd, Invert
- End Sub
-
-
'Déclaration api SetVolumeLabel
Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
'Déclaration api SetCursorPos
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
'Déclaration api SetComputerName
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long
'Déclaration api PlaySound
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'Déclaration api InetIsOffline
Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
'Déclaration api GetTickCount
Private Declare Function GetTickCount& Lib "kernel32" ()
'Déclaration api GetDiskFreeSpaceEx
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
'Déclaration api GetCursorPos
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
'Déclaration api GetUserName
Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Déclaration api FindExecutable
Const MAX_FILENAME_LEN = 260
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
'Déclaration api blockinput (clavier souris)
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
'Décaration api Sleep
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Déclaration api flash de la fenetre
Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Const Invert = 1
'Déclaration Api Beep
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
'Api Flahwindows
Private Sub Command1_Click()
Me.WindowState = 1
Me.Caption = "Api FlashWindow"
If Timer1.Enabled = False Then Timer1.Enabled = True Else Timer1.Enabled = False
End Sub
Private Sub Command10_Click()
MsgBox "Etes vous connecté a internet? " + CStr(CBool(Not (InetIsOffline(0)))), vbInformation
End Sub
Private Sub Command11_Click()
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
Private Sub Command12_Click()
NvNom$ = InputBox("Nouveau nom du Pc ?", "SetComputerName...")
SetComputerName (NvNom$)
MsgBox "Au prochain redémarrage le nom de l'ordinateur sera : " & NvNom$
End Sub
Private Sub Command13_Click()
'recupére la position du pointeur avec api GetCursorPos
Dim Point As POINTAPI
GetCursorPos Point
'Repositionne le pointeur de la souris
SetCursorPos Point.x + 300, Point.y + 300
End Sub
Private Sub Command14_Click()
NvNom$ = InputBox("Nouveau nom pour le lecteur c: ?", "SetVolumeLabel")
SetVolumeLabel "c:\", NvNom$
End Sub
'Api Beep
Private Sub Command2_Click()
Dim Cnt As Long
For Cnt = 0 To 500 Step 10
'0 a 500Hrz pendant 50ms
Beep Cnt, 50
DoEvents
Next Cnt
End Sub
Private Sub Command3_Click()
MsgBox "L'api sleep va faire attendre le code pendant 5sec", vbInformation
Sleep 5000
MsgBox "Voila 5 secondes se sont écoulées...", vbExclamation
End Sub
Private Sub Command4_Click()
DoEvents
'bloque le clavier et la souris
BlockInput True
'Attent 10 sec
Sleep 10000
'débloque le clavier et la souris
BlockInput False
End Sub
Private Sub Command5_Click()
Dim i As Integer, s2 As String
Const sFile = "C:\Windows\system.ini"
'Verification de l'existance du fichier
If Dir(sFile) = "" Or sFile = "" Then
MsgBox "fichier non trouvé", vbCritical
Exit Sub
End If
'Creer un buffer
s2 = String(MAX_FILENAME_LEN, 32)
'recherche le nom et le handle del' executable, associé avec ce fichier
i = FindExecutable(sFile, vbNullString, s2)
If i > 32 Then
MsgBox Left$(s2, InStr(s2, Chr$(0)) - 1)
Else
MsgBox "Pas de programme associé!!!"
End If
End Sub
Private Sub Command6_Click()
Dim dwLen As Long
Dim strString As String
'Creer un buffer
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String(dwLen, "X")
'prend le nom
GetUserName strString, dwLen
'Affiche le nom utilisateur
MsgBox strString
End Sub
Private Sub Command7_Click()
Dim Point As POINTAPI
GetCursorPos Point
MsgBox "Le curseur se trouve :" & Point.x & "," & Point.y
End Sub
Private Sub Command8_Click()
Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
'Le disque
Const RootPathName = "C:\"
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
Me.Print
Msg = "Espace Total: " & Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
"Espace Libre :" & Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
"Espace Utilisable :" & Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes" & vbCrLf & _
"Espace Utilisé :" & Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
'Affichage
MsgBox Msg
End Sub
Private Sub Command9_Click()
Dim Mn As Long
Mn = GetTickCount / 60000
MsgBox "Windows est démarrer depuis " & Mn & " minutes."
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
Static Sec As Integer
Sec = Sec + 1
If Sec = 10 Then Timer1.Enabled = False: Me.WindowState = 0: Me.Caption = "Quelques Api..."
FlashWindow Me.hwnd, Invert
End Sub
Conclusion
Tous est dans le Zip!!!!!
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
GetEnvironmentVariable [ par Boldor ]
Bonjour,Je voudrai recuperer la valeur des variables d'environnement a partir d'un programme VB.Comment utiliser la fonction GetEnvironmentVariable ?Y
les API windows [ par Mskine ]
Où je peux trouver des informations,definitions, conseils, des fonctions APIMerci d'avance
API [ par CyrilB ]
Je voudrais pouvoir fermer une fenêtre MS-DOS même si celle-ci est en cours d'execution.Il y a une fonction API qui fait ça mais je ne sais plus laque
Proprietes des fichiers ss NT 4.00 \ Utilisation des fonctions API [ par Xavier ]
En fouillant dans l'aide des API, j'ai trouve quelques fonctions pouvant resoudre mon probleme.Qui peut me dire comment faire appel aux fonctions :Get
API pour icônes [ par Xaviou ]
Salut,Je suis à la recherche d'une API pour afficher la boite de dialogue de changement d'icône (boite que l'on peut obtenir, lorsque l'on regarde les
API SHGetFileInfo [ par Xaviou ]
Salut,quelqu'un saurait-il comment utiliser l'API SHGetFileInfo ? Pour ma part, c'est le bide complet.J'attends vos réponses avec impatience.@+Xaviou
Menu avec icone [ par Xaviou ]
Salutje recherche l'API pour intégrer des incones dans mes menus. J'ai trouvé une API (ModifyMenu) qui permet de remplacer le caption d'un menu par un
Fonctions API [ par Yvan ]
Une petite question : les fonctions API fonctionnent-elles de la même façonsur Win 95, Win 98 et Win NT ?Si je prends comme exemple la fonction GetVo
Lecteurs disponibles [ par Yvan ]
Salut,Je cherche le moyen de connaître les lettres des lecteurs qui se trouvent sur un ordinateur. Ce qui doit se faire avec les API selon moi. Et s
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|