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

📄 memwnd.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                }
                memset( ptr, ' ', 9 - len );
                ptr += 9 - len;
                i += 4;
            }
            if( offset + i >= limit ) break;
            ptr = GenByte( data[i+3], ptr );
            ptr = GenByte( data[i+2], ptr );
            ptr = GenByte( data[i+1], ptr );
            ptr = GenByte( data[i], ptr );
            *ptr = ' ';
            ptr++;
        }
        if( i < digits ) {
            len = ( ( digits - i ) / 4 ) * 9;
            memset( ptr, ' ', len );
            ptr += len;
        }
        break;
    }
    *ptr = ' ';
    ptr ++;
    for( i=0; i < digits; i++ ) {
        if( offset + i >= limit ) {
            memset( ptr, ' ', digits - i );
            ptr += digits - i;
            break;
        }
        if( isalnum( data[i] ) || ispunct( data[i] ) ) {
            *ptr = data[i];
        } else {
            *ptr = '.';
        }
        ptr ++;
    }
    *ptr = '\0';
    return( TRUE );
} /* GenLine */

static void MySetScrollPos( MemWndInfo *info, DWORD offset ) {

    DWORD       val;

    val = ( ( offset - info->base ) * SCROLL_RANGE ) /
          ( info->limit - info->base );
    SetScrollPos( info->scrlbar, SB_CTL, val, TRUE );
}

static DWORD ScrollPosToOffset( WORD pos, MemWndInfo *info ) {

    DWORD       offset;

    offset = ( pos * ( info->limit - info->base ) ) / SCROLL_RANGE;
    offset += info->base;
    return( offset );
} /* ScrollPosToOffset */

/*
 * RedrawMemWnd
 */

static void RedrawMemWnd( HWND hwnd, HDC dc, MemWndInfo *info ) {

    unsigned    i;
    DWORD       offset;
    RECT        area;
    RECT        fill;
    HBRUSH      wbrush;
    HFONT       old_font;
    POINT       txtsize;
    BOOL        rc;

    if( CurFont != GetMonoFont() ) CalcTextDimensions( hwnd, dc, info );
    old_font = SelectObject( dc, CurFont );
    if(  ISCODE( info ) ) {
        MySetScrollPos( info, ( info->limit - info->base) / 2 );
        RedrawAsCode( dc, info );
        return;
    }
    i = 0;
    area.left = 0;
    area.top = 0;
    area.right = info->width;
    area.bottom = FontHeight;
    fill.right = area.right;
    offset = info->offset;
    wbrush = GetStockObject( WHITE_BRUSH );
    while( offset < info->limit ) {
        rc = GenLine( info->bytesdisp, info->limit, info->disp_type,
                      info->sel , Buffer, offset );
        DrawText( dc, Buffer, -1, &area, DT_LEFT | DT_NOCLIP );
        fill.top = area.top;
        fill.bottom = area.bottom;
        GetTextExtentPoint( dc, Buffer, strlen( Buffer ), &txtsize );
        fill.left = area.left + txtsize.x;
        FillRect( dc, &fill, wbrush );
        area.top += FontHeight;
        area.bottom += FontHeight;
        offset += info->bytesdisp;
        i++;
        if( i > info->lastline ) break;
    }
    if( area.top < ( info->lastline + 1 ) * FontHeight ) {
        area.bottom = ( info->lastline + 1 ) * FontHeight;
        FillRect( dc, &area, wbrush );
    }
    MySetScrollPos( info, info->offset );
    SelectObject( dc, old_font );
} /* RedrawMemWnd */

static unsigned BytesToDisplay( unsigned width, WORD type ) {

    unsigned    bytes;

    bytes = width / FontWidth;
    if( bytes < NO_DATA_SPACE ) {
        bytes = 0;
    } else {
        switch( type ) {
        case MEMINFO_WORD:
            bytes = 2 * ( ( bytes - NO_DATA_SPACE ) / 7 );
            break;
        case MEMINFO_DWORD:
            bytes = 4 * ( ( bytes - NO_DATA_SPACE ) / 14 );
            break;
        case MEMINFO_BYTE:
        default:
            bytes = ( bytes - NO_DATA_SPACE ) / 4;
//          if( bytes > 16 ) bytes = 16;
            break;
        }
    }
    if( bytes < 1 ) bytes = 1;
    if( bytes > MAX_BYTES ) bytes = MAX_BYTES;
    return( bytes );
} /* BytesToDisplay */

/*
 * CalcTextDimensions - find the number of bytes to display on a line,
 *                      the number of lines in the window, whether to
 *                      display scroll bars etc... when the window is
 *                      resized or the font changes
 */
static void CalcTextDimensions( HWND hwnd, HDC dc, MemWndInfo *info ) {

    BOOL        owndc;
    RECT        rect;
    WORD        width;
    WORD        height;
    HFONT       old_font;
    unsigned    lines;
    BOOL        need_scrlbar;
    unsigned    scrl_width;
    POINT       fontsize;

    if( dc == NULL ) {
        dc = GetDC( hwnd );
        owndc = TRUE;
    } else {
        owndc = FALSE;
    }

    CurFont = GetMonoFont();
    old_font = SelectObject( dc, GetMonoFont() );
    GetTextExtentPoint( dc, "0000000000", 10, &fontsize );
    FontWidth = fontsize.x / 10;
    FontHeight = fontsize.y;

    GetClientRect( hwnd, &rect );
    width = rect.right - rect.left;
    height = rect.bottom - rect.top;
    info->lastline = height / FontHeight;

    /*
     * decide if we need a scroll bar and calculate the number
     * of bytes to display on each line
     */

    info->bytesdisp = BytesToDisplay( width, info->disp_type );
    lines = info->limit / info->bytesdisp;
    if( ( info->limit - info->base ) % info->bytesdisp != 0 ) lines++;
    if( ISCODE( info ) ) {
        need_scrlbar = NeedScrollBar( info );
    } else {
        need_scrlbar = ( lines > info->lastline );
    }
    if( need_scrlbar ) {
        scrl_width = GetSystemMetrics( SM_CXVSCROLL );
        if( width < scrl_width ) {
            width = 0;
        } else {
            width -= scrl_width;
        }
        MoveWindow( info->scrlbar, width, 0, scrl_width, height, TRUE );
        ShowWindow( info->scrlbar, SW_NORMAL );
        info->bytesdisp = BytesToDisplay( width, info->disp_type );
    } else {
        ShowWindow( info->scrlbar, SW_HIDE );
    }
    info->offset -= ( info->offset - info->base ) % info->bytesdisp;
    info->width = width;
    SelectObject( dc, old_font );
    if( owndc ) ReleaseDC( hwnd, dc );
}

static void ReSizeMemBox( HWND hwnd, DWORD size, MemWndInfo *info ) {

    HDC         dc;
    RECT        area;
    HBRUSH      wbrush;

    dc = GetDC( hwnd );
//    old_font = SelectObject( dc, CurFont );
    CalcTextDimensions( hwnd, dc, info );

    /*
     * Clear edge areas that may not get refreshed
     */
    wbrush = GetStockObject( WHITE_BRUSH );
    area.top = 0;
    area.bottom = HIWORD( size );
    area.right = LOWORD( size );
    area.left = area.right - 5 * FontWidth;
    FillRect( dc, &area, wbrush );
    area.top = area.bottom - FontHeight;
    area.left = 0;
    FillRect( dc, &area, wbrush );
    RedrawMemWnd( hwnd, dc, info );
    InvalidateRect( info->scrlbar, NULL, TRUE );
    UpdateWindow( info->scrlbar );
//    SelectObject( dc, old_font );
    ReleaseDC( hwnd, dc );
} /* ReSizeMembox */

static void ScrollData( HWND hwnd, WORD wparam, WORD pos, MemWndInfo *info ) {

    HDC         dc;
    DWORD       offset;

    switch( wparam ) {
    case SB_LINEUP:
        if( info->offset == info->base ) return;
        info->offset -= info->bytesdisp;
        break;
    case SB_LINEDOWN:
        if( info->limit - info->offset <= info->bytesdisp ) return;
        info->offset += info->bytesdisp;
        break;
    case SB_PAGEUP:
        if( info->offset == info->base ) return;
        if( info->offset < info->lastline * info->bytesdisp + info->base ) {
            info->offset = info->base;
        } else {
            info->offset -= info->lastline * info->bytesdisp;
        }
        break;
    case SB_PAGEDOWN:
        if( info->offset + info->lastline * info->bytesdisp > info->limit ) {
            if( info->limit - info->offset <= info->bytesdisp ) {
                return;
            } else {
                info->offset = info->limit -
                           ( ( info->limit - info->base ) % info->bytesdisp );
                if( info->offset == info->limit ) {
                    info->offset = info->limit - info->bytesdisp;
                }
            }
        } else {
            info->offset += info->lastline * info->bytesdisp;
        }
        break;
    case SB_THUMBTRACK:
    case SB_THUMBPOSITION:
        offset = ScrollPosToOffset( pos, info );
        offset -= ( offset - info->base ) % info->bytesdisp;
        info->offset = offset;
        if( offset >= info->limit ) {
            info->offset = info->limit -
                           ( ( info->limit - info->base ) % info->bytesdisp );
        }
        if( offset == info->limit ) {
            info->offset = info->limit - info->bytesdisp;
        }
        break;
    case SB_TOP:
        info->offset = info->base;
        break;
    case SB_BOTTOM:
        info->offset = info->limit - info->lastline * info->bytesdisp;
        break;
    default:
        return;
    }
    dc = GetDC( hwnd );
    RedrawMemWnd( hwnd, dc, info );
    ReleaseDC( hwnd, dc );
} /* ScrollData */


BOOL __export FAR PASCAL OffsetProc( HWND hwnd, WORD msg, WORD wparam,
                                    DWORD lparam )
{
    char                buf[41];
    unsigned long       offset;
    char                *end;
    HWND                parent;
    HWND                ctl;
    MemWndInfo          *info;
    HDC                 dc;
    HCURSOR             hourglass;
    HCURSOR             oldcursor;

    lparam = lparam;
    switch( msg ) {
    case WM_INITDIALOG:
        ctl = GetDlgItem( hwnd, OFF_OFFSET );
        SetFocus( ctl );
        return( FALSE );
        break;
    case WM_COMMAND:
        switch( LOWORD( wparam ) ) {
            case IDOK:
                /* get the request */
                GetDlgItemText( hwnd, OFF_OFFSET, buf, 40 );
                offset = strtoul( buf, &end, 0 );
                if( *end != '\0' ) {
                    while( isspace( *end ) ) end++;
                    if( *end != '\0' ) {
                        RCMessageBox( hwnd, MWND_ENTER_NUMERIC_VALUE,
                                    MemConfigInfo.appname,
                                    MB_OK | MB_ICONEXCLAMATION );
                        break;
                    }
                }
                /* set the offset */
                parent = GetParent( hwnd );
                info = (MemWndInfo *)GetWindowLong( parent, 0 );
                if( offset > info->limit ) {
                    RCMessageBox( hwnd, MWND_OFFSET_TOO_BIG,
                                MemConfigInfo.appname,
                                MB_OK | MB_ICONEXCLAMATION );
                    break;
                }
                if( offset < info->base ) {
                    RCMessageBox( hwnd, MWND_OFFSET_TOO_SMALL,
                                MemConfigInfo.appname,
                                MB_OK | MB_ICONEXCLAMATION );
                    break;
                }
                hourglass = LoadCursor( NULL, IDC_WAIT );
                SetCapture( parent );
                oldcursor= SetCursor( hourglass );
                if( ISCODE( info ) ) {
                    info->ins_cnt = GetInsCnt( info, offset );
                } else {
                    offset -= ( offset - info->base ) % info->bytesdisp;
                    info->offset = offset;
                }
                dc = GetDC( parent );
                RedrawMemWnd( parent, dc, info );
                ReleaseDC( parent, dc );
                SetCursor( oldcursor );
                ReleaseCapture();
                /* fall through */
            case IDCANCEL:
                EndDialog( hwnd, FALSE );
                break;
        }
        break;
    default:
        return( FALSE );
    }
    return( TRUE );
}


BOOL __export FAR PASCAL MemDisplayProc( HWND hwnd, UINT msg, WPARAM wparam,
                                    DWORD lparam ) {

    HDC                 dc;
    MemWndInfo          *info;
    PAINTSTRUCT         paint;
    RECT                area;
    HANDLE              inst;
    HMENU               menu;
    BOOL                state;
    DWORD               size;
    HBRUSH              wbrush;
    FARPROC             fp;
    WORD                cmd;


    info = (MemWndInfo *)GetWindowLong( hwnd, 0 );
    switch( msg ) {
    case WM_CREATE:
        RegDisasmRtns();
        info = (MemWndInfo *) ( (CREATESTRUCT *)lparam)->lpCreateParams;
        SetWindowLong( hwnd, 0, (DWORD)info );
        menu = GetMenu( hwnd );
        CheckMenuItem( menu, info->disp_type, MF_CHECKED );
        if( info->autopos ) {
            CheckMenuItem( menu, MEMINFO_AUTO_POS, MF_CHECKED | MF_BYCOMMAND );
        }
        inst = GET_HINSTANCE( hwnd );
        info->scrlbar = CreateWindow(
            "ScrollBar",                /* Window class name */
            "",
            WS_CHILD|SBS_VERT,          /* Window style */
            0,                          /* Initial X position */
            0,                          /* Initial Y position */
            0,                          /* Initial X size */
            0,                          /* Initial Y size */
            hwnd,                       /* Parent window handle */
            NULL,                       /* Window menu handle */
            inst,                       /* Program instance handle */
            NULL);                      /* Create parameters */
        MoveWindow( hwnd, MemConfigInfo.xpos, MemConfigInfo.ypos,
                    MemConfigInfo.xsize, MemConfigInfo.ysize, TRUE );
        ShowWindow( info->scrlbar, SW_HIDE );
        SetScrollRange( info->scrlbar, SB_CTL, 0, SCROLL_RANGE, FALSE );
        if( MemConfigInfo.disp_info ) {
            DisplaySegInfo( hwnd, inst, info );
        }
        break;
    case WM_SIZE:
        if( wparam == SIZE_MAXIMIZED ){
            info->maximized = TRUE;
        } else {
            info->maximized = FALSE;
        }
        ReSizeMemBox( hwnd, lparam, info );
    case WM_MOVE:
        if( info->autopos && IsWindow( info->dialog ) ) {
            PositionSegInfo( info->dialog );
        }
        break;
    case WM_PAINT:
        BeginPaint( hwnd, &paint );
        RedrawMemWnd( hwnd, paint.hdc, info );
        EndPaint( hwnd, &paint );
        break;

⌨️ 快捷键说明

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