bool WdeProcessArgs( char **argv, int argc ) { int i; bool ok; ok = true; for( i = 1; i < argc; i++ ) { if( !stricmp( argv[i], CREATE_NEW_FLAG ) ) { WdeCreateNewFiles = TRUE; } else if( stricmp( argv[i], DDE_OPT ) ) { if( WRFileExists( argv[i] ) ) { ok = (WdeOpenResource( argv[i] ) && ok); } else if( WdeCreateNewFiles ) { ok = (WdeCreateNewResource( argv[i] ) != NULL && ok); } else { ok = false; } } } if( !ok ) { WdeSetStatusByID( -1, WDE_INPUTFILENOTFOUND ); } return( ok ); }
WINEXPORT LRESULT CALLBACK WdeMainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { HMENU menu; LRESULT ret; bool pass_to_def; WdeResInfo *res_info; WORD wp; about_info ai; if( WdeCleanupStarted ) { if( message == WM_DESTROY ) { PostQuitMessage( 0 ); } return( DefFrameProc( hWnd, hWinWdeMDIClient, message, wParam, lParam ) ); } pass_to_def = TRUE; ret = FALSE; res_info = WdeGetCurrentRes(); menu = WdeGetMenuHandle(); switch( message ) { case WM_INITMENU: handleInitMenu( menu ); break; case WM_USER: WdeSetStatusByID( -1, WDE_ONLYONEINSTANCE ); break; case WM_MENUSELECT: WdeHandleMenuSelect( wParam, lParam ); break; case WM_MEASUREITEM: WdeHandleMeasureItem( (MEASUREITEMSTRUCT *)lParam ); ret = TRUE; pass_to_def = FALSE; break; case WM_DRAWITEM: WdeHandleDrawItem( (DRAWITEMSTRUCT *)lParam ); ret = TRUE; pass_to_def = FALSE; break; case WM_MOVE: if( IsZoomed( hWnd ) ) { WdeSetOption( WdeOptIsScreenMax, TRUE ); } else if( !IsIconic( hWnd ) ) { WdeUpdateScreenPosOpt(); WdeSetOption( WdeOptIsScreenMax, FALSE ); } break; case WM_SIZE: if( wParam == SIZE_MAXIMIZED ) { WdeSetOption( WdeOptIsScreenMax, TRUE ); } else if( wParam != SIZE_MINIMIZED ) { WdeUpdateScreenPosOpt(); WdeSetOption( WdeOptIsScreenMax, FALSE ); } if( wParam != SIZE_MINIMIZED ) { WdeResizeWindows(); } pass_to_def = FALSE; break; case WM_COMMAND: wp = LOWORD( wParam ); if( !WdeIsMenuIDValid( menu, wp ) ) { break; } switch( wp ) { case IDM_SELECT_MODE: case IDM_DIALOG_TOOL: case IDM_PBUTTON_TOOL: case IDM_CBUTTON_TOOL: case IDM_RBUTTON_TOOL: case IDM_GBUTTON_TOOL: case IDM_FRAME_TOOL: case IDM_TEXT_TOOL: case IDM_ICON_TOOL: case IDM_EDIT_TOOL: case IDM_LISTBOX_TOOL: case IDM_COMBOBOX_TOOL: case IDM_HSCROLL_TOOL: case IDM_VSCROLL_TOOL: case IDM_SIZEBOX_TOOL: case IDM_STATUSBAR_TOOL: case IDM_LISTVIEW_TOOL: case IDM_TREEVIEW_TOOL: case IDM_TABCNTL_TOOL: case IDM_ANIMATE_TOOL: case IDM_UPDOWN_TOOL: case IDM_TRACKBAR_TOOL: case IDM_PROGRESS_TOOL: case IDM_HOTKEY_TOOL: case IDM_HEADER_TOOL: case IDM_CUSTOM1_TOOL: case IDM_CUSTOM2_TOOL: WdeSetBaseObject( wp ); pass_to_def = FALSE; break; case IDM_STICKY_TOOLS: WdeToggleStickyTools(); pass_to_def = FALSE; break; case IDM_FMLEFT: case IDM_FMRIGHT: case IDM_FMTOP: case IDM_FMBOTTOM: case IDM_FMVCENTRE: case IDM_FMHCENTRE: case IDM_ESCAPE: case IDM_DELETEOBJECT: case IDM_SPACE_HORZ: case IDM_SPACE_VERT: ret = WdePassToEdit( message, wParam, lParam ); pass_to_def = FALSE; break; case IDM_SELECT_DIALOG: WdeSelectDialog( res_info ); pass_to_def = FALSE; break; case IDM_OPTIONS: WdeDisplayOptions (); pass_to_def = FALSE; break; case IDM_NEW_RES: WdeCreateNewResource( NULL ); pass_to_def = FALSE; break; case IDM_DDE_CLEAR: WdeClearCurrentResource(); pass_to_def = FALSE; break; case IDM_OPEN_RES: WdeOpenResource( NULL ); pass_to_def = FALSE; break; case IDM_SAVE_RES: WdeSaveResource( res_info, FALSE ); pass_to_def = FALSE; break; case IDM_SAVEAS_RES: WdeSaveResource( res_info, TRUE ); pass_to_def = FALSE; break; case IDM_DDE_UPDATE_PRJ: WdeUpdateDDEEditSession(); break; case IDM_PASTEOBJECT: if( FMPasteValid() ) { ret = WdePassToEdit( message, wParam, lParam ); } pass_to_def = FALSE; break; case IDM_CUTOBJECT: case IDM_COPYOBJECT: ret = WdePassToEdit( message, wParam, lParam ); pass_to_def = FALSE; break; case IDM_SAME_WIDTH: WdeSameSize( R_RIGHT ); pass_to_def = FALSE; break; case IDM_SAME_HEIGHT: WdeSameSize( R_BOTTOM ); pass_to_def = FALSE; break; case IDM_SAME_SIZE: WdeSameSize( R_BOTTOM | R_RIGHT ); pass_to_def = FALSE; break; case IDM_SIZETOTEXT: WdeHandleSizeToText(); pass_to_def = FALSE; break; case IDM_GOTO_INFOBAR: WdeSetFocusToInfo(); pass_to_def = FALSE; break; case IDM_GOTO_OBJECT: WdeHandleGotoCurrentObject(); pass_to_def = FALSE; break; case IDM_DIALOG_RESTORE: WdeRestoreCurrentDialog(); pass_to_def = FALSE; break; case IDM_TAB: case IDM_STAB: WdeHandleTabEvent( wp == IDM_TAB ); pass_to_def = FALSE; break; #if 0 /* this strategy has been rejected in favor of the hide option */ case IDM_REMOVE_DIALOG: WdeRemoveDialog( res_info ); pass_to_def = FALSE; break; #endif case IDM_HIDE_DIALOG: WdeHideCurrentDialog(); pass_to_def = FALSE; break; case IDM_TEST_MODE: WdeHandleTestModeMenu( res_info ); pass_to_def = FALSE; break; case IDM_DIALOG_NEW: if( WdeCreateNewDialog( NULL, res_info->is32bit ) ) { WdeHandleGotoCurrentObject(); } pass_to_def = FALSE; break; case IDM_DIALOG_SAVE: case IDM_DIALOG_SAVEAS: case IDM_DIALOG_SAVEINTO: WdeSaveCurrentDialog( wp ); pass_to_def = FALSE; break; case IDM_SET_ORDER: case IDM_SET_TABS: case IDM_SET_GROUPS: WdeSetDialogMode( wp ); pass_to_def = FALSE; break; case IDM_DEFINEOBJECT: case IDM_GEN_DEFINEOBJECT: if( !WdeDefineCurrentObject( wp ) ) { WdeWriteTrail( "WdeResWndProc: Define failed!" ); } pass_to_def = FALSE; break; case IDM_MDI_CASCADE: case IDM_MDI_TILEV: case IDM_MDI_TILEH: case IDM_MDI_ARRANGE: WdeHandleMDIArrangeEvents( wp ); pass_to_def = FALSE; break; case IDM_EXIT: /* clean up before we exit */ PostMessage( hWinWdeMain, WM_CLOSE, 0, 0 ); break; case IDM_SELCUST1: case IDM_SELCUST2: if( !WdeSetCurrentCustControl( wp - IDM_SELCUST1 ) ) { WdeWriteTrail( "WdeMainWndProc: WdeSetCurrentCustControl failed!" ); WdeSetStatusByID( -1, WDE_SETFAILED ); } pass_to_def = FALSE; break; case IDM_MS_CUSTOM: WdeLoadCustomLib( TRUE, FALSE ); pass_to_def = FALSE; break; #ifndef __NT__ case IDM_BOR_CUSTOM: WdeLoadCustomLib( FALSE, FALSE ); pass_to_def = FALSE; break; #endif case IDM_LOADLIB: WdeLoadCustomLib( FALSE, TRUE ); pass_to_def = FALSE; break; case IDM_WRITE_SYMBOLS: WdeResourceHashTableAction( res_info, WRITE_HASH ); pass_to_def = FALSE; break; case IDM_LOAD_SYMBOLS: WdeResourceHashTableAction( res_info, LOAD_HASH ); pass_to_def = FALSE; break; case IDM_VIEW_SYMBOLS: WdeResourceHashTableAction( res_info, VIEW_HASH ); pass_to_def = FALSE; break; case IDM_SHOW_TOOLS: WdeHandleShowToolsMenu(); pass_to_def = FALSE; break; case IDM_SHOW_RIBBON: WdeShowRibbon(); pass_to_def = FALSE; break; case IDM_HELP: WdeHelpRoutine(); pass_to_def = FALSE; break; case IDM_HELP_SEARCH: WdeHelpSearchRoutine(); pass_to_def = FALSE; break; case IDM_HELP_ON_HELP: WdeHelpOnHelpRoutine(); pass_to_def = FALSE; break; case IDM_ABOUT: ai.owner = hWnd; ai.inst = hInstWde; ai.name = AllocRCString( WDE_ABOUT_NAME ); ai.version = AllocRCString( WDE_ABOUT_VERSION ); ai.first_cr_year = "1984"; ai.title = AllocRCString( WDE_ABOUT_TITLE ); DoAbout( &ai ); FreeRCString( ai.name ); FreeRCString( ai.version ); FreeRCString( ai.title ); pass_to_def = FALSE; break; } break; case WM_DESTROY: WWinHelp( hWinWdeMain, "resdlg.hlp", HELP_QUIT, 0 ); PostQuitMessage( 0 ); break; case WDE_FATAL_EXIT: WdeFatalExit = TRUE; WdeQueryKillApp( TRUE ); PostMessage( hWinWdeMain, WM_CLOSE, 0, 0 ); break; case WM_ENDSESSION: if ( !wParam ) { WdeFatalExit = FALSE; } break; case WM_QUERYENDSESSION: ret = WdeQueryKillApp( FALSE ); if( ret ) { WdeFatalExit = TRUE; pass_to_def = FALSE; } break; case WM_CLOSE: // this prevents the user from closing the editor during // DDE initialization if( !wParam && !EnableMenuInput ) { return( 0 ); } /* clean up before we exit */ WdeCleanupStarted = TRUE; if( wParam ) { // wParam is non-zero if the DDE connection died WdeFatalExit = TRUE; WdeQueryKillApp( TRUE ); wParam = 0; } if( !WdeCleanup( res_info, WdeFatalExit ) ) { WdeCleanupStarted = FALSE; pass_to_def = FALSE; } } if( pass_to_def ) { ret = DefFrameProc( hWnd, hWinWdeMDIClient, message, wParam, lParam ); } return( ret ); }
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 ); }
bool WdeStartDDEEditSession( void ) { WdeResInfo *rinfo; WdeResDlgItem *ditem; char *filename; HDDEDATA hData; void *data; DWORD ret; uint_32 size; OBJPTR object; bool ok; object = NULL; ditem = WdeAllocResDlgItem(); ok = (ditem != NULL); if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hFileItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); ok = (hData != (HDDEDATA)NULL); } if( ok ) { filename = (char *)WdeHData2Mem( hData ); DdeFreeDataHandle( hData ); ok = (filename != NULL); } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hIs32BitItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); if( hData != (HDDEDATA)NULL ) { ditem->is32bit = TRUE; DdeFreeDataHandle( hData ); } } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hNameItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); ok = (hData != (HDDEDATA)NULL); } if( ok ) { data = WdeHData2Mem( hData ); DdeFreeDataHandle( hData ); ok = (data != NULL); } if( ok ) { ditem->dialog_name = WRMem2WResID( data, ditem->is32bit ); ok = (ditem->dialog_name != NULL); WRMemFree( data ); } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hDataItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); if( hData != (HDDEDATA)NULL ) { data = WdeHData2Mem( hData ); size = (int)DdeGetData( hData, NULL, 0, 0 ); DdeFreeDataHandle( hData ); if( data != NULL ) { ditem->dialog_info = WdeMem2DBI( (uint_8 *)data, size, ditem->is32bit ); ok = (ditem->dialog_info != NULL); WRMemFree( data ); } else { ok = false; } } } if( ok ) { rinfo = WdeCreateNewResource( filename ); ok = (rinfo != NULL); } if( ok ) { if( ditem->dialog_info != NULL ) { ok = WdeOpenDialogFromResInfo( rinfo, ditem ); if( ok ) { WdeAddResDlgItemToResInfo( rinfo, ditem ); object = ditem->object; } } else { object = WdeCreateNewDialog( ditem->dialog_name, ditem->is32bit ); if( ditem != NULL ) { WdeFreeResDlgItem( &ditem, TRUE ); } ditem = NULL; } ok = ok && (object != NULL); } if( ok ) { MakeObjectCurrent( object ); } if( !ok ) { if( ditem != NULL ) { WdeFreeResDlgItem( &ditem, TRUE ); } if( rinfo != NULL ) { WdeFreeResInfo( rinfo ); } } if( filename != NULL ) { WRMemFree( filename ); } return( ok ); }