查询是否有数据下载
//TIMER
case WM_TIMER:
{
int i = 0;
timeval tv ;
int ret = 0;
int len = 0;
fd_set reads ;
__int64 llNum = 0;
char * lpData = NULL;
char szRecv[1024] = "";
char szText[MAX_PATH]= "";
// Initialize the use of the Windows CE Internet functions.
if (g_bProxy)
{
hOpen = InternetOpen (TEXT("CeHttp"), INTERNET_OPEN_TYPE_PROXY,
lpszProxyServer, 0, 0);
}
else
{
hOpen = InternetOpen (TEXT("CeHttp"), INTERNET_OPEN_TYPE_PRECONFIG,
NULL, 0, 0);
}
if (g_bOpenURL)
{
if (!(hRequest = InternetOpenUrl (hOpen, lpszServer, NULL, 0,
INTERNET_FLAG_RELOAD, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("InternetOpenUrl Error"),
GetLastError());
goto exit;
}
}
else
{
// Open an HTTP session for a specified site by using lpszServer.
if (!(hConnect = InternetConnect (hOpen,
lpszServer,
INTERNET_INVALID_PORT_NUMBER,
NULL, NULL,
INTERNET_SERVICE_HTTP,
0, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("InternetConnect Error"),
GetLastError());
goto exit;
}
// Open an HTTP request handle.
if (!(hRequest = HttpOpenRequest (hConnect,
TEXT("GET"),
NULL,
HTTP_VERSION,
NULL,
(LPCTSTR*)AcceptTypes,
dwFlags, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("HttpOpenRequest Error"),
GetLastError());
goto exit;
}
// Send a request to the HTTP server.
if (!HttpSendRequest (hRequest, NULL, 0, NULL, 0))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("HttpSendRequest Error"),
GetLastError());
goto exit;
}
}
// Call HttpQueryInfo to find out the size of the headers.
HttpQueryInfo (hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &dwSize,
NULL);
// Allocate a block of memory for lpHeadersA.
lpHeadersA = new CHAR [dwSize];
// Call HttpQueryInfo again to get the headers.
if (!HttpQueryInfo (hRequest,
HTTP_QUERY_RAW_HEADERS_CRLF,
(LPVOID) lpHeadersA, &dwSize, NULL))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("HttpQueryInfo"),
GetLastError());
goto exit;
}
else
{
// Clear all of the existing text in the edit control and prepare
// to put the new information in it.
SendMessage (g_hwndEdit, EM_SETSEL, 0, -1);
SendMessage (g_hwndEdit, WM_CLEAR, 0, 0);
SendMessage (g_hwndEdit, WM_PAINT, TRUE, 0);
}
// Terminate headers with NULL.
lpHeadersA [dwSize] = '\0';
// Get the required size of the buffer that receives the Unicode
// string.
dwSize = MultiByteToWideChar (CP_ACP, 0, lpHeadersA, -1, NULL, 0);
// Allocate a block of memory for lpHeadersW.
lpHeadersW = new TCHAR [dwSize];
// Convert headers from ASCII to Unicode
MultiByteToWideChar (CP_ACP, 0, lpHeadersA, -1, lpHeadersW, dwSize);
// Put the headers in the edit control.
SendMessage (g_hwndMain, WM_PUTTEXT, NULL, (LPARAM) lpHeadersW);
// Free the blocks of memory.
delete[] lpHeadersA;
delete[] lpHeadersW;
// Allocate a block of memory for lpHeadersW.
lpBufferA = new CHAR [32000];
do
{
if (!InternetReadFile (hRequest, (LPVOID)lpBufferA, 32000, &dwSize))
{
wsprintf(szErrMsg, TEXT("%s: %x"), TEXT("InternetReadFile Error"),
GetLastError());
goto exit;
}
if (dwSize != 0)
{
// Terminate headers with NULL.
lpBufferA [dwSize] = '\0';
// Get the required size of the buffer which receives the Unicode
// string.
dwSize = MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, NULL, 0);
// Allocate a block of memory for lpBufferW.
lpBufferW = new TCHAR [dwSize];
// Convert the buffer from ASCII to Unicode.
MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, lpBufferW, dwSize);
// Put the buffer in the edit control.
SendMessage (g_hwndMain, WM_PUTTEXT, NULL, (LPARAM) lpBufferW);
// Free the block of memory.
delete[] lpBufferW;
}
} while (dwSize);
// Free the block of memory.
delete[] lpBufferA;
bReturn = TRUE;
exit:
// Close the Internet handles.
if (hOpen)
{
if (!InternetCloseHandle (hOpen))
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("CloseHandle Error"),
GetLastError());
}
if (hConnect)
{
if (!InternetCloseHandle (hConnect))
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("CloseHandle Error"),
GetLastError());
}
if (hRequest)
{
if (!InternetCloseHandle (hRequest))
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("CloseHandle Error"),
GetLastError());
}