NVAPIExampleDlg.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 / NVAPIExample
  10. |*
  11. |* PROGRAM: CNVAPIExampleDlg.cpp
  12. |*
  13. |* PURPOSE: Implementation of the main property sheet like dialog.
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "NVAPIExample.h"
  17. #include "NVAPIExampleDlg.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. // This is a standard about box.
  24. //
  25. class CAboutDlg : public CDialog
  26. {
  27. public:
  28. CAboutDlg();
  29. // Dialog Data
  30. //{{AFX_DATA(CAboutDlg)
  31. enum { IDD = IDD_ABOUTBOX };
  32. //}}AFX_DATA
  33. // ClassWizard generated virtual function overrides
  34. //{{AFX_VIRTUAL(CAboutDlg)
  35. protected:
  36. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  37. //}}AFX_VIRTUAL
  38. // Implementation
  39. protected:
  40. //{{AFX_MSG(CAboutDlg)
  41. //}}AFX_MSG
  42. DECLARE_MESSAGE_MAP()
  43. };
  44. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  45. {
  46. //{{AFX_DATA_INIT(CAboutDlg)
  47. //}}AFX_DATA_INIT
  48. }
  49. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CAboutDlg)
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  56. //{{AFX_MSG_MAP(CAboutDlg)
  57. // No message handlers
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. // Disable the warning about "this" usage member variable initialization
  61. // in the constructor.
  62. //
  63. #pragma warning(disable:4355)
  64. CNVAPIExampleDlg::CNVAPIExampleDlg(CWnd* pParent /*=NULL*/)
  65. : CSheet(CNVAPIExampleDlg::IDD, pParent)
  66. , m_iCurrentPage (-1)
  67. , m_pageFirst (this)
  68. , m_pageSecond (this)
  69. , m_pageThird (this)
  70. , m_pagePreview (this)
  71. , m_pageExport(this)
  72. , m_iPageCount (sizeof (m_pPages)/sizeof (m_pPages[0]))
  73. {
  74. //{{AFX_DATA_INIT(CNVAPIExampleDlg)
  75. // NOTE: the ClassWizard will add member initialization here
  76. //}}AFX_DATA_INIT
  77. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  78. m_hIcon = AfxGetApp()->LoadIcon(IDI_MAIN);
  79. // Initialize the pages array.
  80. //
  81. m_pPages[0] = &m_pageFirst;
  82. m_pPages[1] = &m_pageSecond;
  83. m_pPages[2] = &m_pageThird;
  84. m_pPages[3] = &m_pagePreview;
  85. m_pPages[4] = &m_pageExport;
  86. }
  87. void CNVAPIExampleDlg::DoDataExchange(CDataExchange* pDX)
  88. {
  89. CSheet::DoDataExchange(pDX);
  90. //{{AFX_DATA_MAP(CNVAPIExampleDlg)
  91. // NOTE: the ClassWizard will add DDX and DDV calls here
  92. //}}AFX_DATA_MAP
  93. }
  94. BEGIN_MESSAGE_MAP(CNVAPIExampleDlg, CSheet)
  95. //{{AFX_MSG_MAP(CNVAPIExampleDlg)
  96. ON_WM_SYSCOMMAND()
  97. ON_WM_PAINT()
  98. ON_WM_QUERYDRAGICON()
  99. ON_BN_CLICKED(IDC_ABOUT, OnAbout)
  100. ON_WM_CLOSE()
  101. //}}AFX_MSG_MAP
  102. ON_MESSAGE(UM_NERO_USER_DIALOG, OnNeroUserDialog)
  103. ON_MESSAGE(UM_NERO_IDLE_CALLBACK, OnNeroIdleCallback)
  104. END_MESSAGE_MAP()
  105. BOOL CNVAPIExampleDlg::OnInitDialog()
  106. {
  107. CSheet::OnInitDialog();
  108. // Add "About..." menu item to system menu.
  109. // IDM_ABOUTBOX must be in the system command range.
  110. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  111. ASSERT(IDM_ABOUTBOX < 0xF000);
  112. CMenu* pSysMenu = GetSystemMenu(FALSE);
  113. if (pSysMenu != NULL)
  114. {
  115. CString strAboutMenu;
  116. strAboutMenu.LoadString(IDS_ABOUTBOX);
  117. if (!strAboutMenu.IsEmpty())
  118. {
  119. pSysMenu->AppendMenu(MF_SEPARATOR);
  120. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  121. }
  122. }
  123. // Set the icon for this dialog. The framework does this automatically
  124. // when the application's main window is not a dialog
  125. SetIcon(m_hIcon, TRUE); // Set big icon
  126. SetIcon(m_hIcon, FALSE); // Set small icon
  127. // Get the rectangle of the child page dialog placeholder.
  128. //
  129. CRect rcPlaceholder;
  130. GetDlgItem (IDC_PAGE_PLACEHOLDER)->GetWindowRect (&rcPlaceholder);
  131. ScreenToClient (&rcPlaceholder);
  132. // Create and reposition all child pages using the placeholder
  133. // rectangle.
  134. //
  135. for (int i = 0; i < m_iPageCount; i ++)
  136. {
  137. VERIFY (m_pPages[i]->Create ());
  138. m_pPages[i]->MoveWindow (&rcPlaceholder);
  139. }
  140. // Once everything is created, switch to the zero-th page.
  141. //
  142. SwitchPage (0);
  143. return TRUE; // return TRUE unless you set the focus to a control
  144. }
  145. void CNVAPIExampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  146. {
  147. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  148. {
  149. CAboutDlg dlgAbout;
  150. dlgAbout.DoModal();
  151. }
  152. else
  153. {
  154. CSheet::OnSysCommand(nID, lParam);
  155. }
  156. }
  157. // If you add a minimize button to your dialog, you will need the code below
  158. // to draw the icon. For MFC applications using the document/view model,
  159. // this is automatically done for you by the framework.
  160. void CNVAPIExampleDlg::OnPaint()
  161. {
  162. if (IsIconic())
  163. {
  164. CPaintDC dc(this); // device context for painting
  165. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  166. // Center icon in client rectangle
  167. int cxIcon = GetSystemMetrics(SM_CXICON);
  168. int cyIcon = GetSystemMetrics(SM_CYICON);
  169. CRect rect;
  170. GetClientRect(&rect);
  171. int x = (rect.Width() - cxIcon + 1) / 2;
  172. int y = (rect.Height() - cyIcon + 1) / 2;
  173. // Draw the icon
  174. dc.DrawIcon(x, y, m_hIcon);
  175. }
  176. else
  177. {
  178. CSheet::OnPaint();
  179. }
  180. }
  181. // The system calls this to obtain the cursor to display while the user drags
  182. // the minimized window.
  183. HCURSOR CNVAPIExampleDlg::OnQueryDragIcon()
  184. {
  185. return (HCURSOR) m_hIcon;
  186. }
  187. void CNVAPIExampleDlg::OnAbout()
  188. {
  189. CAboutDlg dlg;
  190. dlg.DoModal ();
  191. }
  192. // OK button is actually a Next button.
  193. //
  194. void CNVAPIExampleDlg::OnOK()
  195. {
  196. // First ask the page if it wants to handle the click and only act
  197. // if not.
  198. //
  199. if (!m_pPages[m_iCurrentPage]->OnNext ())
  200. {
  201. // Go to the next page unless we are at the end.
  202. //
  203. if (m_iCurrentPage < m_iPageCount - 1)
  204. {
  205. SwitchPage (m_iCurrentPage + 1);
  206. }
  207. else
  208. {
  209. // If at the end, exit. The user clicked 'Finish'.
  210. //
  211. CSheet::OnOK();
  212. }
  213. }
  214. }
  215. // Cancel button is actually a Back button.
  216. //
  217. void CNVAPIExampleDlg::OnCancel()
  218. {
  219. // First ask the page if it wants to handle the click and only act
  220. // if not.
  221. //
  222. if (!m_pPages[m_iCurrentPage]->OnBack ())
  223. {
  224. // Go to the previous page unless we are at the beginning.
  225. //
  226. if (0 < m_iCurrentPage)
  227. {
  228. SwitchPage (m_iCurrentPage - 1);
  229. }
  230. }
  231. }
  232. // A method used for page switching.
  233. //
  234. void CNVAPIExampleDlg::SwitchPage (int iNewPage)
  235. {
  236. // Get the pointers to CPage for ease of use.
  237. //
  238. CPage * pOldPage = m_iCurrentPage >= 0? m_pPages[m_iCurrentPage]: NULL;
  239. CPage * pNewPage = m_pPages[iNewPage];
  240. // Load the string for 'Back', set it to the button and enable it
  241. // as appropriate.
  242. //
  243. CString str;
  244. str.LoadString (IDS_BUTTON_BACK);
  245. GetDlgItem (IDCANCEL)->SetWindowText (str);
  246. GetDlgItem (IDCANCEL)->EnableWindow (iNewPage > 0);
  247. // Load the string for 'Finish' or 'Next' as appropriate and always
  248. // enable the button (this is to make sure if any of the pages left it
  249. // disabled.
  250. //
  251. str.LoadString (iNewPage == m_iPageCount-1? IDS_BUTTON_FINISH: IDS_BUTTON_NEXT);
  252. GetDlgItem (IDOK)->SetWindowText (str);
  253. GetDlgItem (IDOK)->EnableWindow (iNewPage < 3);
  254. bool bForward = m_iCurrentPage < iNewPage;
  255. // Now, show the new page, then hide the old one.
  256. //
  257. pNewPage->ShowWindow (SW_SHOW);
  258. if (pOldPage != NULL)
  259. {
  260. pOldPage->OnChangeState (false, bForward);
  261. pOldPage->ShowWindow (SW_HIDE);
  262. }
  263. pNewPage->UpdateWindow ();
  264. pNewPage->OnChangeState (true, bForward);
  265. m_iCurrentPage = iNewPage;
  266. }
  267. void CNVAPIExampleDlg::OnClose()
  268. {
  269. // If X was clicked, just end the dialog.
  270. //
  271. EndDialog (IDCANCEL);
  272. }
  273. DWORD CNVAPIExampleDlg::GetCommonPageData (void)
  274. {
  275. return (DWORD) &m_pageData;
  276. }
  277. // This is a message handler for our user message UM_NERO_USER_DIALOG. We
  278. // have no interest in handling it. Instead, we forward it to the current
  279. // page.
  280. //
  281. LRESULT CNVAPIExampleDlg::OnNeroUserDialog (WPARAM wParam, LPARAM lParam)
  282. {
  283. return m_pPages[m_iCurrentPage]->SendMessage (UM_NERO_USER_DIALOG, wParam, lParam);
  284. }
  285. // This is a message handler for our user message UM_NERO_IDLE_CALLBACK. We
  286. // have no interest in handling it. Instead, we forward it to the current
  287. // page.
  288. //
  289. LRESULT CNVAPIExampleDlg::OnNeroIdleCallback (WPARAM wParam, LPARAM lParam)
  290. {
  291. return m_pPages[m_iCurrentPage]->SendMessage (UM_NERO_IDLE_CALLBACK);
  292. }