📄 wremain.c
字号:
/****************************************************************************
*
* 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 <ddeml.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
#include "waccel.h"
#include "wmenu.h"
#include "wstring.h"
#include "wreglbl.h"
#include "wrehints.h"
#include "wremem.h"
#include "wrememf.h"
#include "wremsg.h"
#include "wremsgs.gh"
#include "wrenames.h"
#include "wreopts.h"
#include "wreres.h"
#include "wreribbn.h"
#include "wrestat.h"
#include "wresvobj.h"
#include "wresvmlt.h"
#include "wrerenam.h"
#include "wre_rc.h"
#include "wrectl3d.h"
#include "wredde.h"
#include "wregcres.h"
#include "wredel.h"
#include "wreaccel.h"
#include "wremenu.h"
#include "wrestr.h"
#include "wredlg.h"
#include "wreimg.h"
#include "wreclip.h"
#include "wresym.h"
#include "wregetfn.h"
#include "wreftype.h"
#include "wremain.h"
#include "wresall.h"
#include "bitmap.h"
#include "wrdll.h"
#include "wrdmsg.h"
#include "wrbitmap.h"
#include "wwinhelp.h"
#include "jdlg.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define ABOUT_TIMER 666
#define ABOUT_TIMEOUT 2000
#define CREATE_NEW_FLAG "/n"
#define NO_IFACE_FLAG "/nointerface"
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
extern int PASCAL WinMain ( HINSTANCE, HINSTANCE, LPSTR, int);
extern LRESULT WINEXPORT WREMainWndProc ( HWND, UINT, WPARAM, LPARAM );
extern Bool WINEXPORT WREAbout ( HWND, WORD, WPARAM, LPARAM );
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static Bool WREInit ( HINSTANCE );
static Bool WREInitInst ( HINSTANCE );
static Bool WREWasAcceleratorHandled ( MSG * );
static HWND WRECreateMDIClientWindow ( HWND, HINSTANCE );
static LRESULT WREHandleMDIArrangeEvents ( WORD );
static void WREUpdateScreenPosOpt ( void );
static Bool WRECleanup ( Bool );
static Bool WREProcessArgs ( char **, int );
static void WREDisplayAboutBox ( HINSTANCE, HWND, UINT );
static void WREHideSessions ( Bool show );
/****************************************************************************/
/* type definitions */
/****************************************************************************/
/****************************************************************************/
/* static variables */
/****************************************************************************/
static HINSTANCE WREInst;
static HACCEL WREAccel;
static HMENU WREMenu;
static Bool WREIsMinimized = FALSE;
static HWND WREMainWin = NULL;
static HWND WREMDIWin = NULL;
static Bool WRECleanupStarted = FALSE;
static Bool WREFatalExit = FALSE;
static char WREMainClass[] = "WREMainClass";
Bool WRECreateNewFiles = FALSE;
Bool WRENoInterface = FALSE;
extern Bool WRERemoveResource ( WREResInfo * );
extern Bool pleaseOpenFile( UINT msg );
/* set the WRES library to use compatible functions */
WResSetRtns(open,close,read,write,lseek,tell,WREMemAlloc,WREMemFree);
static void peekArgs( char **argv, int argc )
{
int i;
for( i = 1; i<argc; i++ ) {
if( !stricmp( argv[i], CREATE_NEW_FLAG ) ) {
//WRECreateNewFiles = TRUE;
} else if( !stricmp( argv[i], NO_IFACE_FLAG ) ) {
WRENoInterface = TRUE;
}
}
}
static void startEditors( void )
{
WRFileType ftype;
WREResInfo *res_info;
Bool editor_started;
Bool ret;
int num_types;
uint_16 type;
if( WREGetNumRes() != 1 ) {
if( WRENoInterface ) {
WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
}
return;
}
editor_started = FALSE;
num_types = 0;
res_info = WREGetCurrentRes();
ftype = res_info->info->file_type;
if( res_info->info->file_name == NULL ) {
ftype = WRIdentifyFile( res_info->info->save_name );
} else {
num_types = res_info->info->dir->NumTypes;
}
if( ( ftype != WR_WIN_RC_STR ) &&
( ftype != WR_WIN_RC_MENU ) &&
( ftype != WR_WIN_RC_ACCEL ) ) {
if( WRENoInterface ) {
if( !editor_started ) {
WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
}
}
return;
}
if( num_types == 1 || num_types == 2 ) {
ret = FALSE;
type = 0;
if( ftype == WR_WIN_RC_STR ) {
type = (uint_16)RT_STRING;
} else if( ftype == WR_WIN_RC_MENU ) {
type = (uint_16)RT_MENU;
} else if( ftype == WR_WIN_RC_ACCEL ) {
type = (uint_16)RT_ACCELERATOR;
}
if( type && WREFindTypeNode( res_info->info->dir, type, NULL ) ) {
ret = WRESetResNamesFromType( res_info, type, FALSE, NULL, 0 );
if( ret ) {
editor_started = WREHandleResEdit();
}
}
} else if( num_types == 0 ) {
if( ftype == WR_WIN_RC_STR ) {
editor_started = WRENewStringResource();
} else if( ftype == WR_WIN_RC_MENU ) {
editor_started = WRENewMenuResource();
} else if( ftype == WR_WIN_RC_ACCEL ) {
editor_started = WRENewAccelResource();
}
}
if( WRENoInterface ) {
if( !editor_started ) {
WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
}
}
return;
}
extern Bool WREIsResInfoWinMsg( LPMSG pmsg );
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 );
}
/* Function to initialize the first instance of WRE */
Bool WREInit ( HINSTANCE app_inst )
{
WNDCLASS wc;
/* fill in the WINDOW CLASS structure for the main window */
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WREMainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = app_inst;
wc.hIcon = LoadIcon ( app_inst, "WREIcon" );
wc.hCursor = LoadCursor ( (HINSTANCE) NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = "WREMenu";
wc.lpszClassName = WREMainClass;
/* register the main window class */
if ( !RegisterClass ( &wc ) ) {
return ( FALSE );
}
/* register the res MDI window class */
if ( !WRERegisterResClass ( app_inst ) ) {
return ( FALSE );
}
return ( TRUE );
}
/* Function to initialize all instances of WRE */
Bool WREInitInst ( HINSTANCE app_inst )
{
RECT r, screen, t;
char *title;
DWORD style;
if( !WRERegisterClipFormats( app_inst ) ) {
WREDisplayErrorMsg( WRE_NOREGISTERCLIPFORMATS );
return( FALSE );
}
if( !JDialogInit() ) {
return( FALSE );
}
WRECtl3DInit( app_inst );
WREInitOpts();
WREInitRibbon( app_inst );
WREInitTypeNames();
WREInitTotalText();
if( !WREInitResources( app_inst ) ) {
return( FALSE );
}
/* load the accelerator table */
WREAccel = LoadAccelerators( app_inst, "WREAccelTable" );
/* if the window could not be created return FALSE */
if( WREAccel == NULL ) {
WREDisplayErrorMsg( WRE_NOLOADACCELTABLE );
return( FALSE );
}
WREGetScreenPosOption( &r );
GetWindowRect( GetDesktopWindow(), &screen );
IntersectRect( &t, &screen, &r );
title = WREAllocRCString( WRE_APPNAME );
/* attempt to create the main application window */
style = WS_OVERLAPPEDWINDOW;
if( IsRectEmpty( &r ) ) {
WREMainWin =
CreateWindow( WREMainClass, title, style,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
(HWND) NULL, (HMENU) NULL, app_inst, NULL );
} else {
WREMainWin =
CreateWindow( WREMainClass, title, style,
r.left, r.top, r.right - r.left, r.bottom - r.top,
(HWND) NULL, (HMENU) NULL, app_inst, NULL );
}
if( title ) {
WREFreeRCString( title );
}
/* if the window could not be created return FALSE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -