-
July 3rd, 2013, 10:30 PM
#1
ftp file size
My question is...can this be fixed to work right??????????????????
Code:
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;
m_yay.SetRange(0,filesized);
while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
{
if ( dwRead == 0)
break;
DWORD dwWrite = 0;
progress2 += dwRead;
m_yay.SetPos(progress2);
WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
}
that code above is for a FTP CLIENT using WININET. the code is getting a file from the server and downloading...it works, but the progress bar is not working right....like it fills to fast...sometimes it doesn't even move...so can you help me with this problem
Last edited by vaas; July 3rd, 2013 at 11:25 PM.
-
July 4th, 2013, 12:29 AM
#2
Re: ftp file size
MY question is....why does the progress bar go crazy..filling like 10000 times..instead of starting from the beginning and slowing incrementing ot the end....
I used StepIt instead of setpos and its almost working...
[code]
the progress bar goes crazy..it goes all the way about 1 million times....
Last edited by vaas; July 4th, 2013 at 12:49 AM.
-
July 4th, 2013, 02:26 AM
#3
Re: ftp file size
m_yay.SetRange(0,filesized);
Please read carefully about PBM_SETRANGE message
Best regards,
Igor
-
July 4th, 2013, 03:29 AM
#4
Re: ftp file size
alright.. I fixed
Code:
m_yay.SetRange(0,100);
And also..here isi the code that I edited..but still the progress is going crazy. Should I put the "StepIt" function in a while loop? Or maybe chop it up and put it in a FOR LOOP?
Code:
while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
{
if ( dwRead == 0)
break;
DWORD dwWrite = 0;
WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
m_yay.StepIt();
}
-
July 4th, 2013, 04:49 AM
#5
Re: ftp file size
Originally Posted by vaas
alright.. I fixed
Code:
m_yay.SetRange(0,100);
What did you fixed?
Originally Posted by vaas
And also..here isi the code that I edited..but still the progress is going crazy. Should I put the "StepIt" function in a while loop? Or maybe chop it up and put it in a FOR LOOP?
Code:
while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
{
if ( dwRead == 0)
break;
DWORD dwWrite = 0;
WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
m_yay.StepIt();
}
Why do you use StepIt()? Did you call SetStep() before?
Perhaps, you'll get back to reading MSDN documentation about CProgressCtrl and its methods?
Victor Nijegorodov
-
July 4th, 2013, 07:38 AM
#6
Re: ftp file size
Well, probably it must be something like:
Code:
while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
{
if ( dwRead == 0)
break;
DWORD dwWrite = 0;
progress2 += dwRead;
UINT progressPercent = DOUBLE(progress2) * 100 / filesized + 0.5;
m_yay.SetPos(progressPercent);
WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
}
Best regards,
Igor
-
July 5th, 2013, 04:16 PM
#7
Re: ftp file size
Cool..i got it work with Igor Vartanov code
here is the code
Code:
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);
GetDlgItem(IDC_EDIT4)->SetWindowText(csNumber);
HANDLE hFile = CreateFile(strText, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
char Buffer[4024];
DWORD dwRead =0;
m_yay.SetRange(0,100);
while(InternetReadFile(handle1, Buffer, sizeof(Buffer), &dwRead) == TRUE)
{
if ( dwRead == 0)
break;
DWORD dwWrite = 0;
progress2 += dwRead;
UpdateData(true);
CString what = m_what;
UpdateData(false);
DWORD dwNO;
dwNO= atol((char*)(LPCTSTR)what);
UINT progressPercent = DOUBLE(progress2) * 100 / dwNO;
m_yay.SetPos(progressPercent);
WriteFile(hFile, Buffer, dwRead, &dwWrite, NULL);
}
}
thx
Last edited by terryeverlast; July 5th, 2013 at 04:17 PM.
Reason: messed up
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|