Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP library wrapping IProgressDialog interface
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01528196
Message ID:
01528327
Views:
84
Below is C++ code sample. I also found very competent C# implementation on Pinvoke.
http://pinvoke.net/default.aspx/Interfaces/IProgressDialog.html
#include "stdafx.h"
#include "Shlobj.h"

IProgressDialog* pIDlg;

void StartDialog();
void StopDialog();
void RunDialog();

int _tmain()
{
	// In FLL use COINIT_APARTMENTTHREADED
	HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
	if (FAILED(hr))
	{
		printf("Call to CoInitializeEx failed.");
		return -1;
	}

	RunDialog();

	CoUninitialize();
	return 0;
}

void StopDialog()
{
	if (pIDlg)
	{
		HRESULT hr = pIDlg->StopProgressDialog();
	}
}

void StartDialog()
{
	LPCLASSFACTORY pIClassFactory;

	HRESULT hr = CoGetClassObject(
		CLSID_ProgressDialog, 
		CLSCTX_INPROC_SERVER, 
		NULL, 
		IID_IClassFactory, 
		(LPVOID *)&pIClassFactory); 

	if (SUCCEEDED(hr)) 
	{
		hr = pIClassFactory->CreateInstance(
			NULL, 
			IID_IProgressDialog, 
			(LPVOID *) &pIDlg);

		pIClassFactory->Release(); 
	}

	pIDlg->SetTitle(L"Dialog Title");

	pIDlg->SetLine(1, L"Line 1", FALSE, NULL);
	pIDlg->SetLine(2, L"Line 2...", FALSE, NULL);

	pIDlg->SetCancelMsg(
		L"Please wait while we cancel the process...", 
		NULL);

	DWORD dwFlags = PROGDLG_NORMAL 
		| PROGDLG_MODAL 
		| PROGDLG_NOMINIMIZE 
		| PROGDLG_AUTOTIME;

	pIDlg->Timer(PDTIMER_RESET, NULL);

	hr = pIDlg->StartProgressDialog(
		GetDesktopWindow(), 
		NULL,
		dwFlags,
		NULL);
}

void RunDialog()
{
	pIDlg = NULL;
	StartDialog();

	for (int i=0; i < 100; i++)
	{
		if (pIDlg->HasUserCancelled())
		{
			Sleep(1000);
			break;
		}

		Sleep(100);
		pIDlg->SetProgress(i, 100);
	}

	StopDialog();
}
Previous
Reply
Map
View

Click here to load this message in the networking platform