आप CallNtPowerInformation
एपीआई समारोह है कि निम्नलिखित पैरामीटर लेता है कॉल करने के लिए चाहते हो सकता है:
NTSTATUS WINAPI CallNtPowerInformation(
_In_ POWER_INFORMATION_LEVEL InformationLevel,
_In_ PVOID lpInputBuffer,
_In_ ULONG nInputBufferSize,
_Out_ PVOID lpOutputBuffer,
_In_ ULONG nOutputBufferSize
);
InformationLevel
paramer आप SystemPowerInformation
enum मूल्य है कि एक साथ lpOutputBuffer
भरता पारित में SYSTEM_POWER_INFORMATION
संरचना:
typedef struct _SYSTEM_POWER_INFORMATION {
ULONG MaxIdlenessAllowed;
ULONG Idleness;
ULONG TimeRemaining;
UCHAR CoolingMode;
} SYSTEM_POWER_INFORMATION, *PSYSTEM_POWER_INFORMATION;
फिर TimeRemaining
, जो सेकंड में व्यक्त किया जाता है मिलता है।
संपादित करें: वीबी.नेट में परीक्षण किया गया। संपादित करें: कोड जोड़ा गया।
Queryer.vb
Imports System.Runtime.InteropServices
Public Class Queryer
Const SystemPowerInformation As Integer = 12
Const STATUS_SUCCESS As Integer = 0
Private Structure SYSTEM_POWER_INFORMATION
Public MaxIdlenessAllowed As UInteger
Public Idleness As UInteger
Public TimeRemaining As Integer
Public CoolingMode As Byte
End Structure
<DllImport("PowrProf.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function CallNtPowerInformation(
ByVal InformationLevel As Int32,
ByVal lpInputBuffer As IntPtr,
ByVal nInputBufferSize As UInt32,
ByVal lpOutputBuffer As IntPtr,
ByRef nOutputBufferSize As UInt32) As UInt32
End Function
Public Function Query() As Integer
Dim PowerInformation As SYSTEM_POWER_INFORMATION
Dim Status As IntPtr = IntPtr.Zero
Dim ReturnValue As UInteger
Try
Status = Marshal.AllocCoTaskMem(Marshal.SizeOf(GetType(SYSTEM_POWER_INFORMATION)))
ReturnValue = CallNtPowerInformation(SystemPowerInformation, Nothing, 0, Status, Marshal.SizeOf(GetType(SYSTEM_POWER_INFORMATION)))
PowerInformation = Marshal.PtrToStructure(Status, GetType(SYSTEM_POWER_INFORMATION))
Catch ex As Exception
Return 0
Finally
Marshal.FreeCoTaskMem(Status)
End Try
Return PowerInformation.TimeRemaining
End Function
End Class
प्रपत्र:
Public Class Form1
Public Sub Loader() Handles Me.Load
Dim rolex As New Timer()
rolex.Interval = 500
AddHandler rolex.Tick, AddressOf TimerScattato
rolex.Start()
End Sub
Private Sub TimerScattato()
Dim secondi As Integer = q.Query()
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(secondi)
lblTimeLeft.Text = String.Format("{0,2}:{1,2}:{2,2}", iSpan.Hours, iSpan.Minutes, iSpan.Seconds)
End Sub
Private q As New Queryer
End Class
[? क्या आप की कोशिश की है] (http://mattgemmell.com/what-have-you-tried/) – Drop
मैं एक प्रारंभ बिंदु के लिए हर जगह खोज रहा हूं, और इस तरह कोई सवाल भी नहीं मिला। तो, मेरे पास कोई कोड नहीं है। –
https://msdn.microsoft.com/en-us/library/windows/desktop/aa373217%28v=vs.85%29.aspx –