BurnDlg.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* NeroSDK / NeroCBUI
  10. |*
  11. |* PROGRAM: TestNeroCBUI
  12. |*
  13. |* PURPOSE: Sample application for the use of NeroCBUI
  14. ******************************************************************************/
  15. // NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES !
  16. //
  17. // In order to make BurnDlg work in a MFC project one should:
  18. //
  19. // 1) Create a new CDialog derived class (probably using the wizard). The
  20. // dialog template should be empty (no controls). Its size will mandate
  21. // the initial size of the BurnProgressDlg.
  22. // 2) OnInitDialog should be used to create a NeroCBUI BurnProgressDlg
  23. // object and set its properties. This is the place to create the
  24. // actual window with IModelessDialog::Create method.
  25. // 3) It is essential to trigger the WM_GETMINMAXINFO message if NULL was
  26. // passed as pRect to IModelessDialog::Create. If it is non-NULL,
  27. // WM_GETMINMAXINFO triggering is not necessary.
  28. // 4) PreTranslateMessage should be overriden to allow the BurnProgressDlg
  29. // to handle its own dialog messages.
  30. // 5) OnCancel should be handled (even though there are no controls) so that
  31. // dialog dismissal is handled properly.
  32. // 6) OnSize should be handled to allow the sizing of the BurnProgressDlg.
  33. // 7) Finally, the burn process should be started after the dialog is
  34. // initialized. It is best to post a user message from the OnInitDialog
  35. // so that OnInitDialog can return. When the message is processed, it
  36. // will initiate the burn process. Due to the MFC architecture, even
  37. // though we posted a message from OnInitDialog, the dialog will not yet
  38. // be shown at the time of user message processing so we MUST show and
  39. // update the window manually.
  40. //
  41. // NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES ! NOTES !
  42. #include "stdafx.h"
  43. #include "TestNeroCBUI.h"
  44. #include "BurnDlg.h"
  45. #include <afxdlgs.h>
  46. #ifdef _DEBUG
  47. #define new DEBUG_NEW
  48. #undef THIS_FILE
  49. static char THIS_FILE[] = __FILE__;
  50. #endif
  51. // Allow the #define below if you want to test the dialog without setting
  52. // the minimum size.
  53. //
  54. //#define DONT_FORCE_MIN_SIZE
  55. #define UM_POST_INIT_DIALOG (WM_APP + 1)
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CBurnDlg dialog
  58. CBurnDlg::CBurnDlg(CWnd* pParent /*=NULL*/)
  59. : CDialog(CBurnDlg::IDD, pParent)
  60. {
  61. //{{AFX_DATA_INIT(CBurnDlg)
  62. // NOTE: the ClassWizard will add member initialization here
  63. //}}AFX_DATA_INIT
  64. m_pDeviceInfo = NULL;
  65. m_bWizardMode = FALSE;
  66. }
  67. CBurnDlg::~CBurnDlg ()
  68. {
  69. m_wndDialog.Detach ();
  70. // We must not release m_pDeviceInfo. It is not ours!!!
  71. //
  72. }
  73. void CBurnDlg::DoDataExchange(CDataExchange* pDX)
  74. {
  75. CDialog::DoDataExchange(pDX);
  76. //{{AFX_DATA_MAP(CBurnDlg)
  77. // NOTE: the ClassWizard will add DDX and DDV calls here
  78. //}}AFX_DATA_MAP
  79. }
  80. BEGIN_MESSAGE_MAP(CBurnDlg, CDialog)
  81. //{{AFX_MSG_MAP(CBurnDlg)
  82. ON_WM_DESTROY()
  83. ON_WM_SIZE()
  84. ON_WM_GETMINMAXINFO()
  85. //}}AFX_MSG_MAP
  86. ON_MESSAGE(UM_POST_INIT_DIALOG, OnPostInitDialog)
  87. END_MESSAGE_MAP()
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CBurnDlg message handlers
  90. BOOL CBurnDlg::OnInitDialog()
  91. {
  92. CDialog::OnInitDialog();
  93. if (SUCCEEDED (m_pModelessDialog.CoCreateInstance (__uuidof (BurnProgressDlg))))
  94. {
  95. CComQIPtr<IBurnProgressDlg3> pBurnProgressDlg (m_pModelessDialog);
  96. CComBSTR bstr;
  97. // We add this as a custom control as we are implementing dummy
  98. // IUnknown and needed IExternalChildWindow interface.
  99. //
  100. pBurnProgressDlg->AddCustomControl (BPCCP_BOTTOM_RIGHT_CORNER, this);
  101. bstr = "Test name";
  102. pBurnProgressDlg.p->put_CompilationName (bstr);
  103. bstr = "100 MB";
  104. pBurnProgressDlg.p->put_CompilationSize (bstr);
  105. bstr = "01:05:10";
  106. pBurnProgressDlg.p->put_CompilationTime (bstr);
  107. bstr = "ISO/Audio";
  108. pBurnProgressDlg.p->put_CompilationType (bstr);
  109. pBurnProgressDlg->put_WizardMode (m_bWizardMode);
  110. if(m_bWizardMode)
  111. pBurnProgressDlg.p->put_GUIFlags (BPGF_USED_BUFFER);
  112. CRect rect;
  113. GetClientRect (&rect);
  114. // Create the BurnProgressDlg with the same dimensions as its
  115. // parent dialog.
  116. //
  117. HWND hWndDialog = NULL;
  118. m_pModelessDialog.p->Create (m_hWnd, &rect, &hWndDialog);
  119. if (hWndDialog != NULL)
  120. {
  121. m_wndDialog.Attach (hWndDialog);
  122. m_wndDialog.ShowWindow (SW_SHOW);
  123. }
  124. // Let the dialog be shown first, then start the burn process.
  125. //
  126. PostMessage (UM_POST_INIT_DIALOG);
  127. }
  128. return TRUE; // return TRUE unless you set the focus to a control
  129. // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131. void CBurnDlg::OnDestroy()
  132. {
  133. CDialog::OnDestroy();
  134. if (m_pModelessDialog)
  135. {
  136. m_pModelessDialog.p->Destroy ();
  137. }
  138. }
  139. void CBurnDlg::OnSize(UINT nType, int cx, int cy)
  140. {
  141. CDialog::OnSize(nType, cx, cy);
  142. if (m_wndDialog.m_hWnd != NULL)
  143. {
  144. CRect rect (0, 0, cx, cy);
  145. m_wndDialog.MoveWindow (&rect);
  146. }
  147. }
  148. void CBurnDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  149. {
  150. #ifndef DONT_FORCE_MIN_SIZE
  151. if (m_wndDialog.m_hWnd != NULL)
  152. {
  153. MINMAXINFO mmi;
  154. mmi = *lpMMI;
  155. m_wndDialog.SendMessage (WM_GETMINMAXINFO, 0, (LPARAM) &mmi);
  156. CRect rect (0, 0, mmi.ptMinTrackSize.x, mmi.ptMinTrackSize.y);
  157. AdjustWindowRectEx (&rect, GetStyle (), FALSE, GetExStyle ());
  158. lpMMI->ptMinTrackSize.x = rect.Width ();
  159. lpMMI->ptMinTrackSize.y = rect.Height ();
  160. }
  161. else
  162. {
  163. CDialog::OnGetMinMaxInfo(lpMMI);
  164. }
  165. #else
  166. CDialog::OnGetMinMaxInfo(lpMMI);
  167. #endif
  168. }
  169. BOOL CBurnDlg::PreTranslateMessage(MSG* pMsg)
  170. {
  171. if (m_pModelessDialog)
  172. {
  173. if (m_pModelessDialog.p->TranslateAccelerator (pMsg) == S_OK)
  174. {
  175. return TRUE;
  176. }
  177. }
  178. return CDialog::PreTranslateMessage(pMsg);
  179. }
  180. LRESULT CBurnDlg::OnPostInitDialog (WPARAM wParam, LPARAM lParam)
  181. {
  182. CComQIPtr<IBurnProgressDlg> pBurnProgressDlg (m_pModelessDialog);
  183. if (pBurnProgressDlg)
  184. {
  185. ShowWindow (SW_SHOW);
  186. UpdateWindow ();
  187. static char szFilter[] = "Nero Images (*.nrg)|*.nrg|ISO Images (*.iso)|*.iso|All Files (*.*)|*.*||";
  188. CFileDialog fileDlg(TRUE,"nrg",NULL
  189. , OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilter, this);
  190. if(fileDlg.DoModal() == IDOK)
  191. {
  192. memset(&m_neroImage,0,sizeof(m_neroImage));
  193. m_neroImage.nwiImageFileName[0] = '\0';
  194. CString csFilename = fileDlg.GetPathName();
  195. m_neroImage.nwiLongImageFileName = (LPCSTR)csFilename;
  196. pBurnProgressDlg.p->Burn2 (m_pDeviceInfo, NERO_BURN_IMAGE_MEDIA, &m_neroImage, NBF_DETECT_NON_EMPTY_CDRW|NBF_WRITE, 0, NULL);
  197. }
  198. else
  199. {
  200. pBurnProgressDlg.p->AddLogLine(NERO_TEXT_STOP,L"Burning not started! (TestNeroCBUI)");
  201. pBurnProgressDlg.p->Cancel();
  202. }
  203. }
  204. return 0;
  205. }
  206. void CBurnDlg::OnCancel()
  207. {
  208. CComQIPtr<IBurnProgressDlg> pBurnProgressDlg (m_pModelessDialog);
  209. BOOL bCanClose = FALSE;
  210. ATLASSERT (pBurnProgressDlg.p != NULL);
  211. if (pBurnProgressDlg.p)
  212. {
  213. // Ask the BurnProgressDlg if we are allowed to close the parent.
  214. //
  215. pBurnProgressDlg.p->CanCloseParent (&bCanClose);
  216. }
  217. if (!bCanClose)
  218. {
  219. // If not allowed to close, cancel the burning process.
  220. //
  221. if (pBurnProgressDlg.p)
  222. {
  223. pBurnProgressDlg.p->Cancel ();
  224. }
  225. }
  226. else
  227. {
  228. CDialog::OnCancel ();
  229. }
  230. }
  231. STDMETHODIMP CBurnDlg::Create (/*[in]*/ HWND hWndParent, /*[out, retval]*/ HWND * phWnd)
  232. {
  233. *phWnd = CreateWindow ("BUTTON",
  234. "This is a test button!",
  235. WS_CHILD|WS_VISIBLE|BS_MULTILINE,
  236. 0, 0, 10, 10,
  237. hWndParent,
  238. (HMENU) 9999,
  239. AfxGetResourceHandle (),
  240. NULL);
  241. return S_OK;
  242. }
  243. STDMETHODIMP CBurnDlg::get_MinSize (/*[out, retval]*/ SIZE * pSize)
  244. {
  245. *pSize = CSize (50, 50);
  246. return S_OK;
  247. }
  248. STDMETHODIMP CBurnDlg::get_MaxSize (/*[out, retval]*/ SIZE * pSize)
  249. {
  250. *pSize = CSize (150, INT_MAX);
  251. return S_OK;
  252. }