B14Dlg.cpp
上传用户:szxyd1688
上传日期:2007-06-08
资源大小:1440k
文件大小:5k
源码类别:

屏幕保护

开发平台:

Visual C++

  1. // B14Dlg.cpp : implementation file
  2. //
  3. #include "StdAfx.h"
  4. #include "ScreenSaverWnd.h"
  5. #include "B14Dlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. IMPLEMENT_DYNAMIC(CB14Dlg, CDialog)
  13. // MFC's normal processing would have CDialog and CWnd handle any messages
  14. // not handled by the CScreenSaverDlg.  Some are not appropriate for a
  15. // screen saver's configuration dialog, so we skip CDialog and CWnd in the
  16. // line below, and have all unhandled messages go to the CCmdTarget.
  17. // The WindowProc() below will forward the reasonable messages to CDialog.
  18. //
  19. BEGIN_MESSAGE_MAP(CB14Dlg, CCmdTarget)
  20. //{{AFX_MSG_MAP(CScreenSaverDlg)
  21. ON_WM_NCDESTROY()
  22. ON_WM_CREATE()
  23. //}}AFX_MSG_MAP
  24. ON_COMMAND(IDOK, OnOK)
  25. ON_COMMAND(IDCANCEL, OnCancel)
  26. ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
  27. END_MESSAGE_MAP()
  28. // There should be only one CScreenSaverDlg instantiated at a time.
  29. // The helper function AfxGetScreenSaverDlg() returns this pointer.
  30. //
  31. /* static */ CB14Dlg* CB14Dlg::sm_pTheConfigureDialog = NULL;
  32. CB14Dlg::CB14Dlg()
  33. {
  34. ASSERT(!sm_pTheConfigureDialog);
  35. sm_pTheConfigureDialog = this;
  36. }
  37. CB14Dlg::~CB14Dlg()
  38. {
  39. sm_pTheConfigureDialog = NULL;
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. void CB14Dlg::OnNcDestroy()
  43. {
  44. CDialog::OnNcDestroy();
  45. }
  46. BOOL CB14Dlg::OnInitDialog()
  47. {
  48. if (AfxGetScreenSaverWnd())
  49. AfxGetScreenSaverWnd()->RestoreOptions();
  50. return CDialog::OnInitDialog();
  51. }
  52. int CB14Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  53. {
  54. if (CDialog::OnCreate(lpCreateStruct) == -1)
  55. return -1;
  56. #ifdef _DEBUG
  57. // Screen savers should be TOPMOST to block out any other windows,
  58. // such as other topmost windows created previously.  However, if you
  59. // are trying to debug a screen saver, it can get in the way.
  60. // We remove the topmost status from this window only if we're _DEBUG.
  61. // 
  62. SetWindowPos(&CWnd::wndNoTopMost,
  63. 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  64. #endif
  65. return 0;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. //
  69. // The default message routing is not built to deal with screen saver
  70. // dialogs.  This avoids the default dialog proc from handling anything we
  71. // don't handle.
  72. //
  73. LRESULT CB14Dlg::DefWindowProc(UINT uMsg,WPARAM wParam,LPARAM lParam)
  74. {
  75. return 0L;
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // ::ScreenSaverConfigureDialog():
  79. // This API must be exported to be recognized as a configurable screen
  80. // saver.  This serves as the dialog message proc called by Windows to
  81. // display the configuration dialog for the screen saver.  Not all messages
  82. // that go to the dialog actually get sent to our proc.
  83. //
  84. BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg,
  85.                                        WPARAM wParam, LPARAM lParam)
  86. {
  87. // There should be one global instance of a CB14Dlg derivative.
  88. ASSERT(AfxGetScreenSaverDialog());
  89. if (!AfxGetScreenSaverDialog())
  90. return 0L;
  91. if (!AfxGetScreenSaverDialog()->m_hWnd)
  92. AfxGetScreenSaverDialog()->Attach(hDlg);
  93. // MFC does a lot of helpful but nonstandard things with WM_INITDIALOG.
  94. //
  95. // Since a screen saver's configuration dialog proc is dictated to us,
  96. // we need to manually perform the ->OnInitDialog() call ourselves.
  97. //
  98. // This is equivalent to MFC4.2's ::AfxDlgProc() [which is not exported
  99. // nor used by the sanctioned exported public ::AfxCallWndProc()
  100. // function].
  101. //
  102. LRESULT lResult;
  103. if (uMsg == WM_INITDIALOG)
  104. {
  105. // special case for WM_INITDIALOG
  106. CDialog* pDlg =
  107. DYNAMIC_DOWNCAST(CDialog,
  108. CWnd::FromHandlePermanent(hDlg));
  109. if (pDlg != NULL)
  110. lResult = pDlg->OnInitDialog();
  111. else
  112. lResult = 1;
  113. }
  114. else
  115. {
  116. lResult =
  117. AfxCallWndProc(
  118. AfxGetScreenSaverDialog(),
  119. AfxGetScreenSaverDialog()->m_hWnd,
  120.         uMsg, wParam, lParam);
  121. }
  122. if (uMsg == WM_NCDESTROY)
  123. {
  124. ASSERT(!AfxGetScreenSaverDialog() ||
  125.        !AfxGetScreenSaverDialog()->m_hWnd);
  126. }
  127. return lResult;
  128. }
  129. // ::RegisterDialogClasses():
  130. // This API must be exported to be recognized as a configurable screen
  131. // saver.  It is called upon startup to register any WNDCLASS structures
  132. // that would later be necessary to display a configuration dialog.
  133. //
  134. BOOL WINAPI RegisterDialogClasses(HANDLE hInstance)
  135. {
  136. // We rely on the default registered window class used by MFC
  137. // dialogs.  Therefore, we have nothing to do here.
  138. //
  139. return TRUE;
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. LRESULT CB14Dlg::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  143. {
  144. return CDialog::WindowProc(uMsg, wParam, lParam);
  145. }