Click here to Skip to main content
15,891,529 members
Articles / Containers / Virtual Machine

TOOL

Rate me:
Please Sign up or sign in to vote.
4.98/5 (52 votes)
23 Oct 200676 min read 230.8K   5.4K   147  
TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language interpreter. The purpose of this article is to introduce the TOOL interpreter and language from the perspective of a person who has a desire to include a scripting solution as part of his project.
/*****************************************************************************/
/*                              SOURCE FILE                                  */
/*****************************************************************************/
/*
       $Archive: $

      $Revision: $
          $Date: $
        $Author: $

    Description: Implementation for the VMTimeOutMsgBox class

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/


#include "VMMessageBox.h"



BEGIN_MESSAGE_MAP( VMTimeOutMsgBox, CDialog )
	//{{AFX_MSG_MAP( VMTimeOutMsgBox )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::VMTimeOutMsgBox

       DESCRIPTION:  ctor for this object

             INPUT:  lpMsgBoxtext      - Text Message for the MessageBox                    
                     lpMsgBoxCaption   - Caption for the MessageBox                     
                     uiMsgBoxStyle     - Button, Icon style                   
                     uiDefaultResponse - Default return value from this                                                 this if the user does not respond                    
                     uiTimeOutValue    - Time Out for this (in milliseconds)
            OUTPUT:  void
           RETURNS:  void
*/
VMTimeOutMsgBox::VMTimeOutMsgBox( LPSTR lpMsgBoxtext,
                                  LPSTR lpMsgBoxCaption, 
                                  UINT  uiMsgBoxStyle, 
                                  UINT  uiDefaultResponse,
                                  UINT  uiTimeOutValue ) 
{
  m_MsgBoxInfo.lpMsgBoxtext       = lpMsgBoxtext;
  m_MsgBoxInfo.lpMsgBoxCaption    = lpMsgBoxCaption;
  m_MsgBoxInfo.uiMsgBoxStyle      = uiMsgBoxStyle;
  m_MsgBoxInfo.uiDefaultResponse  = uiDefaultResponse;
  m_MsgBoxInfo.uiTimeOutValue     = uiTimeOutValue;
}
/* End of function "VMTimeOutMsgBox::VMTimeOutMsgBox"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::DoDataExchange

       DESCRIPTION:  see mfc docs

             INPUT:  pDX - see mfc docs 
            OUTPUT:  none

           RETURNS:  void
*/
void VMTimeOutMsgBox::DoDataExchange( CDataExchange* pDX )
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP( VMTimeOutMsgBox )
	//}}AFX_DATA_MAP
}
/* End of function "VMTimeOutMsgBox::DoDataExchange"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::IndirectCreate

       DESCRIPTION:  private subordinate to overridden create methods

             INPUT:  none

           RETURNS:  returns the results of the base class' CreateIndirect
*/
BOOL VMTimeOutMsgBox::IndirectCreate( CWnd* pParentWnd )
{
    long aldt[ sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) ];

    ZeroMemory( aldt, sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) );
    long lStyle = WS_POPUP | WS_VISIBLE | WS_DLGFRAME;

    memset ( aldt, NULL, sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) );
    memcpy ( aldt, &lStyle, sizeof( long ) );

    return( CDialog::CreateIndirect( aldt, pParentWnd ) );
}
/* End of function "VMTimeOutMsgBox::IndirectCreate"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::Create

       DESCRIPTION:  overridden to allow this to operate without any template
                     as they really aren't required by this

             INPUT:  LPCTSTR lpszTemplateName - ignored
                     CWnd* pParentWnd - passed to base class

           RETURNS:  returns the results of the base class' CreateIndirect
*/
BOOL VMTimeOutMsgBox::Create( LPCTSTR lpszTemplateName, CWnd* pParentWnd )
{
   if ( IndirectCreate( pParentWnd ) )
      return TRUE;                     // 2b|!2b==?
   else
      return FALSE;                    // 2b|!2b==?
}
/* End of function "VMTimeOutMsgBox::Create"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::Create

       DESCRIPTION:  overridden to allow this to operate without any template
                     as they really aren't required by this

             INPUT:  UINT nIDTemplate - ignored
                     CWnd* pParentWnd - passed to base class

           RETURNS:  returns the results of the base class' CreateIndirect
*/
BOOL VMTimeOutMsgBox::Create( UINT nIDTemplate, CWnd* pParentWnd )
{
   if ( IndirectCreate( pParentWnd ) )
      return TRUE;                      // 2b|!2b==?
   else
      return FALSE;                     // 2b|!2b==?
}
/* End of function "VMTimeOutMsgBox::Create"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::DoModal

       DESCRIPTION:  overridden so that this can be created without a template.
                     This method first sets up a memory region that can be used
                     for an indirect create, if the create operation succeeds,
                     then this calls into the base class for the rest of the
                     work.

             INPUT:  none
            OUTPUT:  none

           RETURNS:  results from CDialog::DoModal or ATD_CREATE_ERROR if
                     the indirect creation failed
*/
int VMTimeOutMsgBox::DoModal() 
{
   long aldt[ sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) ];

   ZeroMemory( aldt, sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) );
   long lStyle = WS_POPUP | WS_VISIBLE | WS_DLGFRAME;

   memset ( aldt, NULL, sizeof( DLGTEMPLATE) + ( 3 * sizeof(DLGITEMTEMPLATE) ) );
   memcpy ( aldt, &lStyle, sizeof( long ) );

   if ( CDialog::InitModalIndirect( (DLGTEMPLATE*)aldt ) )
	   return CDialog::DoModal();
   else
     return ATD_CREATE_ERROR;
}
/* End of function "VMTimeOutMsgBox::DoModal"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMTimeOutMsgBox::WindowProc

       DESCRIPTION:  implements the window proc for this

             INPUT:  see mfc docs 
            OUTPUT:  void

           RETURNS:  true or return from base class
*/
LRESULT VMTimeOutMsgBox::WindowProc( UINT message, WPARAM wParam, LPARAM lParam ) 
{
  if ( WM_INITDIALOG == message )
  {
     ShowWindow( SW_HIDE );
     if ( 0 != m_MsgBoxInfo.uiTimeOutValue )
          m_MsgBoxInfo.uiTimeOutValue = SetTimer( m_MsgBoxInfo.uiDefaultResponse,
                                                  m_MsgBoxInfo.uiTimeOutValue, 
                                                  NULL );
     {
        m_uiRetCode = ::MessageBox( this->m_hWnd, 
                                    m_MsgBoxInfo.lpMsgBoxtext, 
                                    m_MsgBoxInfo.lpMsgBoxCaption, 
                                    m_MsgBoxInfo.uiMsgBoxStyle );
        EndDialog( m_uiRetCode );
     }
     return true;
  }
  else
  if ( WM_TIMER == message )
  {
     HWND  hwnd;
     if ( ( hwnd = ::FindWindow( "#32770", m_MsgBoxInfo.lpMsgBoxCaption ) ) != 0 )
     {
        // "capture" return code
        //
        m_uiRetCode = m_MsgBoxInfo.uiDefaultResponse;

        // first end the message box, then end the invisible container d'log
        //
        ::EndDialog( hwnd, m_MsgBoxInfo.uiDefaultResponse );
        EndDialog( m_MsgBoxInfo.uiDefaultResponse );
     }
     return true;
  }
  else
  if ( WM_DESTROY == message )
  {
     KillTimer( m_MsgBoxInfo.uiTimeOutValue );
     return true;
  }
  else
     return CDialog::WindowProc( message, wParam, lParam );
}
/* End of function "VMTimeOutMsgBox::WindowProc"
/*****************************************************************************/



/*****************************************************************************/
/* Check-in history */
/*
 *$Log: $
*/
/*****************************************************************************/


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions