SCREENSAFEDLG.CPP
上传用户:trhysrzt
上传日期:2022-03-19
资源大小:9454k
文件大小:3k
源码类别:

屏幕保护

开发平台:

Visual C++

  1. // ScreenSafeDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ScreenSafe.h"
  5. #include "ScreenSafeDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // CAboutDlg dialog used for App About
  10. class CAboutDlg : public CDialog
  11. {
  12. public:
  13. CAboutDlg();
  14. // Dialog Data
  15. enum { IDD = IDD_ABOUTBOX };
  16. protected:
  17. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  18. // Implementation
  19. protected:
  20. DECLARE_MESSAGE_MAP()
  21. };
  22. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  23. {
  24. }
  25. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. }
  29. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  30. END_MESSAGE_MAP()
  31. // CScreenSafeDlg dialog
  32. CScreenSafeDlg::CScreenSafeDlg(CWnd* pParent /*=NULL*/)
  33. : CDialog(CScreenSafeDlg::IDD, pParent)
  34. {
  35. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  36. }
  37. void CScreenSafeDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. }
  41. BEGIN_MESSAGE_MAP(CScreenSafeDlg, CDialog)
  42. ON_WM_SYSCOMMAND()
  43. ON_WM_PAINT()
  44. ON_WM_QUERYDRAGICON()
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. // CScreenSafeDlg message handlers
  48. BOOL CScreenSafeDlg::OnInitDialog()
  49. {
  50. CDialog::OnInitDialog();
  51. // Add "About..." menu item to system menu.
  52. // IDM_ABOUTBOX must be in the system command range.
  53. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  54. ASSERT(IDM_ABOUTBOX < 0xF000);
  55. CMenu* pSysMenu = GetSystemMenu(FALSE);
  56. if (pSysMenu != NULL)
  57. {
  58. CString strAboutMenu;
  59. strAboutMenu.LoadString(IDS_ABOUTBOX);
  60. if (!strAboutMenu.IsEmpty())
  61. {
  62. pSysMenu->AppendMenu(MF_SEPARATOR);
  63. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  64. }
  65. }
  66. // Set the icon for this dialog.  The framework does this automatically
  67. //  when the application's main window is not a dialog
  68. SetIcon(m_hIcon, TRUE); // Set big icon
  69. SetIcon(m_hIcon, FALSE); // Set small icon
  70. // TODO: Add extra initialization here
  71. return TRUE;  // return TRUE  unless you set the focus to a control
  72. }
  73. void CScreenSafeDlg::OnSysCommand(UINT nID, LPARAM lParam)
  74. {
  75. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  76. {
  77. CAboutDlg dlgAbout;
  78. dlgAbout.DoModal();
  79. }
  80. else
  81. {
  82. CDialog::OnSysCommand(nID, lParam);
  83. }
  84. }
  85. // If you add a minimize button to your dialog, you will need the code below
  86. //  to draw the icon.  For MFC applications using the document/view model,
  87. //  this is automatically done for you by the framework.
  88. void CScreenSafeDlg::OnPaint() 
  89. {
  90. if (IsIconic())
  91. {
  92. CPaintDC dc(this); // device context for painting
  93. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  94. // Center icon in client rectangle
  95. int cxIcon = GetSystemMetrics(SM_CXICON);
  96. int cyIcon = GetSystemMetrics(SM_CYICON);
  97. CRect rect;
  98. GetClientRect(&rect);
  99. int x = (rect.Width() - cxIcon + 1) / 2;
  100. int y = (rect.Height() - cyIcon + 1) / 2;
  101. // Draw the icon
  102. dc.DrawIcon(x, y, m_hIcon);
  103. }
  104. else
  105. {
  106. CDialog::OnPaint();
  107. }
  108. }
  109. // The system calls this function to obtain the cursor to display while the user drags
  110. //  the minimized window.
  111. HCURSOR CScreenSafeDlg::OnQueryDragIcon()
  112. {
  113. return static_cast<HCURSOR>(m_hIcon);
  114. }