Click here to Skip to main content
15,919,341 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Enumerating Registry Subkeys c++ Pin
Richard MacCutchan15-Nov-11 22:09
mveRichard MacCutchan15-Nov-11 22:09 
AnswerRe: Enumerating Registry Subkeys c++ Pin
User 742933815-Nov-11 22:14
professionalUser 742933815-Nov-11 22:14 
GeneralRe: Enumerating Registry Subkeys c++ Pin
Richard MacCutchan15-Nov-11 23:55
mveRichard MacCutchan15-Nov-11 23:55 
Questionsimple static library linking to dll issue. Pin
Android Lava15-Nov-11 16:32
Android Lava15-Nov-11 16:32 
AnswerRe: simple static library linking to dll issue. Pin
Richard MacCutchan15-Nov-11 22:04
mveRichard MacCutchan15-Nov-11 22:04 
AnswerRe: simple static library linking to dll issue. Pin
Chuck O'Toole16-Nov-11 5:41
Chuck O'Toole16-Nov-11 5:41 
AnswerRe: simple static library linking to dll issue. Pin
jschell16-Nov-11 10:00
jschell16-Nov-11 10:00 
QuestionURLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 15:09
professionaljkirkerx15-Nov-11 15:09 
AnswerRe: URLDownloadToFile, Cancel Button Pin
Chuck O'Toole15-Nov-11 16:19
Chuck O'Toole15-Nov-11 16:19 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 16:32
professionaljkirkerx15-Nov-11 16:32 
AnswerRe: URLDownloadToFile, Cancel Button Pin
Chuck O'Toole15-Nov-11 17:01
Chuck O'Toole15-Nov-11 17:01 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx15-Nov-11 17:19
professionaljkirkerx15-Nov-11 17:19 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx16-Nov-11 11:01
professionaljkirkerx16-Nov-11 11:01 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep16-Nov-11 13:40
enhzflep16-Nov-11 13:40 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx17-Nov-11 6:15
professionaljkirkerx17-Nov-11 6:15 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep17-Nov-11 19:45
enhzflep17-Nov-11 19:45 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx18-Nov-11 6:33
professionaljkirkerx18-Nov-11 6:33 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep18-Nov-11 14:15
enhzflep18-Nov-11 14:15 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx18-Nov-11 17:05
professionaljkirkerx18-Nov-11 17:05 
AnswerRe: URLDownloadToFile, Cancel Button Pin
Chuck O'Toole18-Nov-11 17:25
Chuck O'Toole18-Nov-11 17:25 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx18-Nov-11 18:02
professionaljkirkerx18-Nov-11 18:02 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep18-Nov-11 20:28
enhzflep18-Nov-11 20:28 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx19-Nov-11 7:15
professionaljkirkerx19-Nov-11 7:15 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep19-Nov-11 15:00
enhzflep19-Nov-11 15:00 
jkirkerx wrote:
I should be able to get the loop to ask the window if cancel has been invoked.

I'm not too sure about this hope. My understanding had been that the communication should be the other way around - i.e The main window will tell the thread to cancel the download, rather than the thread asking the window if it should continue/cancel

jkirkerx wrote:
FYI:

I'm not not looking for code, just ideas or pointers.

This is the callback, the h file is seperate. I'm fuzzy about this line in the constructor

: m_Progress_Text(NULL), m_Progress_Bar(NULL) {

in which I' not really sure what it means, or what it does.

 


Sure thing, sorry if I've innundated you with useless code, confusing the matter.
I think you'l find that the above snippet will call the constructors for the progress text and the progress bar. I reckon you'd find that if you changed the NULLs to "myProgTest" and 50, respectively that you'd have a progress bar at 50% with the text myProgTest - why not give it a try?


After thinking over this some more last night, I decided to have a go at implementing a cancel button for my downloads. In this case, I added an extra field to the struct that I pass to the thread function - a simple boolean flag, bCancelled. Cancelling the download is a simple matter of setting this flag in the struct from the main thread in response to the cancel button.
In the download function, during the receive loop I simply check the status of this flag. If true, I just clean-up the memory I used and exit. It seems to work flawlessly. Also, since it's a graceful exit, I can be certain of the number of bytes downloaded before it was cancelled. This has a two-fold benefit -
(1) I can close the handle on the file I'm saving it too, avoiding total loss of the data and
(2) I know where the download is up to, so I can resume it at a later time of my choosing

Initially, my aim had been to get the size of a resource if given a url. Since wininet didn't seem to provide the functionality, I had to get access to the raw HTTP headers. From what I could determine, this required low-level use of sockets. However, the rewards have been, well worth-while.



C++
case WM_COMMAND:
    switch(LOWORD(wParam))
    {
        case IDC_BTN_CANCEL:
            singleDownload.bCancelled = true;
            return true;





C++
///////////// step 3 - get received bytes ////////////////
// Receive until the peer closes the connection
hdr->contentLen = 0;
while(1)
{
    if (hdr->bCancelled)
        break;

    memset(hdr->readBuffer, 0, bufSize);
    hdr->thisReadSize = recv (hdr->conn, hdr->readBuffer, bufSize, 0);
    if ( hdr->thisReadSize <= 0 )
        break;

GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx19-Nov-11 17:52
professionaljkirkerx19-Nov-11 17:52 

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.