home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / TIPS.ZIP / prj / ToolTips / ToolTipsDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-14  |  4.3 KB  |  178 lines

  1. // ToolTipsDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ToolTips.h"
  6. #include "ToolTipsDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CToolTipDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27.     // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CAboutDlg)
  29.     protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //}}AFX_VIRTUAL
  32.  
  33. // Implementation
  34. protected:
  35.     //{{AFX_MSG(CAboutDlg)
  36.     //}}AFX_MSG
  37.     DECLARE_MESSAGE_MAP()
  38. };
  39.  
  40. CAboutDlg::CAboutDlg() : CToolTipDialog(CAboutDlg::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CAboutDlg)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CToolTipDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CAboutDlg)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CToolTipDialog)
  54.     //{{AFX_MSG_MAP(CAboutDlg)
  55.         // No message handlers
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CToolTipsDlg dialog
  61.  
  62. CToolTipsDlg::CToolTipsDlg(CWnd* pParent /*=NULL*/)
  63.     : CToolTipDialog(CToolTipsDlg::IDD, pParent)
  64. {
  65.     //{{AFX_DATA_INIT(CToolTipsDlg)
  66.     m_bEnableToolTips = TRUE;
  67.     //}}AFX_DATA_INIT
  68.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  69.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  70. }
  71.  
  72. void CToolTipsDlg::DoDataExchange(CDataExchange* pDX)
  73. {
  74.     CToolTipDialog::DoDataExchange(pDX);
  75.     //{{AFX_DATA_MAP(CToolTipsDlg)
  76.     DDX_Check(pDX, IDC_CHECK_SHOWTOOLTIPS, m_bEnableToolTips);
  77.     //}}AFX_DATA_MAP
  78. }
  79.  
  80. BEGIN_MESSAGE_MAP(CToolTipsDlg, CToolTipDialog)
  81.     //{{AFX_MSG_MAP(CToolTipsDlg)
  82.     ON_WM_SYSCOMMAND()
  83.     ON_WM_PAINT()
  84.     ON_WM_QUERYDRAGICON()
  85.     ON_BN_CLICKED(IDC_CHECK_SHOWTOOLTIPS, OnCheckShowtooltips)
  86.     //}}AFX_MSG_MAP
  87. END_MESSAGE_MAP()
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CToolTipsDlg message handlers
  91.  
  92. BOOL CToolTipsDlg::OnInitDialog()
  93. {
  94.     CToolTipDialog::OnInitDialog();
  95.  
  96.     // Add "About..." menu item to system menu.
  97.  
  98.     // IDM_ABOUTBOX must be in the system command range.
  99.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  100.     ASSERT(IDM_ABOUTBOX < 0xF000);
  101.  
  102.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  103.     if (pSysMenu != NULL)
  104.     {
  105.         CString strAboutMenu;
  106.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  107.         if (!strAboutMenu.IsEmpty())
  108.         {
  109.             pSysMenu->AppendMenu(MF_SEPARATOR);
  110.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  111.         }
  112.     }
  113.  
  114.     // Set the icon for this dialog.  The framework does this automatically
  115.     //  when the application's main window is not a dialog
  116.     SetIcon(m_hIcon, TRUE);            // Set big icon
  117.     SetIcon(m_hIcon, FALSE);        // Set small icon
  118.     
  119.     // TODO: Add extra initialization here
  120.     
  121.     return TRUE;  // return TRUE  unless you set the focus to a control
  122. }
  123.  
  124. void CToolTipsDlg::OnSysCommand(UINT nID, LPARAM lParam)
  125. {
  126.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  127.     {
  128.         CAboutDlg dlgAbout;
  129.         dlgAbout.DoModal();
  130.     }
  131.     else
  132.     {
  133.         CToolTipDialog::OnSysCommand(nID, lParam);
  134.     }
  135. }
  136.  
  137. // If you add a minimize button to your dialog, you will need the code below
  138. //  to draw the icon.  For MFC applications using the document/view model,
  139. //  this is automatically done for you by the framework.
  140.  
  141. void CToolTipsDlg::OnPaint() 
  142. {
  143.     if (IsIconic())
  144.     {
  145.         CPaintDC dc(this); // device context for painting
  146.  
  147.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  148.  
  149.         // Center icon in client rectangle
  150.         int cxIcon = GetSystemMetrics(SM_CXICON);
  151.         int cyIcon = GetSystemMetrics(SM_CYICON);
  152.         CRect rect;
  153.         GetClientRect(&rect);
  154.         int x = (rect.Width() - cxIcon + 1) / 2;
  155.         int y = (rect.Height() - cyIcon + 1) / 2;
  156.  
  157.         // Draw the icon
  158.         dc.DrawIcon(x, y, m_hIcon);
  159.     }
  160.     else
  161.     {
  162.         CToolTipDialog::OnPaint();
  163.     }
  164. }
  165.  
  166. // The system calls this to obtain the cursor to display while the user drags
  167. //  the minimized window.
  168. HCURSOR CToolTipsDlg::OnQueryDragIcon()
  169. {
  170.     return (HCURSOR) m_hIcon;
  171. }
  172.  
  173. void CToolTipsDlg::OnCheckShowtooltips() 
  174. {
  175.     UpdateData(TRUE);
  176.     CToolTipDialog::EnableToolTips(m_bEnableToolTips);
  177. }
  178.