Click here to Skip to main content
15,892,161 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
I tried killing the thread, but it destroyed my window. but that was before I split the functions.

Here's the other half of the code - Callback Statu. I think somehow, there is a way for the callback to receive messages or values during the OnProcess loop, or it's just optimism on my behalf. I should be able to get the loop to ask the window if cancel has been invoked.

There is a code sample on CP that uses a dialog box, in which a handle is created back to the dialog box, I'm not sure if the handle is bi-directional.

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.

#include "stdafx.h"
#include <stdlib.h>

#include "atlstr.h"
#include <string>
#include <tchar.h>

#include <math.h>

#include "resource.h"
#include "stdio.h"
#include <commctrl.h>
#include <Windows.h>
#include <Winuser.h>
#include <Winbase.h>
#include "SQL_Servers_BindCallback.h"

#pragma comment(lib, "urlmon.lib")
#pragma comment(lib,"wininet.lib")
#define RETURN_ON_FAILURE(hr) if (FAILED(hr)) return (hr);	
		
	SQL_Servers_BindCallback::SQL_Servers_BindCallback ( ) : m_Progress_Text(NULL), m_Progress_Bar(NULL) {
		ShowWindow(m_Progress_Bar, SW_SHOW);
		UpdateWindow(m_Progress_Bar);
		UpdateWindow(m_MDIChild);

		SendMessage(m_Progress_Bar, PBM_SETRANGE, 0, MAKELPARAM(0, 5000) );
		SendMessage(m_Progress_Bar, PBM_SETPOS, (WPARAM)10, 0);		
	}

	SQL_Servers_BindCallback::~SQL_Servers_BindCallback( ) {	
	
	}
			
	HRESULT SQL_Servers_BindCallback::OnProgress(
		/* [in] */ ULONG ulProgress, 
		/* [in] */ ULONG ulProgressMax, 
		/* [in] */ ULONG ulStatusCode, 
		/* [in] */ LPCWSTR wszStatusText)
	{				
		static int iMsgLen;
		static double dBytes;
		static double dTotal;
		static double dPercent;
		static double dPB;	
		static TCHAR szStatusMessage[80];			
   		
		wcsncpy_s(szStatusMessage, L"please wait...", wcslen(L"please wait...") );

		switch (ulStatusCode) {		
			case BINDSTATUS_CONNECTING:
				wcsncpy_s(szStatusMessage, L"Connecting to download.microsoft.com", wcslen(L"Connecting to download.microsoft.com") );
				break;

			case BINDSTATUS_DOWNLOADINGDATA:
				// Calculate the MegaBytes Downloaded		
				dBytes = ((float)ulProgress / (1024*1024));
				dTotal = ((float)ulProgressMax / (1024*1024));
				dPercent = dBytes/dTotal*100;

				if ((dBytes > 0.01) && (dTotal > 0.01)) {
					swprintf_s(szStatusMessage,
						80,
						L"Downloading %.2f MB of %.2f MB [%.1f%%]",
						dBytes, dTotal, dPercent
					);					
				}
				break;

			case BINDSTATUS_ENDDOWNLOADDATA:				
				wcsncpy_s(szStatusMessage, L"Disconnecting from download.microsoft.com", wcslen(L"Disconnecting from download.microsoft.com") );
				Sleep(1000);
				return TRUE;
				break;
		}		
		
		// Publish Status Message
		SetWindowText(m_Progress_Text, szStatusMessage);
				
		// Format the Progress Bar Value
		dPB = (float)ulProgress/ulProgressMax*5000.0;
		SendMessage(m_Progress_Bar, PBM_SETPOS, (WPARAM)dPB, 0);
		SendMessage(m_Progress_Bar, PBM_SETRANGE, 0, MAKELPARAM(0, 5000) );		
		iLoopCount++;
		return S_OK;	
	}

	HRESULT SQL_Servers_BindCallback::OnStartBinding(
		/* [in] */ DWORD dwReserved, 
		/* [in] */ IBinding __RPC_FAR *pib)
	{ return S_OK; }
	
	HRESULT SQL_Servers_BindCallback::GetPriority(
		/* [out] */ LONG __RPC_FAR *pnPriority)
	{ return E_NOTIMPL;	}

	HRESULT SQL_Servers_BindCallback::OnLowResource(
		/* [in] */ DWORD reserved) 
	{ return E_NOTIMPL;	}

	HRESULT SQL_Servers_BindCallback::OnStopBinding(
		/* [in] */ HRESULT hresult, 
		/* [unique][in] */ LPCWSTR szError)
	{ return S_OK; }

	HRESULT SQL_Servers_BindCallback::GetBindInfo(
		/* [out] */ DWORD __RPC_FAR *grfBINDF, 
		/* [unique][out][in] */ BINDINFO __RPC_FAR *pbindinfo)
	{ return E_NOTIMPL; }

	HRESULT SQL_Servers_BindCallback::OnDataAvailable(
		/* [in] */ DWORD grfBSCF, 
		/* [in] */ DWORD dwSize, 
		/* [in] */ FORMATETC __RPC_FAR *pformatetc, 
		/* [in] */ STGMEDIUM __RPC_FAR *pstgmed)
	{ return S_OK; }

	HRESULT SQL_Servers_BindCallback::OnObjectAvailable(
		/* [in] */ REFIID riid, 
		/* [iid_is][in] */ IUnknown __RPC_FAR *punk)
	{ return E_NOTIMPL;	}

	ULONG SQL_Servers_BindCallback::AddRef()
	{ return 0;	}

	ULONG SQL_Servers_BindCallback::Release()	
	{ return 0; }

	HRESULT SQL_Servers_BindCallback::QueryInterface(
		/* [in] */ REFIID riid, 
		/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
	{ return E_NOTIMPL;	}

GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep19-Nov-11 15:00
enhzflep19-Nov-11 15:00 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx19-Nov-11 17:52
professionaljkirkerx19-Nov-11 17:52 
GeneralRe: URLDownloadToFile, Cancel Button Pin
enhzflep20-Nov-11 0:56
enhzflep20-Nov-11 0:56 
GeneralRe: URLDownloadToFile, Cancel Button Pin
jkirkerx20-Nov-11 18:06
professionaljkirkerx20-Nov-11 18:06 
QuestionProblem with MSDN Preview Handler Recipe Pin
AndrewG123115-Nov-11 13:26
AndrewG123115-Nov-11 13:26 
QuestionOT - question for real COM / RS232 guru Pin
Vaclav_15-Nov-11 10:33
Vaclav_15-Nov-11 10:33 
AnswerRe: OT - question for real COM / RS232 guru Pin
Richard MacCutchan15-Nov-11 22:00
mveRichard MacCutchan15-Nov-11 22:00 
GeneralRe: OT - question for real COM / RS232 guru Pin
Vaclav_16-Nov-11 2:50
Vaclav_16-Nov-11 2:50 
GeneralRe: OT - question for real COM / RS232 guru Pin
Richard MacCutchan16-Nov-11 3:19
mveRichard MacCutchan16-Nov-11 3:19 
RantSmart pointers Pin
Pascal Ganaye15-Nov-11 6:15
Pascal Ganaye15-Nov-11 6:15 
GeneralRe: Smart pointers Pin
Erudite_Eric15-Nov-11 7:33
Erudite_Eric15-Nov-11 7:33 
GeneralRe: Smart pointers Pin
JackDingler15-Nov-11 11:23
JackDingler15-Nov-11 11:23 
GeneralRe: Smart pointers Pin
Stefan_Lang17-Nov-11 4:42
Stefan_Lang17-Nov-11 4:42 
GeneralRe: Smart pointers Pin
JackDingler17-Nov-11 5:48
JackDingler17-Nov-11 5:48 
GeneralRe: Smart pointers Pin
Stefan_Lang17-Nov-11 5:56
Stefan_Lang17-Nov-11 5:56 
GeneralRe: Smart pointers Pin
Orjan Westin15-Nov-11 23:41
professionalOrjan Westin15-Nov-11 23:41 
GeneralRe: Smart pointers Pin
Erudite_Eric16-Nov-11 22:39
Erudite_Eric16-Nov-11 22:39 

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.