Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'The InternetOpen, InternetOpenURL, InternetReadURL and InternetCloseHandle API
'are needed to perform the task.
DownloadInfo.URLPath = "http://www.garybeene.com/files/gbsnippets.msg"
DownloadInfo.hWndParent = CB.Hndl : DownloadInfo.wMsg = %WM_User + 1001
DownloadInfo.lpBuf = VarPTR(sBuffer) : DownloadInfo.BytesRead = 0
DownloadInfo.Result = 0 : DownloadInfo.@lpBuf = Space$(4096)
hInternetSession = InternetOpen("gbSnippets", %INTERNET_OPEN_TYPE_PRECONFIG, ByVal 0, ByVal 0, 0) 'open session
hFile = InternetOpenUrl(hInternetSession, DownloadInfo.URLPath, _ 'open URL
ByVal 0, ByVal 0, %INTERNET_FLAG_PRAGMA_NOCACHE Or _
%INTERNET_FLAG_NO_CACHE_WRITE Or %INTERNET_FLAG_RELOAD, 0)
HttpQueryInfo(ByVal hFile, %HTTP_QUERY_CONTENT_LENGTH, ByVal VarPTR(sBuffer), SizeOf(sBuffer), 0)
HttpQueryInfo(ByVal hFile, %HTTP_QUERY_LAST_MODIFIED, ByVal VarPTR(sBuffer), SizeOf(sBuffer), 0)
InternetCloseHandle hFile : InternetCloseHandle hInternetSession 'close branch and session
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "WinInet.Inc"
Type tagDownloadInfo
hWndParent As Dword
wMsg As Dword
URLPath As Asciiz * 128 ' Enough
Result As Long
BytesRead As Dword
lpBuf As String Ptr
End Type
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local DownloadInfo As tagDownloadInfo, sBuffer As Asciiz * 25000, x As Long
Local hInternetSession As Dword, hFile As Long, BytesRead As Dword
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = 100 Then
DownloadInfo.URLPath = "http://www.garybeene.com/files/gbsnippets.msg"
DownloadInfo.hWndParent = CB.Hndl : DownloadInfo.wMsg = %WM_User + 1001
DownloadInfo.lpBuf = VarPTR(sBuffer) : DownloadInfo.BytesRead = 0
DownloadInfo.Result = 0 : DownloadInfo.@lpBuf = Space$(4096)
hInternetSession = InternetOpen("gbSnippets", %INTERNET_OPEN_TYPE_PRECONFIG, ByVal 0, ByVal 0, 0) 'open session
hFile = InternetOpenUrl(hInternetSession, DownloadInfo.URLPath, _ 'open URL
ByVal 0, ByVal 0, %INTERNET_FLAG_PRAGMA_NOCACHE Or _
%INTERNET_FLAG_NO_CACHE_WRITE Or %INTERNET_FLAG_RELOAD, 0)
HttpQueryInfo(ByVal hFile, %HTTP_QUERY_CONTENT_LENGTH, ByVal VarPTR(sBuffer), SizeOf(sBuffer), 0)
MsgBox sBuffer
HttpQueryInfo(ByVal hFile, %HTTP_QUERY_LAST_MODIFIED, ByVal VarPTR(sBuffer), SizeOf(sBuffer), 0)
MsgBox sBuffer
InternetCloseHandle hFile : InternetCloseHandle hInternetSession 'close branch and session
End If
End Select
End Function
'gbs_00366
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm