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

  1. /*---------------------------------------------------------------------------*\
  2.  | Modeless.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 "Modeless.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. const int ModelessDialogHeight = 41;
  21.  
  22. void ScreenToClientRect (HWND hParent, RECT *pRect)
  23. {
  24.    ScreenToClient(hParent, (LPPOINT)&pRect->left);
  25.    ScreenToClient(hParent, (LPPOINT)&pRect->right);
  26. }
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CModeless dialog
  30.  
  31. BEGIN_MESSAGE_MAP(CModeless, CDialog)
  32.     //{{AFX_MSG_MAP(CModeless)
  33.     ON_WM_ACTIVATE()
  34.     ON_WM_DESTROY()
  35.     //}}AFX_MSG_MAP
  36.    ON_MESSAGE(WM_SIZETOFIT, OnSizeToFit)
  37. END_MESSAGE_MAP()
  38.  
  39. CModeless::CModeless(CWnd* pParent /*=NULL*/)
  40.     : CDialog(CModeless::IDD, pParent)
  41. {
  42.     //{{AFX_DATA_INIT(CModeless)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CModeless::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CModeless)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BOOL CModeless::OnInitDialog() 
  54. {
  55.    // init the dialog
  56.     BOOL bResult = CDialog::OnInitDialog();
  57.  
  58.    // Note: Since OnSizeToFit is handled, do window placement first, then subclass, since
  59.    //       subclassing may change the size of the dialog box.
  60.  
  61.    // handle window placement    
  62.    CMcWindowPlacement wp;
  63.    wp.RestoreWindowPlacement(_T("Modeless"), _T("WindowPlacement"), this, TRUE);
  64.  
  65.    // subclass the dialog box
  66.    CtlHTMLSubclassDialog(m_hWnd);
  67.  
  68.    // init the dialog
  69.     return bResult;
  70. }
  71.  
  72. LRESULT CModeless::OnSizeToFit (WPARAM wParam, LPARAM lParam)
  73. {
  74.    // we now know the size of the static text, so we can change the size of the
  75.    //    dialog box and move the OK and Cancel buttons down.
  76.    TEXTMETRIC  tm;
  77.    CWnd  *pWnd;
  78.    CDC   *pDC;
  79.    CRect windowRect;
  80.    int   cyChar, delta, height;
  81.  
  82.    // get the text metrics
  83.    pDC = GetDC();
  84.    pDC->GetTextMetrics(&tm);
  85.    cyChar = tm.tmHeight;
  86.    ReleaseDC(pDC);
  87.  
  88.    // get the change in size
  89.    delta = HIWORD(lParam) - cyChar;
  90.  
  91.    // change the window size
  92.    GetWindowRect(&windowRect);
  93.    height = (ModelessDialogHeight * cyChar) / 8 + delta + GetSystemMetrics(SM_CYCAPTION);
  94.    SetWindowPos(0, 0, 0, windowRect.Width(), height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
  95.  
  96.    // change the OK button
  97.    if ((pWnd = GetDlgItem(IDOK)) != 0)
  98.    {
  99.       pWnd->GetWindowRect(&windowRect);
  100.       ScreenToClientRect(m_hWnd, &windowRect);
  101.       pWnd->SetWindowPos(0, windowRect.left, windowRect.top + delta, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  102.    }
  103.  
  104.    // change the Cancel button
  105.    if ((pWnd = GetDlgItem(IDCANCEL)) != 0)
  106.    {
  107.       pWnd->GetWindowRect(&windowRect);
  108.       ScreenToClientRect(m_hWnd, &windowRect);
  109.       pWnd->SetWindowPos(0, windowRect.left, windowRect.top + delta, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  110.    }
  111.    return 0;
  112. }
  113.  
  114. void CModeless::OnDestroy() 
  115. {
  116.    // handle window placement    
  117.    CMcWindowPlacement wp;
  118.    wp.SaveWindowPlacement(_T("Modeless"), _T("WindowPlacement"), this);
  119.  
  120.     CDialog::OnDestroy();
  121. }
  122.  
  123. void CModeless::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  124. {
  125.    CDialog::OnActivate(nState, pWndOther, bMinimized);
  126.    if (DisableControls)
  127.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  128. }
  129.  
  130. void CModeless::OnOK() 
  131. {
  132.    // dismiss the current dialog
  133.     CDialog::OnOK();
  134.  
  135.    CWnd     *pParent = GetParent();
  136.    HWND     hDetails, hMessage, hDetailsText;
  137.    MSG      msg;
  138.    int      i, retVal;
  139.    BOOL     showUnfolded = TRUE;
  140.  
  141.    // disable the parent window to give modal behavior
  142.    pParent->EnableWindow(FALSE);
  143.  
  144.    // display details box
  145.    hDetails = HTMLDetailsBoxModeless(_T("<HTML>Dialing...</HTML>"), _T("Connecting to 372-3333..."), 
  146.                   _T("<HTML>Opening communication port...<BR>The communications port has been opened successfully.<BR>Connecting to device: U.S. Robotics. Type: modem...</HTML>"),
  147.                   CSize(200, 40), showUnfolded, HTMLMB_CANCEL | MB_DEFBUTTON1, 0, 0, -1, IDI_CONNECT);
  148.  
  149.    // do bogus processing
  150.    for (i = 0; i < 50; i++)
  151.    {
  152.       // check to see if the user has canceled
  153.       if ((retVal = HTMLModelessReturnValue(hDetails)) >= 0)
  154.          break;
  155.       while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  156.       {
  157.          TranslateMessage(&msg);
  158.          DispatchMessage(&msg);
  159.       }
  160.       Sleep(100);               // instead of sleep, do other prcessing
  161.    }
  162.  
  163.    // update the message text and details text
  164.    if ((hMessage = ::GetDlgItem(hDetails, HTMLID_MESSAGE_TEXT)) != 0)
  165.    {
  166.       ::SetWindowText(hMessage, _T("<HTML>Connected</HTML>"));
  167.       ::InvalidateRect(hMessage, 0, TRUE);
  168.    }
  169.    if ((hDetailsText = ::GetDlgItem(hDetails, HTMLID_DETAILS_TEXT)) != 0)
  170.    {
  171.       ::SetWindowText(hDetailsText, _T("<HTML>Opening communication port...<BR>The communications port has been opened successfully.<BR>Connecting to device: U.S. Robotics. Type: modem...<BR><B>All communication devices are connnected and ready.</B></HTML>"));
  172.       ::InvalidateRect(hDetailsText, 0, TRUE);
  173.    }
  174.  
  175.    // do bogus processing
  176.    for (i = 0; i < 30; i++)
  177.    {
  178.       // check to see if the user has canceled
  179.       if ((retVal = HTMLModelessReturnValue(hDetails)) >= 0)
  180.          break;
  181.       while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  182.       {
  183.          TranslateMessage(&msg);
  184.          DispatchMessage(&msg);
  185.       }
  186.       Sleep(100);               // instead of sleep, do other prcessing
  187.    }
  188.  
  189.    // get returned value (and do whatever you want with it)
  190.    retVal = HTMLModelessReturnValue(hDetails);
  191.  
  192.    // destroy the modeless dialog
  193.    ::DestroyWindow(hDetails);   // DestroyWindow deletes dialog
  194.  
  195.    // activate the parent - necessary, but there should be a better way of doing this
  196.    pParent->SetWindowPos(0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
  197. }
  198.