Stagiaire WDF
Inscrit: 29/06/2004 09:31
De Paris
Post(s): 40
|
Le Q&R doit être en grève de mise à jour... Ci-joint les bouts de code pour répondre à 2/3 questions: 1) Comment récupérer une valeur binary du registre :
// Déclarations
hKey is int
lpcbData is int
ulOptions is int
lsData is string
// Read option
ulOptions=BinaryOR(0x00020000, 0x0001)
ulOptions=BinaryOR(ulOptions, 0x0008)
ulOptions=BinaryOR(ulOptions, 0x0010)
ulOptions=BinaryAND(ulOptions, BinaryNOT(0x00100000))
// Open key ( 0x80000001 --> HKEY_CURRENT_USER\ )
// With subkey Software\MyOtherSubKey
IF API("ADVAPI32.DLL","RegOpenKeyExA", 0x80000001, "Software\MyOtherSubKey", 0, ulOptions, &hKey)<>0 THEN
Error(ErrorInfo())
RETURN
END
// Ask for buffer size
IF API("ADVAPI32.DLL","RegQueryValueExA", hKey, "MyValueToQuery", Null, "binary", Null, &lpcbData)<>0 THEN
API("ADVAPI32.DLL","RegCloseKey",hKey)
Error(ErrorInfo())
RETURN
END
// Fill string for enough data space
lsData=RepeatString(" ", lpcbData+1)
// Ask for binary data
IF API("ADVAPI32.DLL","RegQueryValueExA", hKey, "MyValueToQuery", Null, "binary", &lsData, &lpcbData)<>0 THEN
API("ADVAPI32.DLL","RegCloseKey",hKey)
Error(ErrorInfo())
ELSE
Info(lsData)
END
// Close opened key
API("ADVAPI32.DLL","RegCloseKey",hKey)
---------------------------------------------------------------------- 2) Comment enregistrer une valeur binary dans le registre :
// Déclarations
hKey is int
lpcbData is int
ulOptions is int
ulOptions1 is int
ulOptions2 is int
lsData is string
// Read option
ulOptions1=BinaryOR(0x00020000, 0x0001)
ulOptions1=BinaryOR(ulOptions1, 0x0008)
ulOptions1=BinaryOR(ulOptions1, 0x0010)
ulOptions1=BinaryAND(ulOptions1, BinaryNOT(0x00100000))
// Write option
ulOptions2=BinaryOR(0x00020000, 0x0002)
ulOptions2=BinaryOR(ulOptions2, 0x0004)
ulOptions2=BinaryAND(ulOptions2, BinaryNOT(0x00100000))
// Open key ( 0x80000001 --> HKEY_CURRENT_USER\ )
// With subkey Software\MyOtherSubKey
IF API("ADVAPI32.DLL","RegOpenKeyExA", 0x80000001, "Software\MyOtherSubKey", 0, OUBinaire(ulOptions1, ulOptions2), &hKey)<>0 THEN
Error(ErrorInfo())
RETURN
END
// What we want to store
lsData="Hello"+RC+RC+"My Name is Bond, James Bond"+RC
// Set binary data
IF API("ADVAPI32.DLL","RegSetValueExA", hKey, "MyValueToQuery", Null, "binary", lsData, Taille(lsData))<>0 THEN
API("ADVAPI32.DLL","RegCloseKey",hKey)
Error(ErrorInfo())
RETURN
END
// Close opened key
API("ADVAPI32.DLL","RegCloseKey",hKey)
---------------------------------------------------------------------- 3) Comment gérer un IDLE Démarrer un thread avec le code suivant:
PROCEDURE IdleProc(peMaxMilliSecs=5000, pbRestart=False)
LASTINPUTINFO is structure
cbSize is unsigned int
dwTime is int
END
lii is LASTINPUTINFO
lii:cbSize=Dimension(lii)
LOOP
IF NOT API("USER32","GetLastInputInfo", &lii) THEN
Error(ErrorInfo())
RETURN
END
currTicks is int=API("KERNEL32","GetTickCount")
lastInputTicks is int=lii:dwTime
idleTicks is int= currTicks - lastInputTicks
Trace("Current Tick="+currTicks+" | Last Input Tick="+lastInputTicks+" | Difference="+idleTicks)
IF idleTicks>=peMaxMilliSecs THEN
Info("Yo I'm In IDLE Mode !")
IF NOT pbRestart THEN
BREAK
END
END
API("KERNEL32","Sleep",1000) // Ou ThreadAttendSignal(x)...
END
Contribution le : 29/05/2005 11:54
|