NVAPIEstimate.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7. namespace LYFZ.NeroDiscBurn.NET
  8. {
  9. /// <summary>
  10. /// Summary description for NVAPIEstimateForm.
  11. /// </summary>
  12. public class NVAPIEstimateForm : System.Windows.Forms.Form, NeroVisionAPI.IProgressCallback
  13. {
  14. [DllImport("kernel32.dll", SetLastError=true)]
  15. static extern IntPtr GetModuleHandleA (string lpModuleName);
  16. private bool m_bEstimate;
  17. private bool m_bShouldCancel;
  18. private double m_seconds;
  19. private bool m_bResult;
  20. private NeroVisionAPI.Project m_project;
  21. private NeroVisionAPI.INeroBurnContext m_pNeroBurnContext;
  22. private System.Windows.Forms.ProgressBar c_CurrentProgress;
  23. private System.Windows.Forms.ProgressBar c_TotalProgress;
  24. private System.Windows.Forms.Label label1;
  25. private System.Windows.Forms.Label c_CurrentItem;
  26. private System.Windows.Forms.Label c_CurrentPercent;
  27. private System.Windows.Forms.Label c_TotalPercent;
  28. private System.Windows.Forms.Label label2;
  29. private System.Windows.Forms.Button c_Cancel;
  30. /// <summary>
  31. /// Required designer variable.
  32. /// </summary>
  33. private System.ComponentModel.Container components = null;
  34. public NVAPIEstimateForm()
  35. {
  36. //
  37. // Required for Windows Form Designer support
  38. //
  39. InitializeComponent();
  40. }
  41. /// <summary>
  42. /// Clean up any resources being used.
  43. /// </summary>
  44. protected override void Dispose( bool disposing )
  45. {
  46. if( disposing )
  47. {
  48. if(components != null)
  49. {
  50. components.Dispose();
  51. }
  52. }
  53. base.Dispose( disposing );
  54. }
  55. #region Windows Form Designer generated code
  56. /// <summary>
  57. /// Required method for Designer support - do not modify
  58. /// the contents of this method with the code editor.
  59. /// </summary>
  60. private void InitializeComponent()
  61. {
  62. this.c_CurrentProgress = new System.Windows.Forms.ProgressBar();
  63. this.c_TotalProgress = new System.Windows.Forms.ProgressBar();
  64. this.label1 = new System.Windows.Forms.Label();
  65. this.c_CurrentItem = new System.Windows.Forms.Label();
  66. this.c_CurrentPercent = new System.Windows.Forms.Label();
  67. this.c_TotalPercent = new System.Windows.Forms.Label();
  68. this.label2 = new System.Windows.Forms.Label();
  69. this.c_Cancel = new System.Windows.Forms.Button();
  70. this.SuspendLayout();
  71. //
  72. // c_CurrentProgress
  73. //
  74. this.c_CurrentProgress.Location = new System.Drawing.Point(8, 40);
  75. this.c_CurrentProgress.Name = "c_CurrentProgress";
  76. this.c_CurrentProgress.Size = new System.Drawing.Size(352, 23);
  77. this.c_CurrentProgress.TabIndex = 3;
  78. //
  79. // c_TotalProgress
  80. //
  81. this.c_TotalProgress.Location = new System.Drawing.Point(8, 104);
  82. this.c_TotalProgress.Name = "c_TotalProgress";
  83. this.c_TotalProgress.Size = new System.Drawing.Size(352, 23);
  84. this.c_TotalProgress.TabIndex = 6;
  85. //
  86. // label1
  87. //
  88. this.label1.Location = new System.Drawing.Point(8, 16);
  89. this.label1.Name = "label1";
  90. this.label1.Size = new System.Drawing.Size(72, 16);
  91. this.label1.TabIndex = 0;
  92. this.label1.Text = "Current item:";
  93. //
  94. // c_CurrentItem
  95. //
  96. this.c_CurrentItem.Location = new System.Drawing.Point(96, 16);
  97. this.c_CurrentItem.Name = "c_CurrentItem";
  98. this.c_CurrentItem.Size = new System.Drawing.Size(200, 16);
  99. this.c_CurrentItem.TabIndex = 1;
  100. //
  101. // c_CurrentPercent
  102. //
  103. this.c_CurrentPercent.Location = new System.Drawing.Point(320, 16);
  104. this.c_CurrentPercent.Name = "c_CurrentPercent";
  105. this.c_CurrentPercent.Size = new System.Drawing.Size(40, 16);
  106. this.c_CurrentPercent.TabIndex = 2;
  107. this.c_CurrentPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  108. //
  109. // c_TotalPercent
  110. //
  111. this.c_TotalPercent.Location = new System.Drawing.Point(320, 80);
  112. this.c_TotalPercent.Name = "c_TotalPercent";
  113. this.c_TotalPercent.Size = new System.Drawing.Size(40, 16);
  114. this.c_TotalPercent.TabIndex = 5;
  115. this.c_TotalPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  116. //
  117. // label2
  118. //
  119. this.label2.Location = new System.Drawing.Point(8, 80);
  120. this.label2.Name = "label2";
  121. this.label2.Size = new System.Drawing.Size(80, 16);
  122. this.label2.TabIndex = 4;
  123. this.label2.Text = "Total progress:";
  124. //
  125. // c_Cancel
  126. //
  127. this.c_Cancel.Location = new System.Drawing.Point(144, 144);
  128. this.c_Cancel.Name = "c_Cancel";
  129. this.c_Cancel.TabIndex = 7;
  130. this.c_Cancel.Text = "Cancel";
  131. this.c_Cancel.Click += new System.EventHandler(this.c_Cancel_Click);
  132. //
  133. // NVAPIEstimateForm
  134. //
  135. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  136. this.ClientSize = new System.Drawing.Size(370, 176);
  137. this.Controls.Add(this.c_Cancel);
  138. this.Controls.Add(this.label1);
  139. this.Controls.Add(this.c_CurrentProgress);
  140. this.Controls.Add(this.c_TotalProgress);
  141. this.Controls.Add(this.c_CurrentItem);
  142. this.Controls.Add(this.c_CurrentPercent);
  143. this.Controls.Add(this.c_TotalPercent);
  144. this.Controls.Add(this.label2);
  145. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  146. this.MaximizeBox = false;
  147. this.Name = "NVAPIEstimateForm";
  148. this.ShowInTaskbar = false;
  149. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  150. this.Text = "NVAPIEstimateForm";
  151. this.ResumeLayout(false);
  152. }
  153. #endregion
  154. public void OnProgress(NeroVisionAPI.ProgressAction action, string itemname, double currentRemain, double currentTotal, float currentFraction, double totalRemain, double totalTotal, float totalFraction)
  155. {
  156. // This is a IProgressCallback method implementation.
  157. // We are called every once in a while to report progress.
  158. //
  159. float currentPercent = currentFraction*100;
  160. float totalPercent = totalFraction*100;
  161. c_CurrentItem.Text = itemname;
  162. c_CurrentProgress.Value = (int) currentPercent;
  163. c_CurrentPercent.Text = currentPercent.ToString ("N0") + "%";
  164. c_TotalProgress.Value = (int) totalPercent;
  165. c_TotalPercent.Text = totalPercent.ToString ("N0") + "%";
  166. // We must process messages from a Windows message queue in order
  167. // for everything to repaint properly as well as for the Cancel
  168. // button to be able to perform.
  169. //
  170. Application.DoEvents ();
  171. }
  172. public bool ShouldCancel ()
  173. {
  174. // This is a IProgressCallback method implementation.
  175. // We are called every once in a while to report cancelation.
  176. //
  177. Application.DoEvents ();
  178. return m_bShouldCancel;
  179. }
  180. protected override void OnLoad(EventArgs e)
  181. {
  182. base.OnLoad (e);
  183. // Since both EstimateCreateNeroBurnContextTime and CreateNeroBurnContext
  184. // do not return until their work is done, we need to show our form
  185. // early and process messages to allow it to repaint. We are implementing
  186. // IProgressCallback so we will get notified of the total progress.
  187. //
  188. m_bShouldCancel = false;
  189. this.Visible = true;
  190. Application.DoEvents ();
  191. m_bResult = false;
  192. if (m_bEstimate)
  193. {
  194. this.Text = "Estimating...";
  195. m_seconds = 0;
  196. m_bResult = m_project.EstimateCreateNeroBurnContextTime (this, out m_seconds);
  197. }
  198. else
  199. {
  200. this.Text = "Creating burn context...";
  201. m_pNeroBurnContext = null;
  202. m_bResult = m_project.CreateNeroBurnContext (GetModuleHandleA ("NeroAPI.dll"),
  203. this,
  204. out m_pNeroBurnContext);
  205. }
  206. // Once any of the two above methods returns, we are done, so we
  207. // need to manually close the form.
  208. //
  209. this.Close ();
  210. }
  211. private void c_Cancel_Click(object sender, System.EventArgs e)
  212. {
  213. // When Cancel button is clicked, set the flag. This will
  214. // be returned in the IProgressCallback method.
  215. //
  216. m_bShouldCancel = true;
  217. }
  218. public bool Estimate (System.Windows.Forms.IWin32Window owner, NeroVisionAPI.Project proj, out double seconds)
  219. {
  220. // Set the flag that tells that this is an estimation command.
  221. // Show the dialog and return the resulting seoconds value.
  222. //
  223. m_bEstimate = true;
  224. m_project = proj;
  225. ShowDialog (owner);
  226. seconds = m_seconds;
  227. return m_bResult;
  228. }
  229. public bool CreateNeroBurnContext (System.Windows.Forms.IWin32Window owner, NeroVisionAPI.Project proj, out NeroVisionAPI.INeroBurnContext pNeroBurnContext)
  230. {
  231. // Set the flag that tells that this is a transcoding command.
  232. // Show the dialog and return the resulting INeroBurnContext.
  233. //
  234. m_bEstimate = false;
  235. m_project = proj;
  236. ShowDialog (owner);
  237. pNeroBurnContext = m_pNeroBurnContext;
  238. return m_bResult;
  239. }
  240. }
  241. }