Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_SetDateA = 500
%IDC_SetDateB = 501
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Set Date_Time",300,300,240,140, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_SetDateA,"Set Date_Time A", 50,25,140,25
Control Add Button, hDlg, %IDC_SetDateB,"Set Date_Time B", 50,60,140,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local SysTime As SystemTime
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_SetDateA
SetDateTimeA Exe.Path$ + "text.txt",1,1,2011,1,1,1 'm-d-y-h-m-s
Case %IDC_SetDateB
SysTime.wMonth = 2 : SysTime.wDay = 2 : SysTime.wYear = 2011 'm-d-y
SysTime.wHour = 2 : SysTime.wMinute = 2 : SysTime.wSecond = 2 'h-m-s
SetDateTimeB Exe.Path$ + "text.txt",SysTime
End Select
End Select
End Function
Sub SetDateTimeA(fName$, Month As Long, Day As Long, Year As Long, Hour As Long, Minute As Long, Second As Long)
Local hFile&, LocalTime, StampTime As FileTime, SysTime As SystemTime
SysTime.wYear = Year : SysTime.wMonth = Month : SysTime.wDay = Day
SysTime.wHour = Hour : SysTime.wMinute = Minute : SysTime.wSecond = Second
hFile& = CreateFile(ByCopy fName$, ByVal %GENERIC_READ Or %GENERIC_WRITE, _
ByVal 0, ByVal %NULL, ByVal %OPEN_ALWAYS, ByVal %FILE_ATTRIBUTE_NORMAL, ByVal %NULL) 'get handle
SystemTimeToFileTime SysTime, LocalTime 'Convert system date/time to file structure.
LocalFileTimeToFileTime LocalTime, StampTime 'Convert local FT to UTC (needed by SetFileTime)
SetFileTime ByVal hFile&, ByVal %NULL, ByVal %NULL, StampTime 'Set file time
CloseHandle hFile&
End Sub
Sub SetDateTimeB(fName$, SysTime As SystemTime)
Local hFile&, LocalTime, StampTime As FileTime
hFile& = CreateFile(ByCopy fName$, ByVal %GENERIC_READ Or %GENERIC_WRITE, _
ByVal 0, ByVal %NULL, ByVal %OPEN_ALWAYS, ByVal %FILE_ATTRIBUTE_NORMAL, ByVal %NULL) 'get handle
SystemTimeToFileTime SysTime, LocalTime 'Convert system date/time to file structure.
LocalFileTimeToFileTime LocalTime, StampTime 'Convert local FT to UTC (needed by SetFileTime)
SetFileTime ByVal hFile&, ByVal %NULL, ByVal %NULL, StampTime 'Set file time
CloseHandle hFile&
End Sub
'gbs_01104
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm