Example #1
0
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
                    LPSTR lpszCmdLine,  int nCmdShow )
{
    MSG         msg;
#ifndef __NT__
#if 0
    HWND        win;
    HWND        child;
#endif
#endif

    /* touch unused vars to get rid of warning */
    _wde_touch( lpszCmdLine );
    _wde_touch( nCmdShow );
#ifdef __NT__
    _wde_touch( hinstPrevious );
#endif
#if defined( __NT__ ) && !defined( __WATCOMC__ )
    _argc = __argc;
    _argv = __argv;
#endif

    WRInit();
    WdeInitDisplayError( hinstCurrent );

    /* store the handle to this instance of Wde in a static variable */
    hInstWde = hinstCurrent;

    //check we are running in DDE mode
    IsDDE = WdeIsDDEArgs( _argv, _argc );

    WdeFirstInst = (hinstPrevious == NULL);

    WdeInitEditClass();

    /* is this the first instance of the application? */
#ifndef __NT__
    if( WdeFirstInst ) {
#endif
        /* if so call the routine to initialize the application */
        if( !WdeInit( hinstCurrent ) ) {
            if( IsDDE ) {
                WdeDDEDumpConversation( hinstCurrent );
            }
            return( FALSE );
        }
#ifndef __NT__
    }
#if 0
    else if( IsDDE ) {
        WdeDisplayErrorMsg( WDE_NOMULTIPLEINSTANCES );
        WdeDDEDumpConversation( hinstCurrent );
        return( FALSE );
    } else {
        win = FindWindow( WdeMainClass, NULL );
        if( win != NULL ) {
            child = GetLastActivePopup( win );
            PostMessage( win, WM_USER, 0, 0 );
            BringWindowToTop( win );
            if( child != (HWND)NULL && child != win ) {
                BringWindowToTop( child );
            }
        } else {
            WdeDisplayErrorMsg( WDE_NOMULTIPLEINSTANCES );
        }
        return( FALSE );
    }
#endif
#endif

    if( !WdeInitInst( hinstCurrent ) ) {
        WdeDisplayErrorMsg( WDE_INITFAILED );
        if( IsDDE ) {
            WdeDDEDumpConversation( hinstCurrent );
        }
        return( FALSE );
    }

    if( IsDDE ) {
        if( WdeDDEStart( hinstCurrent ) ) {
            if( !WdeDDEStartConversation() ) {
                WdeDisplayErrorMsg( WDE_DDEINITFAILED );
                PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
            }
        } else {
            WdeDisplayErrorMsg( WDE_DDEINITFAILED );
            PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
        }
    }

    WdeEnableMenuInput( TRUE );

    if( setjmp( WdeEnv ) ) {
        PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
        if( setjmp( WdeEnv ) ) {
            WdeDisplayErrorMsg( WDE_EXCEPTIONDURINGABNORMALEXIT );
            exit( -1 );
        }
        WdePushEnv( &WdeEnv );
    } else {
        WdePushEnv( &WdeEnv );
        WdeProcessArgs( _argv, _argc );
    }

    if( !WdeGetNumRes() ) {
        WdeCreateNewResource( NULL );
    }

    /* create the message loop */
    while( GetMessage( &msg, (HWND)NULL, 0, 0 ) ) {
        if( !WdeIsTestMessage( &msg ) && !WdeIsInfoMessage( &msg ) &&
            !WRIsWRDialogMsg( &msg ) ) {
            if( !WdeWasAcceleratorHandled( &msg ) ) {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }
    }

    if( IsDDE ) {
        WdeDDEEndConversation();
    }

    WdePopEnv( &WdeEnv );

    if( IsDDE ) {
        WdeDDEEnd();
    }

    WRFini();

    return( msg.wParam );
}
Example #2
0
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
                    LPSTR lpszCmdLine, int nCmdShow )
{
    extern char **_argv;
    extern int  _argc;
    MSG         msg;
    Bool        ret;

    /* touch unused vars to get rid of warning */
    _wre_touch( lpszCmdLine );
    _wre_touch( nCmdShow );
#ifdef __NT__
    _wre_touch( hinstPrevious );
#endif

    WRInit();
    WAccelInit();
    WMenuInit();
    WStringInit();
    WREInitDisplayError( hinstCurrent );

    /* store the handle to this instance of WRE in a static variable */
    WREInst = hinstCurrent;

    peekArgs( _argv, _argc );

    /* is this the first instance of the application? */
#ifndef __NT__
    if( hinstPrevious == NULL ) {
#endif
        /* if so call the routine to initialize the application */
        if( !WREInit( hinstCurrent ) ) {
            return( FALSE );
        }
#ifndef __NT__
    }
#endif

    if( !WREInitInst( hinstCurrent ) ) {
        WREDisplayErrorMsg( WRE_INITFAILED );
        return( FALSE );
    }

    if( !WREDDEStart( hinstCurrent ) ) {
        WREDisplayErrorMsg( WRE_DDEINITFAILED );
        return( FALSE );
    }

    ret = WREProcessArgs( _argv, _argc );

    startEditors();

    // create a new empty res if none have been created at this point
    if( ret && WREGetNumRes() == 0 ) {
        WRECreateNewResource( NULL );
    }

    /* create the message loop */
    while( GetMessage( &msg, (HWND)NULL, 0, 0 ) ) {
        if( !WREIsEditWindowDialogMessage( &msg ) &&
                !WREWasAcceleratorHandled( &msg ) &&
                !WREIsResInfoWinMsg( &msg ) &&
                !WRIsWRDialogMsg( &msg ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    WREDDEEnd();
    WStringFini();
    WMenuFini();
    WAccelFini();
    WRFini();

    return( msg.wParam );
}