home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / CMNCTRL.PAK / TOOLPAGE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.9 KB  |  162 lines

  1. // ToolPage.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "ctrldemo.h"
  16. #include "toolbar1.h"
  17. #include "toolbar2.h"
  18. #include "ToolPage.h"
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CToolBarCtrlPage property page
  28.  
  29. IMPLEMENT_DYNCREATE(CToolBarCtrlPage, CPropertyPage)
  30.  
  31. CToolBarCtrlPage::CToolBarCtrlPage() : CPropertyPage(CToolBarCtrlPage::IDD)
  32. {
  33.     //{{AFX_DATA_INIT(CToolBarCtrlPage)
  34.     m_bAltDrag = FALSE;
  35.     //}}AFX_DATA_INIT
  36. }
  37.  
  38. CToolBarCtrlPage::~CToolBarCtrlPage()
  39. {
  40. }
  41.  
  42. void CToolBarCtrlPage::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CPropertyPage::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CToolBarCtrlPage)
  46.     DDX_Check(pDX, IDC_ALTDRAG, m_bAltDrag);
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50.  
  51. BEGIN_MESSAGE_MAP(CToolBarCtrlPage, CPropertyPage)
  52.     //{{AFX_MSG_MAP(CToolBarCtrlPage)
  53.     ON_BN_CLICKED(IDC_ALTDRAG, OnAltdrag)
  54.     //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58.  
  59. BOOL CToolBarCtrlPage::OnInitDialog() 
  60. {
  61.  
  62.     CPropertyPage::OnInitDialog();
  63.  
  64.  
  65.     m_StandardBar.Create(WS_BORDER | WS_VISIBLE | WS_CHILD 
  66.             | CCS_TOP | CCS_ADJUSTABLE | TBSTYLE_TOOLTIPS, 
  67.         CRect(0,0,0,0),this, IDR_STANDARDBAR);
  68.     
  69.     m_PaletteBar.Create(WS_BORDER | WS_VISIBLE | WS_CHILD
  70.             | CCS_BOTTOM | TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS,
  71.         CRect(0,0,0,0),this, IDR_PALETTEBAR);
  72.  
  73.     m_StandardBar.AutoSize();
  74.     m_PaletteBar.AutoSize();
  75.  
  76.     m_ToolTip.Create(this);
  77.  
  78.     CString cstrToolTip;
  79.     CWnd *pWnd;
  80.     CRect rect;
  81.  
  82.     // Setup the tooltip control for tooltips with the static controls
  83.     for (int nIndex = ID_TOOLBARSTYLE; nIndex <= ID_TBSTYLETOOLTIPS2; nIndex++)
  84.     {
  85.         cstrToolTip.LoadString(nIndex);
  86.  
  87.         VERIFY(pWnd = GetDlgItem(nIndex));
  88.         
  89.         pWnd->GetWindowRect(&rect);
  90.         ScreenToClient(&rect);
  91.  
  92.         m_ToolTip.AddTool(this, (LPCTSTR)cstrToolTip, &rect, nIndex);
  93.     }
  94.  
  95.     m_ToolTip.Activate(TRUE);
  96.  
  97.     return TRUE;  // return TRUE unless you set the focus to a control
  98.                   // EXCEPTION: OCX Property Pages should return FALSE
  99. }
  100.  
  101. void CToolBarCtrlPage::ChangeCtrlStyle(long lStyle, BOOL bSetStyle)
  102. {
  103.     long    lStyleOld;
  104.  
  105.     lStyleOld = GetWindowLong( m_StandardBar.GetSafeHwnd(), GWL_STYLE );
  106.     if ( bSetStyle )
  107.         lStyleOld |= lStyle;
  108.     else
  109.         lStyleOld &= ~lStyle;
  110.  
  111.     SetWindowLong( m_StandardBar.GetSafeHwnd(), GWL_STYLE, lStyleOld );
  112.     m_StandardBar.SetWindowPos( NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
  113.  
  114. }
  115.  
  116. // CToolBarCtrlPage message handlers
  117.  
  118. void CToolBarCtrlPage::OnToolbarCommand(UINT nID) 
  119. {
  120.     CString string;
  121.     string.LoadString(nID);
  122.  
  123.     // cast from CString to (LPCSTR) is necessary
  124.     TRACE(_T("User has Pressed : %s\n"), (LPCTSTR)string);
  125. }
  126.  
  127.  
  128. void CToolBarCtrlPage::OnAltdrag() 
  129. {
  130.     UpdateData();
  131.     ChangeCtrlStyle(TBSTYLE_ALTDRAG, m_bAltDrag);
  132. }
  133.  
  134.  
  135. LRESULT CToolBarCtrlPage::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  136. {
  137.     // We need to pass these messages to the tooltip for it to determine
  138.     // the position of the mouse
  139.  
  140.     switch (message)
  141.     {
  142.     case WM_LBUTTONDOWN:
  143.     case WM_RBUTTONDOWN:
  144.     case WM_MBUTTONDOWN:
  145.     case WM_LBUTTONUP:
  146.     case WM_MBUTTONUP:
  147.     case WM_RBUTTONUP:
  148.     case WM_MOUSEMOVE:
  149.         {
  150.             MSG msg;
  151.             msg.hwnd = m_hWnd;
  152.             msg.message = message;
  153.             msg.wParam = wParam;
  154.             msg.lParam = lParam;
  155.  
  156.             m_ToolTip.RelayEvent(&msg);
  157.         }
  158.     }
  159.  
  160.     return CPropertyPage::WindowProc(message,wParam,lParam);
  161. }
  162.