Laptop batery status

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
13 posts Page 1 of 2
User avatar
alex6848
VIP - Donator
VIP - Donator
Posts: 201
Joined: Sat Jan 16, 2010 10:26 pm

Laptop batery status
alex6848
To make batery status checker first insert 1 lable :shock: that is all you need. Then insert the following code. cooll; ***This is the fixed working code***
Code: Select all
Imports System.Runtime.InteropServices


Public Class Form1
    Dim myManagedPower As New ManagedPower()

    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        'Set label to initial status
        Label1.Text = myManagedPower.ToString()
    End Sub

Public Class ManagedPower
    ' GetSystemPowerStatus() is the only unmanaged API called.
    Declare Auto Function GetSystemPowerStatus Lib "kernel32.dll" _
    Alias "GetSystemPowerStatus" (ByRef sps As SystemPowerStatus) As Boolean

    Public Overrides Function ToString() As String
        Dim text As String = ""
        Dim sysPowerStatus As SystemPowerStatus
        ' Get the power status of the system
        If ManagedPower.GetSystemPowerStatus(sysPowerStatus) Then
            ' Current power source - AC/DC
            Dim currentPowerStatus = sysPowerStatus.ACLineStatus
            text += "Power source: " + sysPowerStatus.ACLineStatus.ToString() + Environment.NewLine

            ' Current power status
            text += "Power status: "

            

            ' Check for unknown
            If sysPowerStatus.BatteryFlag = ManagedPower._BatteryFlag.Unknown Then
                text += "Unknown"

            Else
                ' Check if currently charging
                Dim fCharging = (ManagedPower._BatteryFlag.Charging = _
      (sysPowerStatus.BatteryFlag & ManagedPower._BatteryFlag.Charging))

                If fCharging Then
                    Dim currentChargingStatus = ManagedPower._BatteryFlag.Charging
                End If

                ' Print out power level
                ' If the power is not High, Low, or Critical, report it as "Medium".
                Dim currentPowerLevel As String
                If sysPowerStatus.BatteryFlag = 0 Then
                    currentPowerLevel = "Medium                             "
                Else
                    currentPowerLevel = sysPowerStatus.BatteryFlag.ToString()
                End If
                text += currentPowerLevel

                ' Print out charging status
                If fCharging Then
                    Dim currentChargingStatus = ManagedPower._BatteryFlag.Charging.ToString()
                    text += " (" + ManagedPower._BatteryFlag.Charging.ToString() + ") "
                End If
            End If

            ' Finally print the percentage of the battery life remaining.
            Dim currentBatteryPercentage = sysPowerStatus.BatteryLifePercent
            text += Environment.NewLine + "Battery life remaining is " + _
            sysPowerStatus.BatteryLifePercent.ToString() + "%"
        End If
        Return text
    End Function

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SystemPowerStatus
        Public ACLineStatus As _ACLineStatus
        Public BatteryFlag As _BatteryFlag
        Public BatteryLifePercent As Byte
        Public Reserved1 As Byte
        Public BatteryLifeTime As System.UInt32
        Public BatteryFullLifeTime As System.UInt32
    End Structure

    Public Enum _ACLineStatus As Byte
        Battery = 0
        AC = 1
        Unknown = 255
    End Enum

    <Flags()> _
    Public Enum _BatteryFlag As Byte
        High = 1
        Low = 2
        Critical = 4
        Charging = 8
        NoSystemBattery = 128
        Unknown = 255
    End Enum
    
End Class
Last edited by alex6848 on Mon Feb 01, 2010 11:05 pm, edited 1 time in total.
Free Facebook Page Likes - http://fbliker.tk/?ref=gillis
User avatar
RunarM
Hardcore Programmer
Hardcore Programmer
Posts: 508
Joined: Wed Nov 18, 2009 11:33 pm

Re: Laptop batery status
RunarM
Doesn't work =)
Just another day in my life.
http://www.codexvideos.com
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Laptop batery status
Usman55
I also doesn't works for me, any suggestions?
Image
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: Laptop batery status
Lewis
It dont work and theres a working one posted :D
Image
User avatar
alex6848
VIP - Donator
VIP - Donator
Posts: 201
Joined: Sat Jan 16, 2010 10:26 pm

Re: Laptop batery status
alex6848
Scroll up to the top of the page for the fixed & working code.
For some reason it only works in vs2010 beta2. :(
Free Facebook Page Likes - http://fbliker.tk/?ref=gillis
User avatar
Alex
Member
Member
Posts: 40
Joined: Mon Feb 01, 2010 8:17 pm

Re: Laptop batery status
Alex
Worked for me. Nice Job.
<?php

$wants_to_make_guide_today = true;
if($wants_to_make_guide_today == true){
make_guide();
}else{
sleep();
}
?>
User avatar
35000vr
Top Poster
Top Poster
Posts: 176
Joined: Sat Mar 06, 2010 5:09 pm

Re: Laptop batery status
35000vr
D= Does it work or not?
‼ <----- Copy it,it is together and if you backspace it it will both erase
☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"<-----Some Cool symbols.
♂<-----Boy Symbol :)
²ƽ<--------Mini 2 and 5!
ð<----Not sure what it is.
☺☻<-----Smiles
♪♫<----Music Notes
Others:ß┬ƒ○║■ã¿┼↑
User avatar
alex6848
VIP - Donator
VIP - Donator
Posts: 201
Joined: Sat Jan 16, 2010 10:26 pm

Re: Laptop batery status
alex6848
Try using vs 2010 beta2 sorry - it only seems to work in vs 2010 beta2
Free Facebook Page Likes - http://fbliker.tk/?ref=gillis
User avatar
Philipp
Member
Member
Posts: 28
Joined: Mon Apr 05, 2010 12:08 pm

Re: Laptop batery status
Philipp
It's not working *heul*
My Project: Indows Intersmart(Virtual OS in VB)
|-_______________| [3%]
User avatar
rashaahamed123
Just Registered
Just Registered
Posts: 4
Joined: Mon Oct 24, 2011 4:33 pm

Re: Laptop batery status
rashaahamed123
hey tnx man, it wrkd 4 me :)
13 posts Page 1 of 2
Return to “Tutorials”