using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Runtime.InteropServices; namespace NeroFiddlesCOM.NET { /// /// Summary description for NVAPIEstimateForm. /// public class NVAPIEstimateForm : System.Windows.Forms.Form, NeroVisionAPI.IProgressCallback { [DllImport("kernel32.dll", SetLastError=true)] static extern IntPtr GetModuleHandleA (string lpModuleName); private bool m_bEstimate; private bool m_bShouldCancel; private double m_seconds; private bool m_bResult; private NeroVisionAPI.Project m_project; private NeroVisionAPI.INeroBurnContext m_pNeroBurnContext; private System.Windows.Forms.ProgressBar c_CurrentProgress; private System.Windows.Forms.ProgressBar c_TotalProgress; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label c_CurrentItem; private System.Windows.Forms.Label c_CurrentPercent; private System.Windows.Forms.Label c_TotalPercent; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button c_Cancel; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public NVAPIEstimateForm() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.c_CurrentProgress = new System.Windows.Forms.ProgressBar(); this.c_TotalProgress = new System.Windows.Forms.ProgressBar(); this.label1 = new System.Windows.Forms.Label(); this.c_CurrentItem = new System.Windows.Forms.Label(); this.c_CurrentPercent = new System.Windows.Forms.Label(); this.c_TotalPercent = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.c_Cancel = new System.Windows.Forms.Button(); this.SuspendLayout(); // // c_CurrentProgress // this.c_CurrentProgress.Location = new System.Drawing.Point(8, 40); this.c_CurrentProgress.Name = "c_CurrentProgress"; this.c_CurrentProgress.Size = new System.Drawing.Size(352, 23); this.c_CurrentProgress.TabIndex = 3; // // c_TotalProgress // this.c_TotalProgress.Location = new System.Drawing.Point(8, 104); this.c_TotalProgress.Name = "c_TotalProgress"; this.c_TotalProgress.Size = new System.Drawing.Size(352, 23); this.c_TotalProgress.TabIndex = 6; // // label1 // this.label1.Location = new System.Drawing.Point(8, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(72, 16); this.label1.TabIndex = 0; this.label1.Text = "Current item:"; // // c_CurrentItem // this.c_CurrentItem.Location = new System.Drawing.Point(96, 16); this.c_CurrentItem.Name = "c_CurrentItem"; this.c_CurrentItem.Size = new System.Drawing.Size(200, 16); this.c_CurrentItem.TabIndex = 1; // // c_CurrentPercent // this.c_CurrentPercent.Location = new System.Drawing.Point(320, 16); this.c_CurrentPercent.Name = "c_CurrentPercent"; this.c_CurrentPercent.Size = new System.Drawing.Size(40, 16); this.c_CurrentPercent.TabIndex = 2; this.c_CurrentPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // c_TotalPercent // this.c_TotalPercent.Location = new System.Drawing.Point(320, 80); this.c_TotalPercent.Name = "c_TotalPercent"; this.c_TotalPercent.Size = new System.Drawing.Size(40, 16); this.c_TotalPercent.TabIndex = 5; this.c_TotalPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // label2 // this.label2.Location = new System.Drawing.Point(8, 80); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(80, 16); this.label2.TabIndex = 4; this.label2.Text = "Total progress:"; // // c_Cancel // this.c_Cancel.Location = new System.Drawing.Point(144, 144); this.c_Cancel.Name = "c_Cancel"; this.c_Cancel.TabIndex = 7; this.c_Cancel.Text = "Cancel"; this.c_Cancel.Click += new System.EventHandler(this.c_Cancel_Click); // // NVAPIEstimateForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(370, 176); this.Controls.Add(this.c_Cancel); this.Controls.Add(this.label1); this.Controls.Add(this.c_CurrentProgress); this.Controls.Add(this.c_TotalProgress); this.Controls.Add(this.c_CurrentItem); this.Controls.Add(this.c_CurrentPercent); this.Controls.Add(this.c_TotalPercent); this.Controls.Add(this.label2); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "NVAPIEstimateForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "NVAPIEstimateForm"; this.ResumeLayout(false); } #endregion public void OnProgress(NeroVisionAPI.ProgressAction action, string itemname, double currentRemain, double currentTotal, float currentFraction, double totalRemain, double totalTotal, float totalFraction) { // This is a IProgressCallback method implementation. // We are called every once in a while to report progress. // float currentPercent = currentFraction*100; float totalPercent = totalFraction*100; c_CurrentItem.Text = itemname; c_CurrentProgress.Value = (int) currentPercent; c_CurrentPercent.Text = currentPercent.ToString ("N0") + "%"; c_TotalProgress.Value = (int) totalPercent; c_TotalPercent.Text = totalPercent.ToString ("N0") + "%"; // We must process messages from a Windows message queue in order // for everything to repaint properly as well as for the Cancel // button to be able to perform. // Application.DoEvents (); } public bool ShouldCancel () { // This is a IProgressCallback method implementation. // We are called every once in a while to report cancelation. // Application.DoEvents (); return m_bShouldCancel; } protected override void OnLoad(EventArgs e) { base.OnLoad (e); // Since both EstimateCreateNeroBurnContextTime and CreateNeroBurnContext // do not return until their work is done, we need to show our form // early and process messages to allow it to repaint. We are implementing // IProgressCallback so we will get notified of the total progress. // m_bShouldCancel = false; this.Visible = true; Application.DoEvents (); m_bResult = false; if (m_bEstimate) { this.Text = "Estimating..."; m_seconds = 0; m_bResult = m_project.EstimateCreateNeroBurnContextTime (this, out m_seconds); } else { this.Text = "Creating burn context..."; m_pNeroBurnContext = null; m_bResult = m_project.CreateNeroBurnContext (GetModuleHandleA ("NeroAPI.dll"), this, out m_pNeroBurnContext); } // Once any of the two above methods returns, we are done, so we // need to manually close the form. // this.Close (); } private void c_Cancel_Click(object sender, System.EventArgs e) { // When Cancel button is clicked, set the flag. This will // be returned in the IProgressCallback method. // m_bShouldCancel = true; } public bool Estimate (System.Windows.Forms.IWin32Window owner, NeroVisionAPI.Project proj, out double seconds) { // Set the flag that tells that this is an estimation command. // Show the dialog and return the resulting seoconds value. // m_bEstimate = true; m_project = proj; ShowDialog (owner); seconds = m_seconds; return m_bResult; } public bool CreateNeroBurnContext (System.Windows.Forms.IWin32Window owner, NeroVisionAPI.Project proj, out NeroVisionAPI.INeroBurnContext pNeroBurnContext) { // Set the flag that tells that this is a transcoding command. // Show the dialog and return the resulting INeroBurnContext. // m_bEstimate = false; m_project = proj; ShowDialog (owner); pNeroBurnContext = m_pNeroBurnContext; return m_bResult; } } }