スレッドの開始時間を取得          <TOP>


GetThreadTimes 指定されたスレッドのタイミングを取得

FileTimeToLocalFileTime 世界協定時刻形式ファイル時間をローカルファイル時間に変換

FileTimeToSystemTime ファイルタイムをシステムタイムに変換

GetCurrentProcess 現在のプロセスに対応する疑似ハンドルを取得

 

 

'================================================================
'= スレッドの開始時間を取得
'= WindowsNT3.1以降
'================================================================
#include "Windows.bi"

Type FILETIME
    dwLowDateTime  As Long
    dwHighDateTime As Long
End Type

Type SYSTEMTIME
    wYear         As Integer
    wMonth        As Integer
    wDayOfWeek    As Integer
    wDay          As Integer
    wHour         As Integer
    wMinute       As Integer
    wSecond       As Integer
    wMilliseconds As Integer
End Type

' 指定されたスレッドのタイミング情報を取得
Declare Function Api_GetThreadTimes& Lib "kernel32" Alias "GetThreadTimes" (ByVal hThread&, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME)

' 世界協定時刻形式ファイル時間をローカルファイル時間に変換
Declare Function Api_FileTimeToLocalFileTime& Lib "kernel32" Alias "FileTimeToLocalFileTime" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME)

' ファイルタイムをシステムファイルに変換
Declare Function Api_FileTimeToSystemTime& Lib "kernel32" Alias "FileTimeToSystemTime" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME)

' カレントスレッドの擬似ハンドルを取得
Declare Function Api_GetCurrentThread& Lib "kernel32" Alias "GetCurrentThread" ()

Var Shared Text1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Var FT0 As FILETIME
    Var FT1 As FILETIME
    Var ST As SYSTEMTIME
    Var txt As String
    Var Ret As Long

    Ret = Api_GetThreadTimes(Api_GetCurrentThread, FT1, FT0, FT0, FT0)
    Ret = Api_FileTimeToLocalFileTime(FT1, FT1)
    Ret = Api_FileTimeToSystemTime(FT1, ST)

    txt = txt & "このスレッドは、" & Chr$(13, 10)
    txt = txt & Trim$(Str$(ST.wYear)) & "/" & Right$(Str$(100 + ST.wMonth), 2) & "/" & Right$(Str$(100 + ST.wDay), 2) & Chr$(13, 10)
    txt = txt & Right$(Str$(100 + ST.wHour), 2) & ":" & Right$(Str$(100 + ST.wMinute), 2) & ":" & Right$(Str$(100 + ST.wSecond), 2) & Chr$(13, 10)
    txt = txt & "に開始されました!"
    Text1.SetWindowText txt
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End