Click here to Skip to main content
15,881,588 members
Articles / Desktop Programming / MFC
Article

CHttpDownloadDlg v1.03

Rate me:
Please Sign up or sign in to vote.
4.81/5 (18 votes)
3 Mar 2000 215.5K   5.7K   97   51
A dialog implementation that performs HTTP downloads.
  • Download source files - 42 Kb
  • Sample Image - DownloadDlg.gif

    Introduction

    Welcome to CHttpDownloadDlg, an MFC dialog which performs HTTP downloads similar to the Internet Explorer download dialog as shown above.


    History
    Usage
    Contacting the Author


    History

    V1.0 (14 November 1999)
    • First public release.

    V1.01 (15 November 1999)

    • Updated documentation to refer to what rc resources are needed by the class.
    • Renamed all resources used from ASYNC_DOWLOAD to include HTTPDOWNLOAD.
    • Now handles HTTP error 407 (Proxy Authentication) and HTTP error 401 (Server Authentication). You are prompted with a password dialog when either of these forms of authentication are required.
    • Sample program now allows you to specify the URL to download from as well as the file to download into and the username and password to connect with.
    • The download file is now deleted if the download was aborted or if some other error occurs during the download.
    • Parsing of URL will now work where "http://" is not explicitely specified.
    • Improved the general look and feel of the demo app and called it "HTML File Downloader".

    V1.02 (29 November 1999)

    • Fixed a number of compiler warnings and errors when used in VC++ 6.0.

    V1.03 (25 January 2000)

    • Fixed a problem where server authentication was not being detected correctly, while proxy authentication was being handled.
    • Updated the way and periodicity certain UI controls are updated during the HTTP download.


    Usage

    To use CHttpDownloadDlg in your project simply include HttpDownloadDlg.cpp/.h from the test application in your application and #include "HttpDownloadDlg.h" in whichever files you want to use the class in. To bring up the dialog to download a specific file, just use some code like the following:

    CHttpDownloadDlg dlg;
    dlg.m_sURLToDownload = _T("http://www.some-site.com/somefile.ext");
    dlg.m_sFileToDownloadInto = _T("c:\\somfile.ext");
    if (dlg.DoModal() == IDOK)
       AfxMessageBox("File was downloaded successfully");

    You should also have a look at the CInetDownloadDlg::OnDownload() code in the sample application.


    Contacting the Author

    PJ Naughter
    Email: pjn@indigo..ie
    Web: http://www.naughter.com
    25 January 2000


    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralMy vote of 4 Pin
    minsikchu8-Sep-10 15:02
    minsikchu8-Sep-10 15:02 
    QuestionHow to copy the res? Pin
    rootdial5-Apr-06 8:42
    rootdial5-Apr-06 8:42 
    Generaltoo many errors Pin
    petri11123-Oct-04 7:17
    petri11123-Oct-04 7:17 
    GeneralRe: too many errors Pin
    pjnaughter23-Oct-04 10:50
    pjnaughter23-Oct-04 10:50 
    GeneralRe: too many errors Pin
    petri11128-Oct-04 18:22
    petri11128-Oct-04 18:22 
    GeneralRe: too many errors Pin
    pjnaughter29-Oct-04 1:06
    pjnaughter29-Oct-04 1:06 
    GeneralRe: too many errors Pin
    KarstenK13-Jul-05 23:11
    mveKarstenK13-Jul-05 23:11 
    GeneralRe: too many errors Pin
    pjnaughter14-Jul-05 0:12
    pjnaughter14-Jul-05 0:12 
    QuestionHow to upload a file to a HTTP server? Pin
    MaTrIX2k216-May-04 12:32
    MaTrIX2k216-May-04 12:32 
    AnswerRe: How to upload a file to a HTTP server? Pin
    pjnaughter17-May-04 0:14
    pjnaughter17-May-04 0:14 
    Question102 error(s), 5 warning(s) What's wrong?? Pin
    Locura6668-Mar-04 16:26
    Locura6668-Mar-04 16:26 
    the demo file run perfect, but....

    when i've tried to create a new workspace, and attach the two files(via "project->add to proyect-> files" mentioned on the .htm , and everything goes wrong. why is happening this? Confused | :confused:

    i'm using Visual C++ 6.0 and the source downloaded from your site (v1.07)

    hope you can help me

    here's the error list




    --------------------Configuration: Download - Win32 Debug--------------------
    Compiling resources...
    Compiling...
    StdAfx.cpp
    Compiling...
    Download.cpp
    DownloadDlg.cpp
    HttpDownloadDlg.cpp
    C:\Download\httpdownloaddlg.h(61) : error C2065: 'IDD_HTTPDOWNLOAD' : undeclared identifier
    C:\Download\httpdownloaddlg.h(61) : error C2057: expected constant expression
    C:\Download\httpdownloaddlg.h(86) : error C2061: syntax error : identifier 'HINTERNET'
    C:\Download\httpdownloaddlg.h(88) : error C2061: syntax error : identifier 'HINTERNET'
    C:\Download\httpdownloaddlg.h(89) : error C2061: syntax error : identifier 'HINTERNET'
    C:\Download\httpdownloaddlg.h(90) : error C2061: syntax error : identifier 'HINTERNET'
    C:\Download\httpdownloaddlg.h(91) : error C2061: syntax error : identifier 'HINTERNET'
    C:\Download\httpdownloaddlg.h(114) : error C2146: syntax error : missing ';' before identifier 'm_nPort'
    C:\Download\httpdownloaddlg.h(114) : error C2501: 'INTERNET_PORT' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(114) : error C2501: 'm_nPort' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(115) : error C2146: syntax error : missing ';' before identifier 'm_hInternetSession'
    C:\Download\httpdownloaddlg.h(115) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(115) : error C2501: 'm_hInternetSession' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(116) : error C2146: syntax error : missing ';' before identifier 'm_hHttpConnection'
    C:\Download\httpdownloaddlg.h(116) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(116) : error C2501: 'm_hHttpConnection' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(117) : error C2146: syntax error : missing ';' before identifier 'm_hHttpFile'
    C:\Download\httpdownloaddlg.h(117) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
    C:\Download\httpdownloaddlg.h(117) : error C2501: 'm_hHttpFile' : missing storage-class or type specifiers
    To avoid this message, please put afxpriv.h in your PCH (normally stdafx.h)
    C:\Download\HttpDownloadDlg.cpp(139) : error C2065: 'm_hInternetSession' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(140) : error C2065: 'm_hHttpConnection' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(141) : error C2065: 'm_hHttpFile' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(158) : error C2065: 'IDC_STATUS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(159) : error C2065: 'IDC_TRANSFER_RATE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(160) : error C2065: 'IDC_TIMELEFT' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(161) : error C2065: 'IDC_PROGRESS1' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(162) : error C2065: 'IDC_FILESTATUS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(163) : error C2065: 'IDC_ANIMATE1' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(204) : error C2065: 'IDR_HTTPDOWNLOAD_ANIMATION' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(208) : error C2065: 'AfxParseURL' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(208) : error C2065: 'm_nPort' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(228) : error C2065: 'IDS_HTTPDOWNLOAD_OK_TO_OVERWRITE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(249) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_FILE_OPEN' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(268) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_FILE_SEEK' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(289) : error C2065: 'IDS_HTTPDOWNLOAD_FILESTATUS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(325) : error C2065: 'IDS_HTTPDOWNLOAD_PERCENTAGE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(336) : error C2065: 'IDS_HTTPDOWNLOAD_BYTES' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(342) : error C2065: 'IDS_HTTPDOWNLOAD_KILOBYTES' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(348) : error C2065: 'IDS_HTTPDOWNLOAD_MEGABYTES' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(372) : error C2065: 'IDS_HTTPDOWNLOAD_OF' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(379) : error C2065: 'IDS_HTTPDOWNLOAD_SECONDS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(390) : error C2065: 'IDS_HTTPDOWNLOAD_MINUTES' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(392) : error C2065: 'IDS_HTTPDOWNLOAD_MINUTES_AND_SECONDS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(396) : error C2065: 'IDS_HTTPDOWNLOAD_TIMELEFT' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(426) : error C2065: 'IDS_HTTPDOWNLOAD_BYTESPERSECOND' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(432) : error C2065: 'IDS_HTTPDOWNLOAD_KILOBYTESPERSECOND' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(479) : error C2065: 'HINTERNET' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(479) : error C2146: syntax error : missing ')' before identifier 'hInternet'
    C:\Download\HttpDownloadDlg.cpp(479) : error C2350: 'CHttpDownloadDlg::QueryStatusNumber' is not a static member
    C:\Download\HttpDownloadDlg.cpp(479) : error C2059: syntax error : ')'
    C:\Download\HttpDownloadDlg.cpp(480) : error C2143: syntax error : missing ';' before '{'
    C:\Download\HttpDownloadDlg.cpp(480) : error C2447: missing function header (old-style formal list?)
    C:\Download\HttpDownloadDlg.cpp(486) : error C2146: syntax error : missing ')' before identifier 'hInternet'
    C:\Download\HttpDownloadDlg.cpp(486) : error C2350: 'CHttpDownloadDlg::QueryStatusCode' is not a static member
    C:\Download\HttpDownloadDlg.cpp(486) : error C2059: syntax error : ')'
    C:\Download\HttpDownloadDlg.cpp(487) : error C2143: syntax error : missing ';' before '{'
    C:\Download\HttpDownloadDlg.cpp(487) : error C2447: missing function header (old-style formal list?)
    C:\Download\HttpDownloadDlg.cpp(491) : error C2146: syntax error : missing ')' before identifier 'hInternet'
    C:\Download\HttpDownloadDlg.cpp(491) : error C2350: 'CHttpDownloadDlg::QueryContentLength' is not a static member
    C:\Download\HttpDownloadDlg.cpp(491) : error C2059: syntax error : ')'
    C:\Download\HttpDownloadDlg.cpp(492) : error C2143: syntax error : missing ';' before '{'
    C:\Download\HttpDownloadDlg.cpp(492) : error C2447: missing function header (old-style formal list?)
    C:\Download\HttpDownloadDlg.cpp(505) : error C2039: 'InternetOpen' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(505) : error C2065: 'InternetOpen' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(505) : error C2065: 'INTERNET_OPEN_TYPE_PRECONFIG' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(510) : error C2065: 'INTERNET_OPEN_TYPE_DIRECT' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(516) : error C2065: 'INTERNET_OPEN_TYPE_PROXY' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(529) : error C2065: 'IDS_HTTPDOWNLOAD_GENERIC_ERROR' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(541) : error C2039: 'InternetSetStatusCallback' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(541) : error C2065: 'InternetSetStatusCallback' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(541) : error C2065: 'INTERNET_INVALID_STATUS_CALLBACK' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(558) : error C2039: 'InternetConnect' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(558) : error C2065: 'InternetConnect' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(559) : error C2065: 'INTERNET_SERVICE_HTTP' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(566) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_RELOAD' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_DONT_CACHE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_KEEP_CONNECTION' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(593) : error C2065: 'AFX_INET_SERVICE_HTTPS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(593) : warning C4018: '==' : signed/unsigned mismatch
    C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_SECURE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_IGNORE_CERT_CN_INVALID' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_IGNORE_CERT_DATE_INVALID' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(595) : error C2065: 'HttpOpenRequest' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(620) : error C2039: 'HttpSendRequest' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(620) : error C2065: 'HttpSendRequest' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(635) : error C2065: 'IDS_HTTPDOWNLOAD_INVALID_SERVER_RESPONSE' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(641) : error C2065: 'HTTP_STATUS_PROXY_AUTH_REQ' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(641) : warning C4018: '==' : signed/unsigned mismatch
    C:\Download\HttpDownloadDlg.cpp(641) : error C2065: 'HTTP_STATUS_DENIED' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(641) : warning C4018: '==' : signed/unsigned mismatch
    C:\Download\HttpDownloadDlg.cpp(649) : error C2039: 'InternetReadFile' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(649) : error C2065: 'InternetReadFile' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(654) : warning C4018: '==' : signed/unsigned mismatch
    C:\Download\HttpDownloadDlg.cpp(660) : error C2065: 'InternetSetOption' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(668) : warning C4018: '==' : signed/unsigned mismatch
    C:\Download\HttpDownloadDlg.cpp(674) : error C2065: 'INTERNET_OPTION_USERNAME' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(676) : error C2065: 'INTERNET_OPTION_PASSWORD' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(684) : error C2039: 'InternetErrorDlg' : is not a member of '`global namespace''
    C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'InternetErrorDlg' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'ERROR_INTERNET_INCORRECT_PASSWORD' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'FLAGS_ERROR_UI_FILTER_FOR_ERRORS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'FLAGS_ERROR_UI_FLAGS_GENERATE_DATA' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'ERROR_INTERNET_FORCE_RETRY' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(688) : error C2065: 'HTTP_STATUS_OK' : undeclared identifier
    C:\Download\HttpDownloadDlg.cpp(688) : fatal error C1003: error count exceeds 100; stopping compilation
    Generating Code...
    Error executing cl.exe.

    Download.exe - 102 error(s), 5 warning
    AnswerRe: 102 error(s), 5 warning(s) What's wrong?? Pin
    pjnaughter17-May-04 0:18
    pjnaughter17-May-04 0:18 
    QuestionHow to ignore global offline mode? Pin
    Ralfy3-Mar-04 17:25
    Ralfy3-Mar-04 17:25 
    GeneralLots and Lots of Errors when compiling Pin
    shultas11-Feb-04 17:04
    shultas11-Feb-04 17:04 
    GeneralRe: Lots and Lots of Errors when compiling Pin
    pjnaughter11-Feb-04 21:30
    pjnaughter11-Feb-04 21:30 
    GeneralRe: Lots and Lots of Errors when compiling Pin
    shultas12-Feb-04 5:46
    shultas12-Feb-04 5:46 
    GeneralRe: Lots and Lots of Errors when compiling Pin
    pjnaughter12-Feb-04 6:01
    pjnaughter12-Feb-04 6:01 
    GeneralCompile shouts: unresolved symbols Pin
    HintiFlo22-Jan-04 10:27
    HintiFlo22-Jan-04 10:27 
    GeneralRe: Compile shouts: unresolved symbols Pin
    pjnaughter22-Jan-04 11:36
    pjnaughter22-Jan-04 11:36 
    GeneralRe: Compile shouts: unresolved symbols Pin
    HintiFlo22-Jan-04 22:24
    HintiFlo22-Jan-04 22:24 
    GeneralRe: Compile shouts: unresolved symbols Pin
    HintiFlo23-Jan-04 2:24
    HintiFlo23-Jan-04 2:24 
    GeneralATL downloading Pin
    Balkrishna Talele6-Jan-04 19:16
    Balkrishna Talele6-Jan-04 19:16 
    GeneralRe: ATL downloading Pin
    pjnaughter7-Jan-04 2:46
    pjnaughter7-Jan-04 2:46 
    GeneralBinary downloads Pin
    Chris Losinger14-Dec-03 16:59
    professionalChris Losinger14-Dec-03 16:59 
    GeneralRe: Binary downloads Pin
    pjnaughter14-Dec-03 22:49
    pjnaughter14-Dec-03 22:49 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.