home *** CD-ROM | disk | FTP | other *** search
Wrap
/*---------------------------------------------------------------------------*\ | Modeless.cpp - CtlHTML(tm) Control Library Test Program | | Windmill Point Software, Alburg, VT 05440 | | Copyright (c) 1999, Windmill Point Software | | All Rights Reserved. | \*---------------------------------------------------------------------------*/ #include "stdafx.h" #include "CtlHTML Demo.h" #include "DevUI.h" #include "..\CtlHtml.h" #include "Modeless.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const int ModelessDialogHeight = 41; void ScreenToClientRect (HWND hParent, RECT *pRect) { ScreenToClient(hParent, (LPPOINT)&pRect->left); ScreenToClient(hParent, (LPPOINT)&pRect->right); } ///////////////////////////////////////////////////////////////////////////// // CModeless dialog BEGIN_MESSAGE_MAP(CModeless, CDialog) //{{AFX_MSG_MAP(CModeless) ON_WM_ACTIVATE() ON_WM_DESTROY() //}}AFX_MSG_MAP ON_MESSAGE(WM_SIZETOFIT, OnSizeToFit) END_MESSAGE_MAP() CModeless::CModeless(CWnd* pParent /*=NULL*/) : CDialog(CModeless::IDD, pParent) { //{{AFX_DATA_INIT(CModeless) //}}AFX_DATA_INIT } void CModeless::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CModeless) //}}AFX_DATA_MAP } BOOL CModeless::OnInitDialog() { // init the dialog BOOL bResult = CDialog::OnInitDialog(); // Note: Since OnSizeToFit is handled, do window placement first, then subclass, since // subclassing may change the size of the dialog box. // handle window placement CMcWindowPlacement wp; wp.RestoreWindowPlacement(_T("Modeless"), _T("WindowPlacement"), this, TRUE); // subclass the dialog box CtlHTMLSubclassDialog(m_hWnd); // init the dialog return bResult; } LRESULT CModeless::OnSizeToFit (WPARAM wParam, LPARAM lParam) { // we now know the size of the static text, so we can change the size of the // dialog box and move the OK and Cancel buttons down. TEXTMETRIC tm; CWnd *pWnd; CDC *pDC; CRect windowRect; int cyChar, delta, height; // get the text metrics pDC = GetDC(); pDC->GetTextMetrics(&tm); cyChar = tm.tmHeight; ReleaseDC(pDC); // get the change in size delta = HIWORD(lParam) - cyChar; // change the window size GetWindowRect(&windowRect); height = (ModelessDialogHeight * cyChar) / 8 + delta + GetSystemMetrics(SM_CYCAPTION); SetWindowPos(0, 0, 0, windowRect.Width(), height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); // change the OK button if ((pWnd = GetDlgItem(IDOK)) != 0) { pWnd->GetWindowRect(&windowRect); ScreenToClientRect(m_hWnd, &windowRect); pWnd->SetWindowPos(0, windowRect.left, windowRect.top + delta, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); } // change the Cancel button if ((pWnd = GetDlgItem(IDCANCEL)) != 0) { pWnd->GetWindowRect(&windowRect); ScreenToClientRect(m_hWnd, &windowRect); pWnd->SetWindowPos(0, windowRect.left, windowRect.top + delta, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); } return 0; } void CModeless::OnDestroy() { // handle window placement CMcWindowPlacement wp; wp.SaveWindowPlacement(_T("Modeless"), _T("WindowPlacement"), this); CDialog::OnDestroy(); } void CModeless::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized) { CDialog::OnActivate(nState, pWndOther, bMinimized); if (DisableControls) CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE); } void CModeless::OnOK() { // dismiss the current dialog CDialog::OnOK(); CWnd *pParent = GetParent(); HWND hDetails, hMessage, hDetailsText; MSG msg; int i, retVal; BOOL showUnfolded = TRUE; // disable the parent window to give modal behavior pParent->EnableWindow(FALSE); // display details box hDetails = HTMLDetailsBoxModeless(_T("<HTML>Dialing...</HTML>"), _T("Connecting to 372-3333..."), _T("<HTML>Opening communication port...<BR>The communications port has been opened successfully.<BR>Connecting to device: U.S. Robotics. Type: modem...</HTML>"), CSize(200, 40), showUnfolded, HTMLMB_CANCEL | MB_DEFBUTTON1, 0, 0, -1, IDI_CONNECT); // do bogus processing for (i = 0; i < 50; i++) { // check to see if the user has canceled if ((retVal = HTMLModelessReturnValue(hDetails)) >= 0) break; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } Sleep(100); // instead of sleep, do other prcessing } // update the message text and details text if ((hMessage = ::GetDlgItem(hDetails, HTMLID_MESSAGE_TEXT)) != 0) { ::SetWindowText(hMessage, _T("<HTML>Connected</HTML>")); ::InvalidateRect(hMessage, 0, TRUE); } if ((hDetailsText = ::GetDlgItem(hDetails, HTMLID_DETAILS_TEXT)) != 0) { ::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>")); ::InvalidateRect(hDetailsText, 0, TRUE); } // do bogus processing for (i = 0; i < 30; i++) { // check to see if the user has canceled if ((retVal = HTMLModelessReturnValue(hDetails)) >= 0) break; while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } Sleep(100); // instead of sleep, do other prcessing } // get returned value (and do whatever you want with it) retVal = HTMLModelessReturnValue(hDetails); // destroy the modeless dialog ::DestroyWindow(hDetails); // DestroyWindow deletes dialog // activate the parent - necessary, but there should be a better way of doing this pParent->SetWindowPos(0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER); }