Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can I get the progress bar to start at the beginning and slowy increment as the program downloads from the ftp source..?????? its going crazy like filling 1 million times..but it does stop when its done downloading.....


here is my code
C++
void CSimpleftpclientDlg::OnButton4() 
{


int index;
         CString strText;
         index = m_dir.GetCurSel();

         m_dir.GetText(index,strText);
        

	
		 HINTERNET handle1 = FtpOpenFile(hIConnect,strText,GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,0);
		DWORD filesized =  FtpGetFileSize(handle1,NULL);
		CString csNumber;
csNumber.Format("%lu", filesized);

MessageBox(csNumber,csNumber,MB_OK);
HANDLE hFile    = CreateFile(strText, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
char Buffer[4024];
  DWORD dwRead =0;
 
  



  while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
  {
    if ( dwRead == 0) 
      break;
    DWORD dwWrite = 0;
	progress2 += dwRead;
	
	
	m_yay.StepIt();

    WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
  }





}



please help

[edit]Code block added, SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 3-Jul-13 20:14pm
v3
Comments
OriginalGriff 4-Jul-13 2:14am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

use the PostMessage API. Post a user defined message to your window/dialog. There you handle it and set the value.

Maybe you should use PostThreadMessage somehow like that:

PostThreadMessage Demystified[^]
 
Share this answer
 
bool m_signed =false; // peoplewant25jan@yahoo.com if you need help , welcome
static DWORD WINAPI DownThread(LPVOID pParameter)//CHTTPDownlogTestDlg
{
CDownloadZipDlg* pThis = (CDownloadZipDlg *)pParameter;
HINTERNET session = NULL;
HINTERNET connect = NULL;
HINTERNET http = NULL;
TCHAR url[MAX_PATH] = {0};
TCHAR server[MAX_PATH] = {0};
TCHAR file[MAX_PATH] = {0};
TCHAR name[MAX_PATH] = _T("C:\\MyDownLog\\");
BYTE lpReadeBuffer[1024 * 8] = {0};
TCHAR header[8] = {0};
TCHAR lpLength[20] = _T("Îļþ´óС:");
DWORD dwTimeout = 15000;
DWORD dwReq = 0;
DWORD dwBufferLength = 500;
DWORD dwIndex = 0;
CString str;
TCHAR *p;

pThis->GetDlgItemText(IDC_EDIT1, url, MAX_PATH);
if(_tcslen(url) < 7)
goto theEnd;
_tcsncpy(header, url, 7);
if(_tcsicmp(header, _T("http://")) != 0)
goto theEnd;
_tcscpy(server, url + 7);
p = _tcschr(server, '/');
if(NULL != p)
{
*p = '\0';
_tcscat(name, _tcsrchr(url, '/') + 1);
}
_tcscpy(file, url + _tcslen(server) + 8);

session = InternetOpen(_T("Mozilla/4.0 (compatible)"), INTERNET_OPEN_TYPE_DIRECT , NULL, NULL, 0);
if(NULL == session)
{
AfxMessageBox(_T("´´½¨»á»°Ê§°Ü"));
goto theEnd;
}
connect = InternetConnect(session, server, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(NULL == connect)
{
AfxMessageBox(_T("½¨Á¢Á¬½Óʧ°Ü"));
goto theSession;
}
// CHAR* pAcceptTypes = "*/*";
http = HttpOpenRequest(connect, "GET", file, _T("HTTP/1.1"), NULL,/* (LPCSTR *)&pAcceptTypes*/NULL, INTERNET_FLAG_RELOAD, 0);
if(NULL == http)
{
AfxMessageBox(_T("ÇëÇó»á»°Ê§°Ü"));
goto theConnect;
}
if( HttpSendRequest(http, NULL, 0, NULL, 0) )
{
//dwBufferLength = 4;//// InternetGetLastResponseInfo
http://www.dreamincode.net/forums/topic/101532-download-file-from-url/
if( !HttpQueryInfo(http, HTTP_QUERY_CONTENT_LENGTH,// | HTTP_QUERY_FLAG_NUMBER,
&lpReadeBuffer, &dwBufferLength, NULL)) //dwBufferLengthÒ»¶¨ÒªÓгõʼ´óС
{
AfxMessageBox(_T("»ñÈ¡Îļþ´óСʧ°Ü"));
goto theHttp;
}
pThis->m_progress.SetRange(0, 100);
DWORD allLength = atol((char*)lpReadeBuffer);
memset(header, 0, sizeof(TCHAR) * 8);
_itot(allLength, header, 10);
_tcscat(lpLength, header);
_tcscat(lpLength, "Bit");
pThis->SetDlgItemText(IDC_STATIC_L, lpLength);

FILE *ffile = fopen(name, "wb+");
if(NULL == ffile)
{
AfxMessageBox(_T("´´½¨Îļþʧ°Ü"));
goto theHttp;
}
do{
InternetReadFile(http, lpReadeBuffer, 1024 * 8, &dwBufferLength);
dwReq += dwBufferLength;
if(dwBufferLength > 0)
fwrite(lpReadeBuffer, 1, dwBufferLength, ffile);
int i = (int)((float)dwReq / (float)allLength * (float)100);
pThis->m_progress.SetPos(i);
//Sleep(100);
}while(dwBufferLength > 0);
fclose(ffile);

}

str.Format(_T("ÏÂÔØÍê³É:%s"), name);
AfxMessageBox(str);


theHttp:
InternetCloseHandle(http);
theConnect:
InternetCloseHandle(connect);
theSession:
InternetCloseHandle(session);
theEnd:
pThis->m_signed = false;
return 0;
}

void CSimpleftpclientDlg::OnButton1()
{
if(false == m_signed)
{
m_signed = true;
HANDLE handle = CreateThread(NULL, 0, DownThread, (LPVOID)this, 0, NULL);
CloseHandle(handle);
}
else
{
AfxMessageBox(_T("ÏÂÔؽø³ÌÕýÔÚÔËÐÐ"));
}

}
 
Share this answer
 
Comments
King Fisher 31-Mar-15 13:39pm    
you have solved 2 year Old question .
i found this question by search in Google
then
it will help other if anybody came here by same way

anyway thank u
i m new to code project
 
Share this answer
 
Comments
CHill60 9-Apr-15 16:52pm    
If you want to comment on a post it is best to use the "Have a Question or Comment?" link next to a post rather than posting a solution. As you can see - you will just get downvotes.
Member 11570547 10-Apr-15 2:57am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900