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

📄 wmain.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

                case IDM_STR_ABOUT:
                    WDisplayAboutBox ( WGetEditInstance(), einfo->win, 0 );
                    pass_to_def = FALSE;
                    break;
            }
            break;

        case WM_DESTROY:
            WWinHelp( hWnd, "resstr.hlp", HELP_QUIT, 0 );
            WCleanup( einfo );
            break;

        case WM_CLOSE:
            ret = TRUE;
            pass_to_def = WHandleWM_CLOSE( einfo, (Bool)wParam );
            wParam = 0;
            break;
    }

    if ( pass_to_def ) {
        ret = DefWindowProc( hWnd, message, wParam, lParam );
    }

    return ( ret );
}

Bool WQuerySave( WStringEditInfo *einfo, Bool force_exit )
{
    return( WQuerySaveRes( einfo, force_exit ) &&
            WQuerySaveSym( einfo, force_exit ) );
}

Bool WQuerySaveRes( WStringEditInfo *einfo, Bool force_exit )
{
    int         msg_ret;
    int         ret;
    UINT        style;
    char        *title;
    char        *text;

    ret = TRUE;

    if( einfo && einfo->info->modified ) {
        msg_ret = IDYES;
        if( einfo->info->stand_alone ) {
            if( force_exit ) {
                style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;
            } else {
                style = MB_YESNOCANCEL | MB_APPLMODAL | MB_ICONEXCLAMATION;
            }
            title = WCreateEditTitle( einfo );
            text = WAllocRCString( W_UPDATEMODIFIEDSTRING );
            msg_ret = MessageBox( einfo->edit_dlg, text, title, style );
            if( text ) {
                WFreeRCString( text );
            }
            if( title ) {
                WMemFree( title );
            }
        }
        if( msg_ret == IDYES ) {
            if( einfo->info->stand_alone ) {
                ret = WSaveObject( einfo, FALSE, FALSE );
            } else {
                SendMessage( einfo->info->parent, STRING_PLEASE_SAVEME, 0,
                             (LPARAM) einfo->hndl );
            }
        } else if( msg_ret == IDCANCEL ) {
            ret = FALSE;
        }
    }

    return( ret );
}

Bool WQuerySaveSym( WStringEditInfo *einfo, Bool force_exit )
{
    int         ret;
    UINT        style;
    char        *title;
    char        *text;

    if( !einfo || !einfo->info->stand_alone ) {
        return( TRUE );
    }

    if( !WRIsHashTableDirty( einfo->info->symbol_table ) ) {
        return( TRUE );
    }

    if( force_exit ) {
        style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;
    } else {
        style = MB_YESNOCANCEL | MB_APPLMODAL | MB_ICONEXCLAMATION;
    }

    title = WCreateEditTitle( einfo );
    text = WAllocRCString( W_UPDATEMODIFIEDSYM );
    ret = MessageBox( einfo->edit_dlg, text, title, style );
    if( text ) {
        WFreeRCString( text );
    }
    if( title ) {
        WMemFree( title );
    }

    if( ret == IDYES ) {
        if( einfo->info->symbol_file == NULL ) {
            char        *fname;
            if( !einfo->file_name ) {
                fname = einfo->info->file_name;
            } else {
                fname = einfo->file_name;
            }
            einfo->info->symbol_file = WCreateSymName( fname );
        }
        return( WSaveSymbols( einfo, einfo->info->symbol_table,
                              &einfo->info->symbol_file, FALSE ) );
    } else if( ret == IDCANCEL ) {
        return( FALSE );
    }

    return( TRUE );
}

Bool WHandleWM_CLOSE( WStringEditInfo *einfo, Bool force_exit )
{
    Bool        ret;

    ret = TRUE;

    if( einfo ) {
        if( einfo->info->modified ||
            WRIsHashTableDirty( einfo->info->symbol_table ) ) {
            ret = WQuerySave( einfo, force_exit );
        }
        if( ret ) {
            SendMessage( einfo->info->parent, STRING_I_HAVE_CLOSED, 0,
                         (LPARAM) einfo->hndl );
            WUnRegisterEditSession( WGetEditSessionHandle( einfo ) );
        }
    }

    return( ret );
}

void WHandleMemFlags( WStringEditInfo *einfo )
{
    char        *rtext;
    char        *ntext;
    WResID      *rname;

    ntext = WAllocRCString( W_STRINGNAMES );
    if( einfo && einfo->current_block && ntext ) {
        WSetStatusByID( einfo->wsb, W_CHANGESTRINGMEMFLAGS, -1 );
        // alloc space for ntext and two 16 bit ints
        rtext = (char *)WMemAlloc( strlen(ntext) + 20 );
        if( rtext ) {
            sprintf( rtext, ntext, einfo->current_block->blocknum & 0xfff0,
                     ( einfo->current_block->blocknum  & 0xfff0 ) + 16 - 1 );
        }
        rname = WResIDFromStr( rtext );
        if( rname != NULL ) {
            einfo->info->modified |=
                WChangeMemFlags( einfo->win, &einfo->current_block->MemFlags,
                                 rname, WGetEditInstance(),
                                 WStrHelpRoutine );
             WMemFree( rname );
        }
        WFreeRCString( ntext );
        WSetStatusReadyText( einfo->wsb );
    }
}

Bool WQueryClearRes( WStringEditInfo *einfo )
{
    int         ret;
    UINT        style;
    char        *title;
    char        *text;

    if( einfo ) {
        style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;
        text = WAllocRCString( W_STRINGCLEARWARNING );
        title = WAllocRCString( W_STRINGCLEARTITLE );
        ret = MessageBox( einfo->edit_dlg, text, title, style );
        if( text ) {
            WFreeRCString( text );
        }
        if( title ) {
            WFreeRCString( title );
        }
        if( ret == IDYES ) {
            return( TRUE );
        }
    }

    return( FALSE );
}

void WHandleClear( WStringEditInfo *einfo )
{
    if( einfo->tbl && einfo->tbl->first_block ) {
        if( WQueryClearRes( einfo ) ) {
            WResetEditWindow( einfo );
            SendDlgItemMessage( einfo->edit_dlg, IDM_STREDLIST,
                                LB_RESETCONTENT, 0, 0 );
            WFreeStringTableBlocks( einfo->tbl->first_block );
            einfo->tbl->first_block = NULL;
            einfo->current_block = NULL;
            einfo->current_string = 0;
            einfo->current_pos = -1;
            if( einfo->info->stand_alone ) {
                if( einfo->file_name != NULL ) {
                    WMemFree( einfo->file_name );
                    einfo->file_name = NULL;
                    WSetEditTitle( einfo );
                }
                if( einfo->info->symbol_table ) {
                    WRFreeHashTable( einfo->info->symbol_table );
                    einfo->info->symbol_table = WRInitHashTable();
                }
            }
            einfo->info->modified = TRUE;
            SetFocus( einfo->edit_dlg );
            WSetStatusByID( einfo->wsb, W_STRINGCLEARMSG, -1 );
        }
    }
}

void WUpdateScreenPosOpt ( HWND win )
{
    RECT        rect;

    GetWindowRect ( win, &rect );

    WSetScreenPosOption ( &rect );
}

void WResizeWindows ( WStringEditInfo *einfo )
{
    RECT  rect;

    if ( !einfo ) {
        einfo = WGetCurrentEditInfo ();
    }

    if ( einfo && einfo->win ) {
        GetClientRect ( einfo->win, &rect );
        WResizeStringEditWindow ( einfo, &rect );
        WResizeStatusWindows ( einfo->wsb, &rect );
        WResizeRibbon ( einfo, &rect );
    }
}

void WDisplayAboutBox ( HINSTANCE inst, HWND parent, UINT msecs )
{
    FARPROC     lpProcAbout;

    lpProcAbout = MakeProcInstance ( (FARPROC) WAbout, inst );
    JDialogBoxParam( inst, "WAboutBox", parent, (DLGPROC) lpProcAbout,
                     (LPARAM) &msecs  );
    FreeProcInstance ( lpProcAbout );
}

Bool WINEXPORT WAbout( HWND hDlg, WORD message, WPARAM wParam, LPARAM lParam )
{
    UINT        msecs, timer, start;
    HDC         dc, tdc;
    HBITMAP     old;
    HWND        w666;
    RECT        rect, arect;
    PAINTSTRUCT ps;
    WORD        w;
    char        *title;

    static BITMAP    bm;
    static HBITMAP   logo;
    static HBRUSH    brush;
    static COLORREF  color;

    switch( message ) {

        case WM_SYSCOLORCHANGE:
            WCtl3dColorChange ();
            break;

        case WM_DESTROY:
            if( logo ) {
                DeleteObject( logo );
            }
            if( brush ) {
                DeleteObject( brush );
            }
            break;

        case WM_INITDIALOG:
            msecs = *((UINT *)lParam);
            if( msecs ) {
                timer = SetTimer( hDlg, ABOUT_TIMER, msecs, NULL );
                if( timer ) {
                    SetWindowLong( hDlg, DWL_USER, (LONG)timer );
                    ShowWindow( GetDlgItem( hDlg, IDOK ), SW_HIDE );
                    title = WAllocRCString( W_STRINGAPPTITLE );
                    SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)title );
                    if( title ) {
                        WFreeRCString( title );
                    }
                }
            }

            logo = LoadBitmap ( WGetEditInstance(), "AboutLogo" );

            //color = RGB(128,128,128);
            color = GetSysColor ( COLOR_BTNFACE );
            brush = CreateSolidBrush ( color );

            GetObject ( logo, sizeof(BITMAP), &bm );
            return ( TRUE );

#if 0
#ifdef __NT__
        case WM_CTLCOLORSTATIC:
            if ( brush ) {
                dc = (HDC) wParam;
                SetBkColor ( dc, color );
                return ( (LRESULT) brush );
            }
            break;
#else
        case WM_CTLCOLOR:
            if ( brush ) {
                dc = (HDC) wParam;
                if ( HIWORD(lParam) == CTLCOLOR_STATIC ) {
                    SetBkColor ( dc, color );
                }
                return ( (LRESULT) brush );
            }
            break;
#endif

        case WM_ERASEBKGND:
            if ( brush ) {
                GetClientRect( hDlg, &rect );
                UnrealizeObject( brush );
                FillRect( (HDC)wParam, &rect, brush );
                return ( TRUE );
            }
            break;
#endif

        case WM_PAINT:
            dc = BeginPaint ( hDlg, &ps );
            if ( dc ) {
                w666 = GetDlgItem ( hDlg, 666 );
                GetClientRect ( w666, &rect );
                GetClientRect ( hDlg, &arect );
                start = ( arect.right - arect.left - bm.bmWidth ) / 2;
                MapWindowPoints ( w666, hDlg, (POINT *) &rect, 2 );
                tdc = CreateCompatibleDC ( dc );
                old = SelectObject ( tdc, logo );
                BitBlt ( dc, start, rect.top + 20, bm.bmWidth, bm.bmHeight,
                         tdc, 0, 0, SRCCOPY );
                SelectObject ( tdc, old );
                DeleteDC ( tdc );
                EndPaint ( hDlg, &ps );
            }
            break;

        case WM_TIMER:
            timer = (UINT) GetWindowLong ( hDlg, DWL_USER );
            if ( timer ) {
                KillTimer ( hDlg, timer );
            }
            EndDialog ( hDlg, TRUE );
            return ( TRUE );
            break;

        case WM_COMMAND:
            w = LOWORD(wParam);
            if ( ( w == IDOK ) || ( w == IDCANCEL ) ) {
                timer = (UINT) GetWindowLong ( hDlg, DWL_USER );
                if ( timer ) {
                    KillTimer ( hDlg, timer );
                }
                EndDialog(hDlg, TRUE);
                return ( TRUE );
            }
            break;

    }

    return ( FALSE );
}

Bool WCleanup ( WStringEditInfo *einfo )
{
    HWND        owner;
    Bool        ok;

    ok = ( einfo != NULL );

    if ( ok ) {
        owner = (HWND)NULL;
        if( !einfo->info->stand_alone ) {
            owner = GetWindow( einfo->win, GW_OWNER );
        }
        einfo->win = (HWND)NULL;
        WFreeStringEInfo ( einfo );
        if( owner != (HWND)NULL ) {
            BringWindowToTop( owner );
        }
    }

    return ( ok );
}

void CALLBACK WStrHelpRoutine( void )
{
    WStringEditInfo     *einfo;

    einfo = WGetCurrentEditInfo();
    if( einfo ) {
        WWinHelp( einfo->win, "resstr.hlp", HELP_CONTENTS, 0 );
    }
}

⌨️ 快捷键说明

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