📄 winmain.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/EnhPi3/WinMain.cpp,v $
* $Date: 2004/07/04 19:32:22 $
*
Description:
This file is a bit of a mess while I sort out what sort of main window
it should have.
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <commctrl.h>
#include "StrToken.h"
#include "Common.h"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
HINSTANCE __hInstance = 0;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_usage()
{
#define USAGE_MSG "\
EnhPi3 [ /start | /admin | /setup ] <file>\n\n\
/start Start the pi3web server specified by <file>\n\
/admin Configure the properties of server specified by <file>\n\
/setup Generate the pi3web configuration file <file> for a new installation.\n\n\
/uninstall Shutdown server, remove registry entry and delete files.\n\n\
Default is /start if no option is specified."
MessageBox( NULL, USAGE_MSG, "EnhPi3 Usage", MB_OK | MB_ICONEXCLAMATION );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Windows entry point
\*____________________________________________________________________________*/
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE /* hPrevInstance */,
LPSTR /* lpCmdLine */,
int /* nCmdShow */ )
{
__hInstance = hInstance;
/*
** Set the current directory to be where the binary is
*/
const char *pErr = 0;
int iLen = 0;
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
::GetModuleFileName( ::GetModuleHandle(NULL), szBuf, BUF_SIZE );
szBuf[BUF_SIZE] = '\0';
for ( iLen = strlen( szBuf )-1; iLen>=0; iLen-- )
{
if ( szBuf[iLen]=='/' || szBuf[iLen]=='\\' || szBuf[iLen]==':' )
{ break; };
};
iLen++;
szBuf[iLen]='\0';
::SetCurrentDirectory( szBuf );
int iRet = 0;
/*
** Convert commandline into argc, argv format, interpreting
** and removing first argument as appropriate
*/
char *lpCmdLine = strdup( ::GetCommandLine() );
/*
**
** LATER
**
** Later, there is a bug here if the command line contains spaces in
** filenames
*/
int iArgc = 1;
const char **ppArgv = (const char **)malloc(sizeof(const char *)*iArgc);
*ppArgv = lpCmdLine;
int iQuoted = 0;
for( int i=0; lpCmdLine[i]; i++ )
{
if ( iQuoted )
{
if ( lpCmdLine[i]=='"' )
{ iQuoted = 0; };
}
else
{
if ( lpCmdLine[i]=='"' )
{ iQuoted = 1; }
else if ( isspace(lpCmdLine[i]) )
{
lpCmdLine[i++] = '\0';
for( ; isspace( lpCmdLine[i] ); i++ );
if ( lpCmdLine[i] )
{
iArgc++;
ppArgv = (const char **)realloc( ppArgv,
sizeof(const char *)*iArgc);
ppArgv[iArgc-1] = &(lpCmdLine[i]);
if ( lpCmdLine[i]=='"' ) { iQuoted = 1; };
};
};
};
};
#if 0
StringTokenizer tTokens( lpCmdLine, " " );
int iArgc = tTokens.NumTokens();
const char **ppArgv = (const char **)PI_NEW( char *[iArgc] );
assert( ppArgv );
int j=0;
for( int i=0; i<iArgc; i++)
{
const char *pToken = tTokens.GetToken( i );
for( int k=0; pToken[k] && isspace( pToken[k] ); k++);
if ( pToken[k] )
{ ppArgv[j++] = &(pToken[k]); };
};
iArgc = j;
#endif
enum { NOARG, START, ADMIN, SETUP, UNINSTALL } eAppType = NOARG;
/*
** If more than 1 arguments, check for '/' or /-/ as first
** argument
*/
if ( iArgc>=2 && ( *ppArgv[1]=='-' || *ppArgv[1]=='/' ) )
{
const char *pCommand = &(( ppArgv[1] )[1]);
if ( !stricmp( pCommand, "Start" ) )
{
eAppType = START;
}
else if ( !stricmp( pCommand, "Admin" ) )
{
eAppType = ADMIN;
}
else if ( !stricmp( pCommand, "Setup" ) )
{
eAppType = SETUP;
}
else if ( !stricmp( pCommand, "Uninstall" ) )
{
eAppType = UNINSTALL;
}
else
{
Internal_usage();
iRet = 0; /* OK */
goto app_done;
};
}
else if ( iArgc<2 )
{
Internal_usage();
iRet = -1; /* Error */
goto app_done;
};
/*
** If an argument was supplied, then remove it from the list
*/
if ( eAppType != NOARG )
{
iArgc--;
for( int i=1; i<iArgc; i++)
{ ppArgv[i] = ppArgv[i+1]; };
}
else
{ eAppType = START; };
/*
** Make sure common controls are loaded
*/
::InitCommonControls();
/*
** Now run the appropriate program
*/
switch( eAppType )
{
case START:
iRet = Pi3_main( hInstance, iArgc, ppArgv );
break;
case ADMIN:
iRet = AD_configMain( hInstance, iArgc, ppArgv );
break;
case SETUP:
iRet = AD_setupMain( hInstance, iArgc, ppArgv );
break;
case UNINSTALL:
iRet = AD_uninstallMain( hInstance, iArgc, ppArgv );
break;
default:
assert( 0 );
};
app_done:
free( ppArgv );
// free( lpCmdLine );
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -