battery level
battery level
.......................
Dernière modification par Backup le sam. 19/mars/2011 16:43, modifié 1 fois.
-
- Messages : 579
- Inscription : ven. 11/mai/2007 15:21
Dobro, je m'incline respectueusement devant la gloire et la splendeur de tes talents de codeur (l33t coding skillz!).
Voilà un p'tit code bien utile, et qui fonctionne parfaitement sur mon portable. Respect.
Je m'en vais de ce pas t'ériger un petit autel dans un coin de ma maison, devant lequel je déposerai quotidiennement des offrandes (barres Mars, ananas, bouteilles de bière, etc.). Si, si, tu le mérites...
Voilà un p'tit code bien utile, et qui fonctionne parfaitement sur mon portable. Respect.
Je m'en vais de ce pas t'ériger un petit autel dans un coin de ma maison, devant lequel je déposerai quotidiennement des offrandes (barres Mars, ananas, bouteilles de bière, etc.). Si, si, tu le mérites...
Juste l'ajout d'un petit graphe en direct pour la décharge (très mal codé à cause des variables globales).
PS: pour PureBasic 4.20, j'ai ajouté la ligne
Promis, je vais télécharger Purebasic 4.30

PS: pour PureBasic 4.20, j'ai ajouté la ligne
Code : Tout sélectionner
If CreateGadgetList(WindowID(0))

Code : Tout sélectionner
Global LastTime
Global LastState
Global OldX, OldY
Procedure Refresh(timeout)
#NUM_DISCHARGE_POLICIES = 4
Enumeration
#level
#text1
#text2
#text3
#image1
EndEnumeration
;
Structure POWER_ACTION_POLICY
action.l
flags.l
EventCode.l
EndStructure
Structure SYSTEM_POWER_LEVEL
Enable.b
Spare.b[3]
BatteryLevel.l
powerpolicy.POWER_ACTION_POLICY
MinSystemState.l
EndStructure
Structure GLOBAL_MACHINE_POWER_POLICY
Revision.l
LidOpenWakeAc.l
LidOpenWakeDc.l
BroadcastCapacityResolution.l
EndStructure
Structure GLOBAL_USER_POWER_POLICY
Revision.l
PowerButtonAc.POWER_ACTION_POLICY
PowerButtonDc.POWER_ACTION_POLICY
SleepButtonAc.POWER_ACTION_POLICY
SleepButtonDc.POWER_ACTION_POLICY
LidCloseAc.POWER_ACTION_POLICY
LidCloseDc.POWER_ACTION_POLICY
DischargePolicy.SYSTEM_POWER_LEVEL[#NUM_DISCHARGE_POLICIES]
GlobalFlags.l
EndStructure
Structure GLOBAL_POWER_POLICY
user.GLOBAL_USER_POWER_POLICY
mach.GLOBAL_MACHINE_POWER_POLICY
EndStructure
Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure
;
Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure
Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure
*PP.POWER_POLICY
Repeat
powerpolicyglobal.GLOBAL_POWER_POLICY
powerpolicy.POWER_POLICY
syspowerstat.SYSTEM_POWER_STATUS
If GetSystemPowerStatus_(syspowerstat)
Select syspowerstat\ACLineStatus
Case 0
SetGadgetText(#text1,"You are currently on Battery Power")
If LastState = 1
LastTime = ElapsedMilliseconds()
OldY = syspowerstat\BatteryLifePercent
OldX = (ElapsedMilliseconds()-LastTime)/30000
EndIf
If LastState = 0
y= syspowerstat\BatteryLifePercent
x= (ElapsedMilliseconds()-LastTime)/30000
StartDrawing(ImageOutput(#image1))
LineXY(oldX*1.2+10, (100-OldY)*2+1, x*1.2+10, (100-y)*2+1,RGB(255,255,0))
; Circle(x*1.2+10,(100-a)*2+1,1, RGB(255,255,0))
StopDrawing()
SetGadgetState(#image1,ImageID(#image1))
Debug Str((ElapsedMilliseconds()-LastTime)/60000)
oldY=y
oldX=x
EndIf
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(200,0,0))
LastState=0
Case 1
SetGadgetText(#text1,"You are currently on AC Power")
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,0,200))
LastState=1
EndSelect
SetGadgetText(#text2,Str(syspowerstat\BatteryLifePercent)+"%")
SetGadgetState(#level,syspowerstat\BatteryLifePercent)
Select syspowerstat\BatteryFlag
Case 1
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(0,0,0))
Case 2
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,127,0))
Case 4
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,0,0))
EndSelect
EndIf
Delay(5000)
ForEver
EndProcedure
If OpenWindow(0,0,0,285,290,"Power Meter",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
hwnd = WindowID(0)
hdc = GetDC_(hwnd)
Rimg = CreateImage(#image1, 250, 210)
StartDrawing(ImageOutput(#image1))
For t=0 To 100 Step 10
LineXY(t*2.4+10,0,t*2.4+10,200,RGB(0,127,0))
LineXY(10,t*2+1,240,t*2+1,RGB(0,127,0))
Next t
StopDrawing()
LastState = 1
TextGadget(#text1,20,20,270,20,"",#PB_Text_Center)
TextGadget(#text2,1,5,30,20,"",#PB_Text_Center)
TextGadget(#text3,20,260,260,20,"By Dobro and Golfy (Purebasic)",#PB_Text_Center)
ProgressBarGadget(#level, 5, 25, 15, 257, 0,100,#PB_ProgressBar_Vertical)
ImageGadget(#image1,27, 40, 240,200, Rimg, #PB_Image_Border)
CreateThread(@Refresh(),timeout)
Repeat
Event = WindowEvent()
Select Event
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
Purebasic 5.30 full sous Windows XP (x86) et Win7 (64 bits), Linux Debian. Orientation réseaux, domotique
http://golfy.olympe.in/Teo-Tea/
http://golfy.olympe.in/Teo-Tea/
Petite contribution pour ce soft sympa,
Après le code les liens vers les icônes (zip) et un exécutable.
Code PB4.31
Aspect sous Vista:

Télécharger les icônes ici : Icônes battery
Télécharger l'exe ici : PortablebatteryLevel.exe
@+
Après le code les liens vers les icônes (zip) et un exécutable.
Code PB4.31
Code : Tout sélectionner
Global LastTime
Global LastState
Global OldX, OldY
Global ImageBatt
ImageBatt = CatchImage(0, ?ImageBatt)
DataSection
ImageBatt : IncludeBinary "..\Battery.ico" ;64x64
EndDataSection
Procedure Refresh(timeout)
#NUM_DISCHARGE_POLICIES = 4
Enumeration
#image0
#text1
#level
#image1
#ContainerPercent
#text2
#text3
EndEnumeration
;
Structure POWER_ACTION_POLICY
action.l
flags.l
EventCode.l
EndStructure
Structure SYSTEM_POWER_LEVEL
Enable.b
Spare.b[3]
BatteryLevel.l
powerpolicy.POWER_ACTION_POLICY
MinSystemState.l
EndStructure
Structure GLOBAL_MACHINE_POWER_POLICY
Revision.l
LidOpenWakeAc.l
LidOpenWakeDc.l
BroadcastCapacityResolution.l
EndStructure
Structure GLOBAL_USER_POWER_POLICY
Revision.l
PowerButtonAc.POWER_ACTION_POLICY
PowerButtonDc.POWER_ACTION_POLICY
SleepButtonAc.POWER_ACTION_POLICY
SleepButtonDc.POWER_ACTION_POLICY
LidCloseAc.POWER_ACTION_POLICY
LidCloseDc.POWER_ACTION_POLICY
DischargePolicy.SYSTEM_POWER_LEVEL[#NUM_DISCHARGE_POLICIES]
GlobalFlags.l
EndStructure
Structure GLOBAL_POWER_POLICY
user.GLOBAL_USER_POWER_POLICY
mach.GLOBAL_MACHINE_POWER_POLICY
EndStructure
Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure
;
Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure
Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure
*PP.POWER_POLICY
Repeat
powerpolicyglobal.GLOBAL_POWER_POLICY
powerpolicy.POWER_POLICY
syspowerstat.SYSTEM_POWER_STATUS
If GetSystemPowerStatus_(syspowerstat)
Select syspowerstat\ACLineStatus
Case 0
SetGadgetText(#text1,"Vous êtes branché sur la batterie");"You are currently on Battery Power")
If LastState = 1
LastTime = ElapsedMilliseconds()
OldY = syspowerstat\BatteryLifePercent
OldX = (ElapsedMilliseconds()-LastTime)/30000
EndIf
If LastState = 0
y= syspowerstat\BatteryLifePercent
x= (ElapsedMilliseconds()-LastTime)/30000
StartDrawing(ImageOutput(#image1))
LineXY(oldX*1.2+10, (100-OldY)*2+1, x*1.2+10, (100-y)*2+1,RGB(255,255,0))
; Circle(x*1.2+10,(100-a)*2+1,1, RGB(255,255,0))
StopDrawing()
SetGadgetState(#image1,ImageID(#image1))
Debug Str((ElapsedMilliseconds()-LastTime)/60000)
oldY=y
oldX=x
EndIf
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(200,0,0))
LastState=0
Case 1
SetGadgetText(#text1,"Vous êtes branché sur le secteur");"You are currently on AC Power")
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,0,200))
LastState=1
EndSelect
SetGadgetText(#text2,Str(syspowerstat\BatteryLifePercent)+"%")
SetGadgetState(#level,syspowerstat\BatteryLifePercent)
Select syspowerstat\BatteryFlag
Case 1
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(70, 212, 185))
Case 2
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,127,0))
Case 4
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,0,0))
EndSelect
EndIf
Delay(5000)
ForEver
EndProcedure
If OpenWindow(0,0,0,350,310,"Power Meter",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,RGB(0,0,0))
hwnd = WindowID(0)
hdc = GetDC_(hwnd)
Rimg = CreateImage(#image1, 250, 210)
StartDrawing(ImageOutput(#image1))
For t=0 To 100 Step 10
LineXY(t*2.4+10,0,t*2.4+10,200,RGB(0,127,0))
LineXY(10,t*2+1,240,t*2+1,RGB(0,127,0))
Next t
StopDrawing()
LastState = 1
ImageGadget(#image0,5,10,64,64, ImageBatt)
TextGadget(#text1,80,20,300,20,"")
SetGadgetColor(#text1,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text1,#PB_Gadget_FrontColor,RGB(255,255,255))
ProgressBarGadget(#level, 10, 75, 60, 225, 0,100,#PB_ProgressBar_Vertical)
ImageGadget(#image1,80, 40, 240,200, Rimg, #PB_Image_Border)
ContainerGadget(#ContainerPercent, 80,255,255,45,#PB_Container_Single)
SetGadgetColor(#ContainerPercent,#PB_Gadget_BackColor,RGB(0,0,0))
TextGadget(#text2,5,2,220,20,"",#PB_Text_Center)
SetGadgetColor(#text2,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text3,5,25,220,15,"By Dobro and Golfy and Jacobus (Purebasic)",#PB_Text_Center)
SetGadgetColor(#text3,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text3,#PB_Gadget_FrontColor,RGB(255,255,255))
CloseGadgetList()
CreateThread(@Refresh(),timeout)
Repeat
Event = WindowEvent() ;WaitWindowEvent()
Select Event
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Télécharger les icônes ici : Icônes battery
Télécharger l'exe ici : PortablebatteryLevel.exe
@+
Dernière modification par Jacobus le mar. 21/juil./2009 20:07, modifié 1 fois.
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
Génial Jacobus !
J'adore l'icône... pour la barre verticale, même idée !
sauf que je viens d'ajouter 2 fonctions sympa : estimation de temps restant et estimation de temps total (à un pourcentage précis)...
http://www.zimagez.com/zimage/powermeter.php
Je te mets tout de même le nouveau code, si tu as le temps de le compiler.
Ce qui serait sympa de notre part (Dobro, toi et moi) serait de placer une url sur ce topic dans le programme et de le mettre en freeware sur Anshare ou autre... pour ma part, je suis pour les freewares (open-source ou non) et vous ?????
[/url]

J'adore l'icône... pour la barre verticale, même idée !
sauf que je viens d'ajouter 2 fonctions sympa : estimation de temps restant et estimation de temps total (à un pourcentage précis)...
http://www.zimagez.com/zimage/powermeter.php
Je te mets tout de même le nouveau code, si tu as le temps de le compiler.
Ce qui serait sympa de notre part (Dobro, toi et moi) serait de placer une url sur ce topic dans le programme et de le mettre en freeware sur Anshare ou autre... pour ma part, je suis pour les freewares (open-source ou non) et vous ?????
Code : Tout sélectionner
Global LastTime
Global LastState
Global FirstY, OldX, OldY, OldYY
Global TMinute, Estimation
Procedure Refresh(timeout)
#NUM_DISCHARGE_POLICIES = 4
Enumeration
#level
#text1
#text2
#text3
#text4
#text5
#text6
#image1
EndEnumeration
;
Structure POWER_ACTION_POLICY
action.l
flags.l
EventCode.l
EndStructure
Structure SYSTEM_POWER_LEVEL
Enable.b
Spare.b[3]
BatteryLevel.l
powerpolicy.POWER_ACTION_POLICY
MinSystemState.l
EndStructure
Structure GLOBAL_MACHINE_POWER_POLICY
Revision.l
LidOpenWakeAc.l
LidOpenWakeDc.l
BroadcastCapacityResolution.l
EndStructure
Structure GLOBAL_USER_POWER_POLICY
Revision.l
PowerButtonAc.POWER_ACTION_POLICY
PowerButtonDc.POWER_ACTION_POLICY
SleepButtonAc.POWER_ACTION_POLICY
SleepButtonDc.POWER_ACTION_POLICY
LidCloseAc.POWER_ACTION_POLICY
LidCloseDc.POWER_ACTION_POLICY
DischargePolicy.SYSTEM_POWER_LEVEL[#NUM_DISCHARGE_POLICIES]
GlobalFlags.l
EndStructure
Structure GLOBAL_POWER_POLICY
user.GLOBAL_USER_POWER_POLICY
mach.GLOBAL_MACHINE_POWER_POLICY
EndStructure
Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure
;
Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure
Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure
*PP.POWER_POLICY
Repeat
powerpolicyglobal.GLOBAL_POWER_POLICY
powerpolicy.POWER_POLICY
syspowerstat.SYSTEM_POWER_STATUS
If GetSystemPowerStatus_(syspowerstat)
Select syspowerstat\ACLineStatus
Case 0
SetGadgetText(#text1,"You are currently on Battery Power")
If LastState = 1
LastTime = ElapsedMilliseconds()
OldY = syspowerstat\BatteryLifePercent
OldX = (ElapsedMilliseconds()-LastTime)/30000
OldYY = OldY
FirstY = OldY
Tminute = 0
SetGadgetText(#text4,"Estimated Remain Time : (calculating)")
SetGadgetText(#text5,"Activity on Battery since : (calculating)")
EndIf
If LastState = 0
y= syspowerstat\BatteryLifePercent
x= (ElapsedMilliseconds()-LastTime)/30000
StartDrawing(ImageOutput(#image1))
LineXY(oldX*1.2+10, (100-OldY)*2+1, x*1.2+10, (100-y)*2+1,RGB(255,255,0))
StopDrawing()
SetGadgetState(#image1,ImageID(#image1))
Debug Str(x)+" - "+Str(Tminute)+" =2 ?"
If x - Tminute >= 2
Tminute = (ElapsedMilliseconds()-LastTime)/30000
If OldYY - Y <> 0
Estimation = y/(OldYY - y)
OldYY = y
SetGadgetText(#text4,"Estimated Remain Time : "+Str(Estimation)+" mn")
Else
OldYY = y
SetGadgetText(#text4,"Estimated Remain Time : -- mn")
EndIf
SetGadgetText(#text5,"Activity on Battery since : "+Str(Tminute/2)+" mn")
SetGadgetColor(#text3, #PB_Gadget_FrontColor, RGB(70,70,70))
SetGadgetText(#text3,"At "+Str(FirstY)+"% battery would be "+Str(Tminute/2+Estimation)+" mn longer.")
EndIf
oldY=y
oldX=x
EndIf
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(200,0,0))
LastState=0
Case 1
SetGadgetText(#text1,"You are currently on AC Power")
SetGadgetText(#text4,"")
SetGadgetText(#text5,"")
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,0,200))
LastState=1
EndSelect
SetGadgetText(#text2,Str(syspowerstat\BatteryLifePercent)+"%")
SetGadgetState(#level,syspowerstat\BatteryLifePercent)
Select syspowerstat\BatteryFlag
Case 1
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(0,0,0))
Case 2
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,127,0))
Case 4
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,0,0))
EndSelect
EndIf
Delay(5000)
ForEver
EndProcedure
If OpenWindow(0,0,0,285,300,"Power Meter",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
hwnd = WindowID(0)
hdc = GetDC_(hwnd)
Rimg = CreateImage(#image1, 250, 210)
StartDrawing(ImageOutput(#image1))
For t=0 To 100 Step 10
LineXY(t*2.4+10,0,t*2.4+10,200,RGB(0,127,0))
LineXY(10,t*2+1,240,t*2+1,RGB(0,127,0))
Next t
StopDrawing()
LastState = 1
TextGadget(#text1,20,5,270,16,"",#PB_Text_Center)
TextGadget(#text2,1,20,30,16,"",#PB_Text_Center)
TextGadget(#text4,30,20,210,16,"",#PB_Text_Center)
TextGadget(#text5,30,35,210,16,"",#PB_Text_Center)
ProgressBarGadget(#level, 3, 52, 20, 215, 0,100,#PB_ProgressBar_Vertical)
ImageGadget(#image1,27, 55, 240,200, Rimg, #PB_Image_Border)
TextGadget(#text3,25,270,260,15,"",#PB_Text_Center)
TextGadget(#text6,25,285,260,15,"By Dobro and Golfy (Purebasic)",#PB_Text_Center)
CreateThread(@Refresh(),timeout)
Repeat
Event = WindowEvent()
Select Event
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
Purebasic 5.30 full sous Windows XP (x86) et Win7 (64 bits), Linux Debian. Orientation réseaux, domotique
http://golfy.olympe.in/Teo-Tea/
http://golfy.olympe.in/Teo-Tea/
Une petite dernière avec modifs de Golfy. J'ai préféré traduire en français
Les icônes sont au même endroit et l'exe aussi, un lien direct sur ce topic inclus dans le prog.
Télécharger les icônes ici : Icônes battery
Télécharger l'exe ici : PortablebatteryLevel.exe
PB 4.31
Les icônes sont au même endroit et l'exe aussi, un lien direct sur ce topic inclus dans le prog.
Télécharger les icônes ici : Icônes battery
Télécharger l'exe ici : PortablebatteryLevel.exe
PB 4.31
Code : Tout sélectionner
Global LastTime
Global LastState
Global FirstY, OldX, OldY, OldYY
Global TMinute, Estimation
Global ImageBatt
ImageBatt = CatchImage(0, ?ImageBatt)
DataSection
ImageBatt : IncludeBinary "..\Battery.ico" ;64x64
EndDataSection
Procedure Refresh(timeout)
#NUM_DISCHARGE_POLICIES = 4
Enumeration
#image0
#ContainerPercent
#level
#text1
#text2
#text3
#text4
#text5
#HyperLinkForum
#image1
EndEnumeration
Structure POWER_ACTION_POLICY
action.l
flags.l
EventCode.l
EndStructure
Structure SYSTEM_POWER_LEVEL
Enable.b
Spare.b[3]
BatteryLevel.l
powerpolicy.POWER_ACTION_POLICY
MinSystemState.l
EndStructure
Structure GLOBAL_MACHINE_POWER_POLICY
Revision.l
LidOpenWakeAc.l
LidOpenWakeDc.l
BroadcastCapacityResolution.l
EndStructure
Structure GLOBAL_USER_POWER_POLICY
Revision.l
PowerButtonAc.POWER_ACTION_POLICY
PowerButtonDc.POWER_ACTION_POLICY
SleepButtonAc.POWER_ACTION_POLICY
SleepButtonDc.POWER_ACTION_POLICY
LidCloseAc.POWER_ACTION_POLICY
LidCloseDc.POWER_ACTION_POLICY
DischargePolicy.SYSTEM_POWER_LEVEL[#NUM_DISCHARGE_POLICIES]
GlobalFlags.l
EndStructure
Structure GLOBAL_POWER_POLICY
user.GLOBAL_USER_POWER_POLICY
mach.GLOBAL_MACHINE_POWER_POLICY
EndStructure
Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure
;
Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure
Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure
*PP.POWER_POLICY
Repeat
powerpolicyglobal.GLOBAL_POWER_POLICY
powerpolicy.POWER_POLICY
syspowerstat.SYSTEM_POWER_STATUS
If GetSystemPowerStatus_(syspowerstat)
Select syspowerstat\ACLineStatus
Case 0
SetGadgetText(#text1,"Vous êtes branché sur la batterie")
If LastState = 1
LastTime = ElapsedMilliseconds()
OldY = syspowerstat\BatteryLifePercent
OldX = (ElapsedMilliseconds()-LastTime)/30000
OldYY = OldY
FirstY = OldY
Tminute = 0
SetGadgetText(#text4,"Temps restant estimé : (calcul)")
SetGadgetText(#text5,"Activité sur batterie depuis : (calcul)")
EndIf
If LastState = 0
y= syspowerstat\BatteryLifePercent
x= (ElapsedMilliseconds()-LastTime)/30000
StartDrawing(ImageOutput(#image1))
LineXY(oldX*1.2+10, (100-OldY)*2+1, x*1.2+10, (100-y)*2+1,RGB(255,255,0))
StopDrawing()
SetGadgetState(#image1,ImageID(#image1))
Debug Str(x)+" - "+Str(Tminute)+" =2 ?"
If x - Tminute >= 2
Tminute = (ElapsedMilliseconds()-LastTime)/30000
If OldYY - Y <> 0
Estimation = y/(OldYY - y)
OldYY = y
SetGadgetText(#text4,"Temps restant estimé : "+Str(Estimation)+" mn")
Else
OldYY = y
SetGadgetText(#text4,"Temps restant estimé : -- mn")
EndIf
SetGadgetText(#text5,"Activité sur batterie depuis : "+Str(Tminute/2)+" mn")
SetGadgetColor(#text3, #PB_Gadget_FrontColor, RGB(70,70,70))
SetGadgetText(#text3,"A "+Str(FirstY)+"% la batterie ne durera plus que "+Str(Tminute/2+Estimation)+" mn.")
EndIf
oldY=y
oldX=x
EndIf
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(200,0,0))
LastState=0
Case 1
SetGadgetText(#text1,"Vous êtes branché sur le secteur")
SetGadgetText(#text4,"")
SetGadgetText(#text5,"")
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,0,200))
LastState=1
EndSelect
SetGadgetText(#text2,Str(syspowerstat\BatteryLifePercent)+"%")
SetGadgetState(#level,syspowerstat\BatteryLifePercent)
Select syspowerstat\BatteryFlag
Case 1
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(32, 199, 223))
Case 2
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,127,0))
Case 4
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,0,0))
EndSelect
EndIf
Delay(5000)
ForEver
EndProcedure
If OpenWindow(0,0,0,350,350,"Power Meter",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,RGB(0,0,0))
hwnd = WindowID(0)
hdc = GetDC_(hwnd)
Rimg = CreateImage(#image1, 250, 210)
StartDrawing(ImageOutput(#image1))
For t=0 To 100 Step 10
LineXY(t*2.4+10,0,t*2.4+10,200,RGB(0,127,0))
LineXY(10,t*2+1,240,t*2+1,RGB(0,127,0))
Next t
StopDrawing()
LastState = 1
ImageGadget(#image0,5,10,64,64, ImageBatt)
TextGadget(#text1,80,20,300,20,"")
SetGadgetColor(#text1,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text1,#PB_Gadget_FrontColor,RGB(255,255,255))
ProgressBarGadget(#level, 10, 75, 60, 265, 0,100,#PB_ProgressBar_Vertical)
ImageGadget(#image1,80, 40, 240,200, Rimg, #PB_Image_Border)
ContainerGadget(#ContainerPercent, 80,255,255,85,#PB_Container_Single)
SetGadgetColor(#ContainerPercent,#PB_Gadget_BackColor,RGB(0,0,0))
TextGadget(#text2,5,2,30,15,"",#PB_Text_Center)
SetGadgetColor(#text2,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text4,35,2,210,15,"",#PB_Text_Center)
SetGadgetColor(#text4,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text4,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text5,5,17,210,15,"",#PB_Text_Center)
SetGadgetColor(#text5,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text5,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text3,5,32,245,15,"",#PB_Text_Center)
SetGadgetColor(#text3,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text3,#PB_Gadget_FrontColor,RGB(255,255,255))
HyperLinkGadget(#HyperLinkForum,20,60,220,15,"By Dobro and Golfy and Jacobus (Purebasic)",RGB(230, 40, 25) ,#PB_HyperLink_Underline)
SetGadgetColor(#HyperLinkForum,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#HyperLinkForum,#PB_Gadget_FrontColor,RGB(255,255,255))
CloseGadgetList()
CreateThread(@Refresh(),timeout)
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #HyperLinkForum :RunProgram("http://www.purebasic.fr/french/viewtopic.php?t=9444")
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
EndIf
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
C'est génial !
Merci Dobro, merci Jacobus !
(l'union fait la force et l'oignon fait la farce...)

Merci Dobro, merci Jacobus !
(l'union fait la force et l'oignon fait la farce...)
Purebasic 5.30 full sous Windows XP (x86) et Win7 (64 bits), Linux Debian. Orientation réseaux, domotique
http://golfy.olympe.in/Teo-Tea/
http://golfy.olympe.in/Teo-Tea/
Ligne 165
; Couleur visible (bleu ciel)
au lieu de
La couleur bleu foncé sur noir c'est pas top.. vaut mieux opter pour un bleu ciel RGB(0,200,200)
Code : Tout sélectionner
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,200,200))
au lieu de
Code : Tout sélectionner
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,0,200))
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Nouvelle version pour Vista en ajoutant le mode Aero, fond spécial transparent, qui donne un air plus fun au soft.
Une tite photo pour les XPsiens

l'exécutable tout prêt ici >> Téléchargement
Le code ( PB 4.31 )
@+
Une tite photo pour les XPsiens
l'exécutable tout prêt ici >> Téléchargement
Le code ( PB 4.31 )
Code : Tout sélectionner
Global LastTime
Global LastState
Global FirstY, OldX, OldY, OldYY
Global TMinute, Estimation
Global ImageBatt
ImageBatt = CatchImage(0, ?ImageBatt)
DataSection
ImageBatt : IncludeBinary "..\Battery.ico" ;64x64
EndDataSection
;---------------------------------
;-AERO / VISTA ONLY
;---------------------------------
;{ Code du forum EN
Structure DWM_BLURBEHIND
dwFlags.l
fEnable.l
hRgnBlur.l
fTransitionOnMaximized.l
EndStructure
#DWM_BB_ENABLE = 1
#DWM_BB_BLURREGION = 2
#DWM_BB_TRANSITIONONMAXIMIZED = 4
Global DWMLib = LoadLibrary_("dwmapi.dll")
Global UseAeroShader.i = #False
Procedure EnableBlurBehindWindow(hWnd.i, benable.b, iregion.i, btransitionOnMaximized.b)
If DWMLib
blurBehind.DWM_BLURBEHIND
blurBehind\dwFlags = #DWM_BB_ENABLE | #DWM_BB_TRANSITIONONMAXIMIZED
blurBehind\fEnable = benable
blurBehind\fTransitionOnMaximized = btransitionOnMaximized
If DWMLib
If (benable And 0) <> iregion
blurBehind\dwFlags = #DWM_BB_BLURREGION
blurBehind\hRgnBlur = iregion
EndIf
*pAfunc = GetProcAddress_(DWMLib, "DwmEnableBlurBehindWindow")
If *pAfunc
CallFunctionFast(*pAfunc, hWnd, @blurBehind)
EndIf
EndIf
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure IsCompositionEnabled()
result.l = #False
If DWMLib
*pAfunc = GetProcAddress_(DWMLib, "DwmIsCompositionEnabled")
If *pAfunc
CallFunctionFast(*pAfunc, @result)
EndIf
EndIf
ProcedureReturn result
EndProcedure
UseAeroShader = IsCompositionEnabled()
;}
Procedure Refresh(timeout)
#NUM_DISCHARGE_POLICIES = 4
Enumeration
#image0
#ContainerPercent
#level
#text1
#text2
#text3
#text4
#text5
#HyperLinkForum
#image1
EndEnumeration
Structure POWER_ACTION_POLICY
action.l
flags.l
EventCode.l
EndStructure
Structure SYSTEM_POWER_LEVEL
Enable.b
Spare.b[3]
BatteryLevel.l
powerpolicy.POWER_ACTION_POLICY
MinSystemState.l
EndStructure
Structure GLOBAL_MACHINE_POWER_POLICY
Revision.l
LidOpenWakeAc.l
LidOpenWakeDc.l
BroadcastCapacityResolution.l
EndStructure
Structure GLOBAL_USER_POWER_POLICY
Revision.l
PowerButtonAc.POWER_ACTION_POLICY
PowerButtonDc.POWER_ACTION_POLICY
SleepButtonAc.POWER_ACTION_POLICY
SleepButtonDc.POWER_ACTION_POLICY
LidCloseAc.POWER_ACTION_POLICY
LidCloseDc.POWER_ACTION_POLICY
DischargePolicy.SYSTEM_POWER_LEVEL[#NUM_DISCHARGE_POLICIES]
GlobalFlags.l
EndStructure
Structure GLOBAL_POWER_POLICY
user.GLOBAL_USER_POWER_POLICY
mach.GLOBAL_MACHINE_POWER_POLICY
EndStructure
Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure
;
Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure
Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure
*PP.POWER_POLICY
Repeat
powerpolicyglobal.GLOBAL_POWER_POLICY
powerpolicy.POWER_POLICY
syspowerstat.SYSTEM_POWER_STATUS
If GetSystemPowerStatus_(syspowerstat)
Select syspowerstat\ACLineStatus
Case 0
SetGadgetText(#text1,"Vous êtes branché sur la batterie")
If LastState = 1
LastTime = ElapsedMilliseconds()
OldY = syspowerstat\BatteryLifePercent
OldX = (ElapsedMilliseconds()-LastTime)/30000
OldYY = OldY
FirstY = OldY
Tminute = 0
SetGadgetText(#text4,"Temps restant estimé : (calcul)")
SetGadgetText(#text5,"Activité sur batterie depuis : (calcul)")
EndIf
If LastState = 0
y= syspowerstat\BatteryLifePercent
x= (ElapsedMilliseconds()-LastTime)/30000
StartDrawing(ImageOutput(#image1))
LineXY(oldX*1.2+10, (100-OldY)*2+1, x*1.2+10, (100-y)*2+1,RGB(255,255,0))
StopDrawing()
SetGadgetState(#image1,ImageID(#image1))
Debug Str(x)+" - "+Str(Tminute)+" =2 ?"
If x - Tminute >= 2
Tminute = (ElapsedMilliseconds()-LastTime)/30000
If OldYY - Y <> 0
Estimation = y/(OldYY - y)
OldYY = y
SetGadgetText(#text4,"Temps restant estimé : "+Str(Estimation)+" mn")
Else
OldYY = y
SetGadgetText(#text4,"Temps restant estimé : -- mn")
EndIf
SetGadgetText(#text5,"Activité sur batterie depuis : "+Str(Tminute/2)+" mn")
SetGadgetColor(#text3, #PB_Gadget_FrontColor, RGB(70,70,70))
SetGadgetText(#text3,"A "+Str(FirstY)+"% la batterie ne durera plus que "+Str(Tminute/2+Estimation)+" mn.")
EndIf
oldY=y
oldX=x
EndIf
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(200,0,0))
LastState=0
Case 1
SetGadgetText(#text1,"Vous êtes branché sur le secteur")
SetGadgetText(#text4,"")
SetGadgetText(#text5,"")
SetGadgetColor(#text1, #PB_Gadget_FrontColor, RGB(0,200,200))
LastState=1
EndSelect
SetGadgetText(#text2,Str(syspowerstat\BatteryLifePercent)+"%")
SetGadgetState(#level,syspowerstat\BatteryLifePercent)
Select syspowerstat\BatteryFlag
Case 1
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(32, 199, 223))
Case 2
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,127,0))
Case 4
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(200,0,0))
EndSelect
EndIf
Delay(5000)
ForEver
EndProcedure
If OpenWindow(0,0,0,350,350,"Power Meter",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered);{
SetWindowColor(0,RGB(0,0,0))
hwnd = WindowID(0)
hdc = GetDC_(hwnd)
Rimg = CreateImage(#image1, 250, 210)
StartDrawing(ImageOutput(#image1))
For t=0 To 100 Step 10
LineXY(t*2.4+10,0,t*2.4+10,200,RGB(0,127,0))
LineXY(10,t*2+1,240,t*2+1,RGB(0,127,0))
Next t
StopDrawing()
LastState = 1
ImageGadget(#image0,5,10,64,64, ImageBatt)
TextGadget(#text1,80,20,300,20,"")
SetGadgetColor(#text1,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text1,#PB_Gadget_FrontColor,RGB(255,255,255))
ProgressBarGadget(#level, 10, 75, 60, 265, 0,100,#PB_ProgressBar_Vertical)
ImageGadget(#image1,80, 40, 240,200, Rimg, #PB_Image_Border)
ContainerGadget(#ContainerPercent, 80,255,255,85,#PB_Container_Single)
SetGadgetColor(#ContainerPercent,#PB_Gadget_BackColor,RGB(0,0,0))
TextGadget(#text2,5,2,30,15,"",#PB_Text_Center)
SetGadgetColor(#text2,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text2,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text4,35,2,210,15,"",#PB_Text_Center)
SetGadgetColor(#text4,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text4,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text5,5,17,210,15,"",#PB_Text_Center)
SetGadgetColor(#text5,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text5,#PB_Gadget_FrontColor,RGB(255,255,255))
TextGadget(#text3,5,32,245,15,"",#PB_Text_Center)
SetGadgetColor(#text3,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#text3,#PB_Gadget_FrontColor,RGB(255,255,255))
HyperLinkGadget(#HyperLinkForum,20,60,220,15,"By Dobro and Golfy and Jacobus (Purebasic)",RGB(230, 40, 25) ,#PB_HyperLink_Underline)
SetGadgetColor(#HyperLinkForum,#PB_Gadget_BackColor,RGB(0,0,0))
SetGadgetColor(#HyperLinkForum,#PB_Gadget_FrontColor,RGB(255,255,255))
CloseGadgetList()
;}
CreateThread(@Refresh(),timeout)
;-ACTIVATION MODE AERO
If UseAeroShader
EnableBlurBehindWindow(WindowID(0), 1, 0, 1)
EndIf
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #HyperLinkForum :RunProgram("http://www.purebasic.fr/french/viewtopic.php?t=9444")
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
EndIf
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.