home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ctlhtmlc / controls.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-07  |  9.4 KB  |  356 lines

  1. /*---------------------------------------------------------------------------*\
  2.  | Controls.cpp  - CtlHTML(tm) Control Library Test Program                  |
  3.  |                 Windmill Point Software, Alburg, VT 05440                 |
  4.  |                 Copyright (c) 1999, Windmill Point Software               |
  5.  |                 All Rights Reserved.                                      |
  6. \*---------------------------------------------------------------------------*/
  7.  
  8. #include "stdafx.h"
  9. #include "CtlHTML Demo.h"
  10. #include "DevUI.h"
  11. #include "..\CtlHtml.h"
  12. #include "Controls.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20.  
  21. // example partial ownerdraw callback function
  22. BOOL MyPartialOwnerDraw (HWND hWnd, HDC hDC, LPSTR szText, RECT *pClientRect, RECT *pTextRect, 
  23.                          int textStyle, BOOL isPushButton, BOOL hasFocus, BOOL isDown, BOOL calcSize)
  24. {
  25.    int id;
  26.  
  27.    id = GetDlgCtrlID(hWnd);
  28.    if (id == IDC_OWNDERDRAW)
  29.    {
  30.       HBRUSH   hBrush, hOldBrush;
  31.       HPEN     hPen,   hOldPen;
  32.  
  33.       // in this case, the ownerdraw doesn't change the size
  34.       if (calcSize)
  35.          return FALSE;
  36.  
  37.       // set the brush and pen
  38.       if (IsWindowEnabled(hWnd))
  39.       {
  40.          hBrush = CreateSolidBrush(RGB(0, 0, 0xc0));
  41.          hPen   = (HPEN)GetStockObject(BLACK_PEN);
  42.       }
  43.       else
  44.       {
  45.          hBrush = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
  46.          hPen   = CreatePen(PS_SOLID, 1, RGB(0, 0, 0x40));
  47.       }
  48.       hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
  49.       hOldPen   = (HPEN)SelectObject(hDC, hPen);
  50.  
  51.       // do drawing
  52.       if (isPushButton)
  53.       {
  54.          if (isDown)
  55.             Rectangle(hDC, pTextRect->left + 5, pTextRect->top + 5, pTextRect->right - 3, pTextRect->bottom - 3);
  56.          else
  57.             Rectangle(hDC, pTextRect->left + 4, pTextRect->top + 4, pTextRect->right - 4, pTextRect->bottom - 4);
  58.       }
  59.       else
  60.          Rectangle(hDC, pTextRect->left, pTextRect->top, pTextRect->right, pTextRect->bottom);
  61.  
  62.       // be sure to restore all GDI objects
  63.       SelectObject(hDC, hOldBrush);
  64.       SelectObject(hDC, hOldPen);
  65.  
  66.       // set DC for text drawing
  67.       SetBkMode(hDC, TRANSPARENT);
  68.       if (IsWindowEnabled(hWnd))
  69.          SetTextColor(hDC, RGB(0xff, 0xff, 0xff));    // use white text on a blue background
  70.  
  71.       // return FALSE to draw the text
  72.       return FALSE;
  73.    }
  74.    else if (id == IDC_OWNERDRAWRB1 || id == IDC_OWNERDRAWRB2 || id == IDC_OWNERDRAWRB3)
  75.    {
  76.       // in this case, the ownerdraw doesn't change the size
  77.       if (calcSize)
  78.          return TRUE;
  79.  
  80.       COLORREF color;
  81.       HBRUSH   hBrush, hOldBrush;
  82.       HPEN     hPen,   hOldPen;
  83.  
  84.       // set the brush and pen
  85.       if (IsWindowEnabled(hWnd))
  86.       {
  87.          sscanf(szText, "%x", &color);
  88.          hBrush = CreateSolidBrush(color);
  89.       }
  90.       else
  91.          hBrush = GetSysColorBrush(COLOR_GRAYTEXT); // use same color as disabled text
  92.       hPen      = (HPEN)GetStockObject(BLACK_PEN);
  93.       hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
  94.       hOldPen   = (HPEN)SelectObject(hDC, hPen);
  95.  
  96.       // do drawing
  97.       if (isPushButton)
  98.       {
  99.          if (isDown)
  100.             Rectangle(hDC, pTextRect->left + 5, pTextRect->top + 5, pTextRect->right - 3, pTextRect->bottom - 3);
  101.          else
  102.             Rectangle(hDC, pTextRect->left + 4, pTextRect->top + 4, pTextRect->right - 4, pTextRect->bottom - 4);
  103.       }
  104.       else
  105.          Rectangle(hDC, pTextRect->left, pTextRect->top, pTextRect->right, pTextRect->bottom);
  106.  
  107.       // be sure to restore all GDI objects
  108.       SelectObject(hDC, hOldBrush);
  109.       SelectObject(hDC, hOldPen);
  110.  
  111.       // draw the focus rect
  112.       if (hasFocus)
  113.       {
  114.          RECT     focusRect;
  115.  
  116.          focusRect = *pTextRect;
  117.          InflateRect(&focusRect, -2, -2);
  118.          DrawFocusRect(hDC, &focusRect);
  119.       }
  120.  
  121.       // return TRUE to not draw the text
  122.       return TRUE;
  123.    }
  124.    else
  125.       return FALSE;
  126. }
  127.  
  128.  
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CButtons property page
  131.  
  132. IMPLEMENT_DYNCREATE(CButtons, CPropertyPage)
  133.  
  134. BEGIN_MESSAGE_MAP(CButtons, CPropertyPage)
  135.     //{{AFX_MSG_MAP(CButtons)
  136.     ON_WM_ACTIVATE()
  137.     //}}AFX_MSG_MAP
  138. END_MESSAGE_MAP()
  139.  
  140. CButtons::CButtons() : CPropertyPage(CButtons::IDD)
  141. {
  142.     //{{AFX_DATA_INIT(CButtons)
  143.     //}}AFX_DATA_INIT
  144. }
  145.  
  146. CButtons::~CButtons()
  147. {
  148. }
  149.  
  150. void CButtons::DoDataExchange(CDataExchange* pDX)
  151. {
  152.     CPropertyPage::DoDataExchange(pDX);
  153.     //{{AFX_DATA_MAP(CButtons)
  154.     //}}AFX_DATA_MAP
  155. }
  156.     
  157. BOOL CButtons::OnInitDialog() 
  158. {
  159.     CPropertyPage::OnInitDialog();
  160.    CtlHTMLSubclassDialog(m_hWnd);
  161.     return TRUE;
  162. }
  163.  
  164. void CButtons::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  165. {
  166.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  167.    if (DisableControls)
  168.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  169. }
  170.  
  171.  
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CCheckBoxes property page
  174.  
  175. IMPLEMENT_DYNCREATE(CCheckBoxes, CPropertyPage)
  176.  
  177. BEGIN_MESSAGE_MAP(CCheckBoxes, CPropertyPage)
  178.     //{{AFX_MSG_MAP(CCheckBoxes)
  179.     ON_WM_ACTIVATE()
  180.     //}}AFX_MSG_MAP
  181. END_MESSAGE_MAP()
  182.  
  183. CCheckBoxes::CCheckBoxes() : CPropertyPage(CCheckBoxes::IDD)
  184. {
  185.     //{{AFX_DATA_INIT(CCheckBoxes)
  186.     //}}AFX_DATA_INIT
  187. }
  188.  
  189. CCheckBoxes::~CCheckBoxes()
  190. {
  191. }
  192.  
  193. void CCheckBoxes::DoDataExchange(CDataExchange* pDX)
  194. {
  195.    BOOL enable = TRUE;
  196.  
  197.     CPropertyPage::DoDataExchange(pDX);
  198.     //{{AFX_DATA_MAP(CCheckBoxes)
  199.     DDX_Check(pDX, IDC_READONLY, enable);
  200.     //}}AFX_DATA_MAP
  201. }
  202.  
  203. BOOL CCheckBoxes::OnInitDialog() 
  204. {
  205.     CPropertyPage::OnInitDialog();
  206.    CtlHTMLSubclassDialog(m_hWnd);
  207.     return TRUE;
  208. }
  209.  
  210. void CCheckBoxes::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  211. {
  212.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  213.    if (DisableControls)
  214.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  215. }
  216.  
  217.  
  218. /////////////////////////////////////////////////////////////////////////////
  219. // CText property page
  220.  
  221. IMPLEMENT_DYNCREATE(CText, CPropertyPage)
  222.  
  223. BEGIN_MESSAGE_MAP(CText, CPropertyPage)
  224.     //{{AFX_MSG_MAP(CText)
  225.     ON_WM_ACTIVATE()
  226.     //}}AFX_MSG_MAP
  227. END_MESSAGE_MAP()
  228.  
  229. CText::CText() : CPropertyPage(CText::IDD)
  230. {
  231.     //{{AFX_DATA_INIT(CText)
  232.     //}}AFX_DATA_INIT
  233. }
  234.  
  235. CText::~CText()
  236. {
  237. }
  238.  
  239. void CText::DoDataExchange(CDataExchange* pDX)
  240. {
  241.     CPropertyPage::DoDataExchange(pDX);
  242.     //{{AFX_DATA_MAP(CText)
  243.     //}}AFX_DATA_MAP
  244. }
  245.  
  246. BOOL CText::OnInitDialog() 
  247. {
  248.     CPropertyPage::OnInitDialog();
  249.  
  250.    CWnd *pWnd;
  251.  
  252.    // Note: Must set edit box text before calling CtlHTMLSubclassDialog, otherwise these controls
  253.    //       will not be subclassed
  254.    if ((pWnd = GetDlgItem(IDC_EDIT1)) != 0)
  255.       pWnd->SetWindowText("<HTML>Left</HTML>");
  256.    if ((pWnd = GetDlgItem(IDC_EDIT2)) != 0)
  257.       pWnd->SetWindowText("<HTML>Center</HTML>");
  258.    if ((pWnd = GetDlgItem(IDC_EDIT3)) != 0)
  259.       pWnd->SetWindowText("<HTML>Right</HTML>");
  260.    if ((pWnd = GetDlgItem(IDC_EDIT4)) != 0)
  261.       pWnd->SetWindowText("<HTML><P align = \"left\">Left attribute</P></HTML>");
  262.    if ((pWnd = GetDlgItem(IDC_EDIT5)) != 0)
  263.       pWnd->SetWindowText("<HTML><P align = \"center\">Center attribute</P></HTML>");
  264.    if ((pWnd = GetDlgItem(IDC_EDIT6)) != 0)
  265.       pWnd->SetWindowText("<HTML><P align = \"right\">Right attribute</P></HTML>");
  266.  
  267.    CtlHTMLSubclassDialog(m_hWnd);
  268.  
  269.     return TRUE;
  270. }
  271.  
  272. void CText::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  273. {
  274.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  275.    if (DisableControls)
  276.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  277. }
  278.  
  279.  
  280. /////////////////////////////////////////////////////////////////////////////
  281. // CControls
  282.  
  283. static int ActivePage = 0;
  284.  
  285. IMPLEMENT_DYNAMIC(CControls, CMcPropertySheet)
  286.  
  287. BEGIN_MESSAGE_MAP(CControls, CMcPropertySheet)
  288.     //{{AFX_MSG_MAP(CControls)
  289.     ON_WM_DESTROY()
  290.     ON_WM_ACTIVATE()
  291.     //}}AFX_MSG_MAP
  292. END_MESSAGE_MAP()
  293.  
  294. CControls::CControls(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  295.     : CMcPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  296. {
  297.    AddPage(&m_Buttons);
  298.    AddPage(&m_CheckBoxes);
  299.    AddPage(&m_Text);
  300. }
  301.  
  302. CControls::CControls(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  303.     : CMcPropertySheet(pszCaption, pParentWnd, iSelectPage)
  304. {
  305.    AddPage(&m_Buttons);
  306.    AddPage(&m_CheckBoxes);
  307.    AddPage(&m_Text);
  308. }
  309.  
  310. CControls::~CControls()
  311. {
  312. }
  313.  
  314. BOOL CControls::OnInitDialog() 
  315. {
  316.    // remove the Apply and Cancel buttons
  317.    RemoveApplyButton();
  318.    RemoveCancelButton();
  319.  
  320.    // init the dialog
  321.     BOOL bResult = CMcPropertySheet::OnInitDialog();
  322.  
  323.    // restore the active page
  324.     SetActivePage(ActivePage);
  325.  
  326.    // handle window placement    
  327.    CMcWindowPlacement wp;
  328.    wp.RestoreWindowPlacement(_T("Controls"), _T("WindowPlacement"), this, TRUE);
  329.  
  330.    // set the ownerdraw function
  331.    CtlHTMLPartialOwnerDraw(MyPartialOwnerDraw);
  332.  
  333.    // init the dialog
  334.     return bResult;
  335. }
  336.  
  337. void CControls::OnDestroy() 
  338. {
  339.    // save active page
  340.    ActivePage = GetActiveIndex();
  341.  
  342.    // handle window placement    
  343.    CMcWindowPlacement wp;
  344.    wp.SaveWindowPlacement(_T("Controls"), _T("WindowPlacement"), this);
  345.  
  346.     CMcPropertySheet::OnDestroy();
  347. }
  348.  
  349. void CControls::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
  350. {
  351.    CMcPropertySheet::OnActivate(nState, pWndOther, bMinimized);
  352.    if (DisableControls)
  353.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  354. }
  355.  
  356.