📄 winloop.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Intrface/WinLoop.cpp,v $
* $Date: 2003/05/13 18:42:07 $
*
Description:
\*____________________________________________________________________________*/
//$SourceTop:$
#include <iostream.h>
#include <stdio.h>
#include "PICompat.h"
#include "Pi2API.h"
#include "IntrFace.h"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define KEY_CONF_MAINWINDOW "MainWindow"
#define CONFIG_ERR(this, msg) \
{ PILog_addMessage( PIObject_getDB(this), \
PIObject_getConfigurationDB(this), PILOG_ERROR, (msg) ); }
/*
** #define D { cerr << __FILE__ << ": " << __LINE__ << endl; }
*/
#define D
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#if 0
/*
** HTML documentation for this handler
*/
/*___+++HTMLDOC_BEGIN+++___*/
Name:
WinLoop
Description:
Create the top level remote administration interface structure
for windows message handling and dispatch messages on the current
thread until WM_QUIT is received (default windows message loop).
Options:
<TABLE BORDER=1>
<TH>Option
<TH>Default
<TH>Values
<TH>Short Description
<TH>Example(s)
<TR>
<TD>MainWindow
<TD>+
<TD><configuration object>
<TD>A valid name of a configuration object used to load the property sheet
<TD>MainWindow PrpSheet
</TABLE>
<STRONG>-</STRONG> in the <IT>default</IT> indicates no default<BR>
<STRONG>+</STRONG> in the <IT>default</IT> indicates the field is mandatory<BR>
<H4>Description of Options</H4>
<H5>Main Window</H5>
This parameter is used in order to create the top level window of the
Win32 GUI application. The specified object must be of class PropSheetClass.
Example:
<PRE>
<Object>
Name WinLoop
Class WinLoopClass
MainWindow PrpSheet
</Object>
</PRE>
/*___+++HTMLDOC_END+++___*/
#endif
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class WinLoop
{
private:
/* ---
Internal data members
--- */
Interface *pInterface; /* the main window dispatch structure */
PIObject *pMainWindow; /* the main window object */
protected:
public:
WinLoop( PIObject *pObject, int iArgc, const char *ppArgv[] )
:
pInterface( 0 ),
pMainWindow( 0 )
{
const char *pMainWindowName = PIConfig_lookupValue(
PIObject_getConfigurationDB( pObject ),
KEY_CONF_MAINWINDOW,
0,
0 );
if ( !pMainWindowName )
{
CONFIG_ERR( pObject, "WinLoop: 'MainWindow' not defined" );
return;
};
PIDB *pDB = PIObject_getDB( pObject );
pMainWindow = PIObject_loadFromLine(
pDB, PIObject_getConfigurationDB( pObject ), pMainWindowName );
if ( !pMainWindow )
{/* --- error set by PIObject_loadFromLine() --- */ return; };
pInterface = Interface_new();
};
~WinLoop()
{
Interface_delete( pInterface );
PIObject_delete( pMainWindow, 0, 0 );
};
int Execute( int iArgc, const char *ppArgv[] )
{
/*
** Send message to initialize the main window
*/
pInterface->iMessage = INTRFACE_MSG_INIT;
int iResult = PILogic_execute( pMainWindow, 1,
(const char **)&pInterface );
/*
** Send message to set defaults to the main window
*/
if (iResult != PIAPI_ERROR)
{
pInterface->iMessage = INTRFACE_MSG_DEFAULTS;
iResult = PILogic_execute( pMainWindow, 1,
(const char **)&pInterface );
}
/*
** Send message to load values to the main window
*/
if (iResult != PIAPI_ERROR)
{
pInterface->iMessage = INTRFACE_MSG_LOAD;
iResult = PILogic_execute( pMainWindow, 1,
(const char **)&pInterface );
}
/*
** Create the main window
*/
if (iResult != PIAPI_ERROR)
{
pInterface->iMessage = INTRFACE_MSG_WIN32CREATE;
iResult = PILogic_execute( pMainWindow, 1,
(const char **)&pInterface );
}
/*
** If the window failed to load popup the message and abort
*/
if ( iResult != PIAPI_COMPLETED )
{
::MessageBox( NULL, pInterface->sError, "Interface Creation Error",
MB_OK );
return PIAPI_ABORT;
};
/*
** Do the windows loop, until WM_QUIT
*/
MSG tMsg;
while( ::GetMessage( &tMsg, NULL, 0, 0 ) )
{
if ( !(PropSheet_IsDialogMessage( pInterface->hWnd, &tMsg )) )
{
::TranslateMessage( &tMsg );
::DispatchMessage( &tMsg );
}
else
{
if (!PropSheet_GetCurrentPageHwnd(pInterface->hWnd))
{
::DestroyWindow( pInterface->hWnd );
::ExitProcess( 0 );
}
}
};
/*
** If the window execution failed popup the message
*/
if ( iResult != PIAPI_COMPLETED )
{
::MessageBox( NULL, pInterface->sError, "Interface Execution Error",
MB_OK );
return PIAPI_ERROR;
};
return PIAPI_COMPLETED;
};
inline int IsOK() { return pMainWindow!=0; };
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int WinLoop_execute( PIObject *pObj,
int iArgc, const char *ppArgv[] )
{
if ( !pObj ) return PIAPI_ERROR;
return ((WinLoop *)PIObject_getUserData(pObj))->Execute( iArgc,
ppArgv );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int WinLoop_onClassLoad( PIClass_LoadAction eLoad, void * )
{
switch( eLoad )
{
case STARTUP:
default:;
};
return PIAPI_COMPLETED;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int WinLoop_constructor( PIObject *pObj,
int iArgc, const char *ppArgv[] )
{
WinLoop *pWin = new WinLoop( pObj, iArgc, ppArgv );
if (!( pWin && pWin->IsOK() ))
{
PI_DELETE( pWin );
return PIAPI_ERROR;
};
if ( PIObject_setUserData( pObj, pWin ) )
{
PI_DELETE( pWin );
CONFIG_ERR( pObj, "WinLoop_constructor: \
PIObject_setUserData() failed" );
return PIAPI_ERROR;
};
return PIAPI_COMPLETED;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int WinLoop_copyConstructor( PIObject *, int, const char *[] )
{
return PIAPI_ERROR;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int WinLoop_destructor( PIObject *pObj, int,
const char *[] )
{
PI_DELETE( (WinLoop *)PIObject_getUserData( pObj ) );
return PIAPI_COMPLETED;
}
#if 0
/*___+++CNF_BEGIN+++___*/
<Class>
Name WinLoopClass
Type LogicExtension
Library IntrFace
OnClassLoad WinLoop_onClassLoad
Constructor WinLoop_constructor
CopyConstructor WinLoop_copyConstructor
Destructor WinLoop_destructor
Execute WinLoop_execute
</Class>
<Object>
Name WinLoop
Class WinLoopClass
MainWindow "PropSheet"
</Object>
/*___+++CNF_END+++___*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -