⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wdemain.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <windows.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "wdeglbl.h"
#include "wdemem.h"
#include "wderes.h"
#include "wdetest.h"
#include "wdestat.h"
#include "wdefdiag.h"
#include "wdeedit.h"
#include "wdealign.h"
#include "wdedefin.h"
#include "wdesym.h"
#include "wdeinfo.h"
#include "wdefutil.h"
#include "wdemsgbx.h"
#include "wdemsgs.gh"
#include "wdefont.h"
#include "wdeopts.h"
#include "wdefinit.h"
#include "wdesdlg.h"
#include "wdetmenu.h"
#include "wdetoolb.h"
#include "wdectool.h"
#include "wderibbn.h"
#include "wdehints.h"
#include "wdedebug.h"
#include "wdecust.h"
#include "wdefordr.h"
#include "wdestken.h"
#include "wdectl3d.h"
#include "wde_rc.h"
#include "wdemain.h"
#include "wdesvdlg.h"
#include "wdedde.h"
#include "wdeclear.h"
#include "wdecurr.h"
#include "wdegoto.h"
#include "wdegetfn.h"
#include "wdefmenu.h"
#include "wdecctl.h"
#include "wrdll.h"
#include "wrdmsg.h"
#include "jdlg.h"

#include "wwinhelp.h"

/* set the WRES library to use compatible functions */
WResSetRtns(open,close,read,write,lseek,tell,WdeMemAlloc,WdeMemFree);

/****************************************************************************/
/* macro definitions                                                        */
/****************************************************************************/
#define ABOUT_TIMER     666
#define ABOUT_TIMEOUT   2000
#define DDE_OPT         "-DDE"
#define CREATE_NEW_FLAG "/n"

#ifndef __ALPHA__
void WdeInt3( void );
#pragma aux WdeInt3 =                                   \
        " int    3h             "
#endif

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/
extern int PASCAL        WinMain        ( HINSTANCE, HINSTANCE, LPSTR, int);
extern LRESULT WINEXPORT WdeMainWndProc ( HWND, UINT, WPARAM, LPARAM );
extern Bool WINEXPORT    WdeAbout       ( HWND, WORD, WPARAM, LPARAM );

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static Bool        WdeInit                  ( HINSTANCE );
static Bool        WdeInitInst              ( HINSTANCE );
static void        WdeUpdateScreenPosOpt    ( void );
static Bool        WdeCleanup               ( WdeResInfo *, Bool );
static HWND        WdeCreateMDIClientWindow ( HWND, HINSTANCE );
static Bool        WdeWasAcceleratorHandled ( MSG * );
static Bool        WdeSaveCurrentDialog     ( WORD );
static Bool        WdeRestoreCurrentDialog  ( void );
static Bool        WdeHideCurrentDialog     ( void );
static void        WdeHandleTabEvent        ( Bool );
static void        WdeHandleSizeToText      ( void );
static void        WdeSetMakeMeCurrent      ( WdeResInfo *, void * );
static LRESULT     WdeHandleMDIArrangeEvents( WORD );
static Bool        WdeSetDialogMode         ( WORD );
static Bool        WdeProcessArgs           ( char **, int  );
static void        WdeDisplayAboutBox       ( HINSTANCE, HWND, UINT );
static Bool        WdeIsDDEArgs             ( char **argv, int argc );

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/
static HINSTANCE hInstWde;
static HACCEL    WdeAccel;
static HMENU     WdeDDEMenu         = NULL;
static HMENU     WdeInitialMenu     = NULL;
static HMENU     WdeResMenu         = NULL;
static HMENU     WdeCurrentMenu     = NULL;
static HWND      hWinWdeMain        = NULL;
static HWND      hWinWdeMDIClient   = NULL;
static Bool      WdeCleanupStarted  = FALSE;
static Bool      WdeFatalExit       = FALSE;
static Bool      IsDDE              = FALSE;
static Bool      EnableMenuInput    = FALSE;
static char      WdeMainClass[]     = "WdeMainClass";
static Bool      WdeFirstInst       = FALSE;
static jmp_buf   WdeEnv;

Bool WdeCreateNewFiles  = FALSE;

int PASCAL WinMain ( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
                     LPSTR     lpszCmdLine,  int       nCmdShow)
{
    extern char **_argv;
    extern int  _argc;
    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

    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 );
}

/* Function to initialize the first instance of Wde */
Bool WdeInit( HINSTANCE app_inst )
{
    WNDCLASS wc;

    /* fill in the WINDOW CLASS structure for the main window */
    wc.style         = CS_DBLCLKS;
    wc.lpfnWndProc   = WdeMainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = app_inst;
    wc.hIcon         = LoadIcon ( app_inst, "WdeIcon" );
    wc.hCursor       = LoadCursor ( (HINSTANCE) NULL, IDC_ARROW );
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszMenuName  = "WdeMenu";
    wc.lpszClassName = WdeMainClass;

    /* register the main window class */
    if( !RegisterClass(&wc) ) {
        WdeDisplayErrorMsg( WDE_NOREGISTERMAINCLASS );
        return( FALSE );
    }

    /* register the edit window class */
    if( !WdeRegisterEditClass( app_inst ) ) {
        WdeDisplayErrorMsg( WDE_NOREGISTEREDITCLASS );
        return( FALSE );
    }

    /* register the res MDI window class */
    if( !WdeRegisterResClass( app_inst ) ) {
        WdeDisplayErrorMsg( WDE_NOREGISTERRESCLASS );
        return( FALSE );
    }

    /* register the tag window class */
    if( !WdeRegisterTagClass( app_inst ) ) {
        WdeDisplayErrorMsg( WDE_NOREGISTERTAGCLASS );
        return( FALSE );
    }

    WdeInitCommonControls();

    return( TRUE );
}

/* Function to initialize all instances of Wde */
Bool WdeInitInst( HINSTANCE app_inst )
{
    RECT        rect, screen, t;
    char        *title;

    /* initialize global variables */

    WdeInitOpts();

    if( !JDialogInit() ) {
        return( FALSE );
    }

    if( !WdeInitResStrings() ) {
        return( FALSE );
    }

    if( !WdeInitCreateTable() ) {
        WdeDisplayErrorMsg( WDE_NOINITCONTROLOBJECTS );
        return ( FALSE );
    }

    WdeCtl3DInit( app_inst );
    WdeGetScreenPosOption( &rect );

    /* load the accelerator table */
    WdeAccel = LoadAccelerators( app_inst, "WdeAccelTable");

    /* if the window could not be created return FALSE */
    if( WdeAccel == (HACCEL)NULL ) {
        WdeDisplayErrorMsg( WDE_LOADACCELFAILED );
        return ( FALSE );
    }

    GetWindowRect( GetDesktopWindow(), &screen );

    if( !IntersectRect( &t, &screen, &rect ) ) {
        t.right  = rect.right  - rect.left;
        t.bottom = rect.bottom - rect.top;
        t.left   = min( 0, ( screen.right  - screen.left - t.right  ) )/2;
        t.top    = min( 0, ( screen.bottom - screen.top  - t.bottom ) )/2;
        t.right  += t.left;
        t.bottom += t.top;
    } else {
        t = rect;
    }

    title = WdeAllocRCString( WDE_APPTITLE );
    /* attempt to create the main application window */
    hWinWdeMain =
        CreateWindow( WdeMainClass, title, WS_OVERLAPPEDWINDOW,
                      t.left, t.top, t.right  - t.left, t.bottom - t.top,
                      (HWND) NULL, (HMENU) NULL, app_inst, NULL );
    if( title ) {
        WdeFreeRCString( title );
    }

    /* if the window could not be created return FALSE */
    if( hWinWdeMain == NULL ) {
        WdeDisplayErrorMsg( WDE_NOCREATEMAINWINDOW );
        return( FALSE );
    }

    hWinWdeMDIClient = WdeCreateMDIClientWindow ( hWinWdeMain, app_inst );

    /* attempt to create the main application info window */
    if( !WdeCreateInfoWindow ( hWinWdeMain, app_inst ) ) {
        WdeDisplayErrorMsg( WDE_NOCREATEINFOWINDOW );
        return ( FALSE );
    }

    if( !WdeCreateStatusLine ( hWinWdeMain, app_inst ) ) {
        WdeDisplayErrorMsg( WDE_NOCREATESTATUSLINE );
        return ( FALSE );
    }

    WdeInitialMenu = GetMenu( hWinWdeMain );
    WdeCurrentMenu = WdeInitialMenu;
    WdeResMenu     = LoadMenu( app_inst, "WdeResMenu" );
    WdeDDEMenu     = LoadMenu( app_inst, "WdeDDEMenu" );

    if( IsDDE ) {
        WdeSetAppMenuToRes( TRUE );
    }


    if( !WdeInitialMenu || !WdeResMenu ) {
        WdeDisplayErrorMsg( WDE_NOINITMENUS );
        return( FALSE );
    }

    if( !WdeInitHints() ) {
        WdeDisplayErrorMsg( WDE_NOINITHINTS );
        return( FALSE );
    }

    WdeInitRibbon ( app_inst );

    if( WdeGetOption( WdeOptIsRibbonVisible ) ) {
        WdeShowRibbon();
    }

    /* if the window was created Show and Update it */
    if( WdeGetOption( WdeOptIsScreenMax ) ) {
        ShowWindow ( hWinWdeMain, SW_SHOWMAXIMIZED );
    } else {
        ShowWindow( hWinWdeMain, SW_SHOWNORMAL );
    }
    UpdateWindow( hWinWdeMain );

    WdeSetFontList     ( hWinWdeMain );

    if( !IsDDE ) {
        WdeDisplayAboutBox ( hInstWde, hWinWdeMain, 1125 );
    }

    if( IsDDE ) {
        WdeInitToolMenu( app_inst, WdeDDEMenu );
    } else {
        WdeInitToolMenu( app_inst, WdeResMenu );
    }
    WdeInitControls( app_inst );

    if( WdeGetOption( WdeOptIsCntlsTBarVisible ) ) {
        if( !WdeCreateControlsToolBar ( ) ) {
            WdeDisplayErrorMsg( WDE_NOCREATETOOLBOX );
            return( FALSE );
        }
    }

    SetFocus( hWinWdeMain );

    return( TRUE );

}

Bool WdeWasAcceleratorHandled ( MSG *msg )
{

    if ( !TranslateMDISysAccel ( hWinWdeMDIClient, msg ) &&
         !TranslateAccelerator ( hWinWdeMain, WdeAccel, msg ) ) {
        return ( FALSE );
    }
    return ( TRUE );
}

void WdeSetAppMenuToRes( Bool set_to_res_menu )
{
    HMENU menu;
    HMENU new_menu;

    WdeShowInfoWindow( set_to_res_menu );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -