INSTALLMESSAGE_PROGRESS
您可以通过向安装程序发出消息来手动控制进度条的状态。详细信息可以在这里找到:
http://msdn.microsoft.com/en-us/library/aa370354.aspx
特别是,您需要一个自定义操作来管理状态栏(它将负责对 进行适当的调用MsiProcessMessage
。我建议您也使用它来生成子安装程序。这里有一些伪代码来说明我的想法是:
LONG LaunchSubinstallersCA(MSIHANDLE current_installer)
{
// Initialize the progress bar range and position
MsiProcessMessage(current_installer, reset_message); // see MSDN for details
for each (subinstaller in list_of_installers)
{
launch subinstaller; // see MSDN for details
// Update the progress bar to reflect most recent changes
MsiProcessMessage(current_installer, increment_message); // see MSDN for details
}
return (result);
}
主要的缺点是进度条将以一种有点不稳定的方式前进。如果您真的想变得花哨并使其更流畅,您可以启动一个单独的“侦听器”线程,该线程将等待来自子安装程序的更新,以便对进度条进行更细粒度的增量。就像是:
LONG LaunchSubinstallersCA(MSIHANDLE current_installer)
{
// Initialize the progress bar range and position
MsiProcessMessage(current_installer, reset_message); // see MSDN for details
launch_listener_thread(); // launches listener_thread_proc (see below)
for each (subinstaller in list_of_installers)
{
launch subinstaller; // see MSDN for details
}
tell_listener_thread_to_stop();
optionally_wait_for_listener_thread_to_die();
return (result);
}
void listener_thread_proc()
{
// Loop until told to stop
while (!time_for_me_to_stop)
{
// Listen for update from sub-installer
timed_wait_for_update(); // probably required IPC, perhaps a named event?
// Only update the progress bar if an update message was actually received
if (!timeout)
{
// Update the progress bar to reflect most recent changes
MsiProcessMessage(current_installer, increment_message); // see MSDN for details
}
}
}
显然,每个子安装程序都必须能够向主安装程序发出已取得进展的信号,因此这可能需要对您的产品进行更广泛的更改。这是否值得努力取决于你。