Click here to Skip to main content
15,905,781 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
That sounds tricky.

I'm not sure what to do yet, but I'm moving forward. Here is my process

Button Click Next ->

_download_SQLServer_Begin - GUI stuff - Call _download_SQLServer_Package
_download_SQLServer_Package - Download Prep - Start Thread
SQL_SoftwareDownload - load callback, call urldownload function
_download_SQLServer_End - End Thread stuff, GUI unwind

cancel button click!
_cancel_SQLServer_Package - stop download process- send message to bind callback to E_ABORT
call _download_SQLServerEnd for thread and GUI unwind

I had to split the gui stuff in half - sorry to bombard you with code, I'm sure theirs much to delete

BOOL _download_SQLServer_Begin( HWND cWnd ) 
{
	BOOL			bResult								= FALSE;
	BOOL			bPreFlightCheck						= FALSE;
	BOOL			bAreWeX64							= FALSE;

	CA_Windows caWin;
		
	// Hide the Instructions
	ShowWindow(lbl_SQL_Server_Download_Instructions, SW_HIDE);
	// Hide the Navigation Buttons
	ShowWindow(bt_SQL_Server_Download_Next, SW_HIDE);
	ShowWindow(bt_SQL_Server_Download_Exit, SW_HIDE);
	ShowWindow(bt_SQL_Server_Download_Cancel, SW_SHOW);
	
	// Hide the Listbox and Intialize it
	ShowWindow(lbl_SQL_Server_Download_Label, SW_HIDE);		
	// Show the Status Bar
	ShowWindow(lbl_SQL_Server_Download_Status, SW_SHOW);
	
	// Are we on a x64 OS 
	bAreWeX64 = caWin._getProcessorArchitecture();
	if (bAreWeX64 == TRUE) {
		SetWindowText(lbl_SQL_Server_Download_Status, L"Requesting X64 Version from microsoft.com");		
	}
	else {
		SetWindowText(lbl_SQL_Server_Download_Status, L"Requesting X86 Version from microsoft.com");		
	}
	SendMessage(pb_SQL_Server_Download_Status, PBM_SETPOS, (WPARAM)0, LPARAM(100));
	SendMessage(pb_SQL_Server_Download_Status, PBM_SETSTEP, (WPARAM)1, NULL);
	ShowWindow(pb_SQL_Server_Download_Status, SW_SHOW);
	UpdateWindow(pb_SQL_Server_Download_Status);
	// Update the Stage 1 more time
	UpdateWindow(cWnd);
	// Call the Program Download Function
	bResult = _download_SQLServer_Package( bAreWeX64 );
	return bResult;
}

BOOL _download_SQLServer_End( HWND cWnd ) {
		
	BOOL			bResult								= FALSE;

	//WaitForSingleObject( hThread, INFINITE );
	//_endthread();
	//CloseHandle(hThread);
	
	ShowWindow(bt_SQL_Server_Download_Cancel, SW_HIDE);
	ShowWindow(bt_SQL_Server_Download_Exit, SW_SHOW);	
	
	if ( bResult == TRUE ) {
		SetWindowText(lbl_SQL_Server_Download_Status, L"Download has completed successfully");		
		// Show the Listbox and Intialize it
		ShowWindow(lbl_SQL_Server_Download_Label, SW_SHOW);
		BOOL preFlightCheck = FALSE;
		Sleep(2000);

		int msgboxID = MessageBoxEx(hSQL_Servers_Download,
			L"Would you like to install SQL Server now?",
			L"SQL Server has been downloaded successfully",
			MB_OKCANCEL | MB_DEFBUTTON1 | MB_ICONINFORMATION,
			LANG_NEUTRAL
		);

		switch ( msgboxID ) 
		{			
			case IDOK:
				preFlightCheck = TRUE;					
				break;

			case IDCANCEL:
				preFlightCheck = FALSE;
				break;
		} 
	}
	return bResult;
}

BOOL _cancel_SQLServer_Package( HWND cWnd )
{
	BOOL bResult  = FALSE;
	int msgboxID;
		
	msgboxID = MessageBoxEx(hSQL_Servers_Download,
			L"Canceling the download will prevent you from installing SQL Server?",
			L"SQL Server is downloading now",
			MB_OKCANCEL | MB_DEFBUTTON1 | MB_ICONINFORMATION,
			LANG_NEUTRAL
	);

	switch ( msgboxID ) 
	{			
		case IDOK:
			// Kill the Callback Loop
			_download_SQLServer_End( cWnd );				
			bResult = FALSE;
			break;
		case IDCANCEL:			
			bResult = FALSE;
			break;
	}
	return bResult;
}

BOOL _download_SQLServer_Package( BOOL X64 )
{
	BOOL					resultCode				= FALSE;
	BOOL					bThread					= FALSE;
	HRESULT					hr						= S_OK;
	
	char					*fs_X86					= "762761216";
	char					*fs_X64					= "834555904";	
	char					*ckSum_X86				= "10ef23fe7bd9b6a64dcaf1927dd19df7";
	char					*ckSum_X64				= "5122f358a63e12a3095aaabba8203292";	
	WCHAR					*szUrl_X86				= L"http://download.microsoft.com/download/9/7/6/9761DF25-CBD8-4D48-9415-065F6BD4E63D/SQLEXPRADV_x86_ENU.exe";
	WCHAR					*szUrl_X64				= L"http://download.microsoft.com/download/9/7/6/9761DF25-CBD8-4D48-9415-065F6BD4E63D/SQLEXPRADV_x64_ENU.exe";
	
	WCHAR					*szFileName_X86			= L"SQLEXPRADV_x86_ENU.EXE";
	WCHAR					*szFileName_X64			= L"SQLEXPRADV_x64_ENU.EXE";
	WCHAR					*szTargetFolder			= NULL;
	WCHAR					*szSystemDrive			= NULL;
	WCHAR					*szFileName_X			= NULL;
		
	DWORD					dwReserved				= 0;
	LPCWSTR					szError					= NULL;
	
	/////////////////////////////////////////////////////////////////////////////////////////
	// Pre Flight Check - See if the file is already downloaded, make sure it's legit	
	// Select the URL target for download based on cpu type	
	if (X64 == FALSE) {
		// Download the X86 Version of SQL Server
		int iSize = wcslen(szUrl_X86)*sizeof(szUrl_X86);
		szUrl = szUrl_X86;
	}
	else {
		// Download the X64 Version of SQL Server
		int iSize = wcslen(szUrl_X64)*sizeof(szUrl_X64);
		szUrl = szUrl_X64;
	}

	// Get the System Drive Letter and Windows Folder
	CA_Windows *caWin = new CA_Windows;	
	szSystemDrive = caWin->_getWindowsFolder();
	caWin = NULL;

	// Figure out where to store the file - prefer appdata folder	
	wcsncpy_s(szFileName, szSystemDrive, wcslen(szSystemDrive) );
	wcsncat_s(szFileName, L"\\Temp\\", wcslen(L"\\Temp\\") );
	
	if (X64 == FALSE) {
		wcsncat_s(szFileName, szFileName_X86, wcslen(szFileName_X86) );		
	} 
	else {
		wcsncat_s(szFileName, szFileName_X64, wcslen(szFileName_X64) );		
	}
		
	// Combine the system drive and app data folder.
	// End of Pre Flight Check
	///////////////////////////////////////////////////////////////////////////////////////////
	// Ready for Take Off
	hThread = (HANDLE)_beginthreadex(NULL, 0, SQL_SoftwareDownload, NULL, 0, (unsigned *)&thread_id);		
	return resultCode;
}

unsigned int __stdcall SQL_SoftwareDownload(void *) {
	int iReturn = 0;
	HRESULT hr = E_FAIL;

	SQL_Servers_BindCallback *callback;
	callback = new SQL_Servers_BindCallback;
	callback->m_MDIChild = hSQL_Servers_Download;
	callback->m_Progress_Text = lbl_SQL_Server_Download_Status;
	callback->m_Progress_Bar = pb_SQL_Server_Download_Status;
	callback->Release();
		
	hr = URLDownloadToFile(NULL, szUrl, szFileName, 0, callback);
	if (hr == S_OK)
		iReturn = 1;	

	return iReturn;
}

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 
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 

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.