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

📄 hwdisp.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        }
        palette_handle = CreatePalette( palette );
        free( palette );
    }
    return( palette_handle );
}


static void PaintBitMap( BITMAPINFOHEADER *hdr, HDC dc ) {

    HDC                 mdc;
    HANDLE              oldhdl;
    HBITMAP             map;
    unsigned            color_count;
    char                *bytes;
    HPALETTE            palette;
    HPALETTE            oldpalette;

    color_count = ColorCount( hdr->biBitCount, hdr->biClrUsed );
    bytes = (char *)hdr + sizeof( BITMAPINFOHEADER );
    bytes += color_count * sizeof( RGBQUAD );
    palette = CreateDIBPalette( (BITMAPINFO *)hdr );
    oldpalette = SelectPalette( dc, palette, FALSE );
    RealizePalette( dc );
    map = CreateDIBitmap( dc, (LPBITMAPINFOHEADER)hdr,
      CBM_INIT, bytes, (LPBITMAPINFO)hdr, DIB_RGB_COLORS );
    mdc = CreateCompatibleDC( dc );
    oldhdl = SelectObject( mdc, map );
    BitBlt( dc, 0, 0, hdr->biWidth, hdr->biHeight, mdc, 0, 0, SRCCOPY );
    SelectPalette( dc, oldpalette, FALSE );
    DeleteObject( palette );
    SelectObject( mdc, oldhdl );
    DeleteObject( map );
    DeleteDC( mdc );
} /* PaintBitMap */

/*
 * this is an undocumented windows structure that was determined
 * by experimentation.  It is subject to change by Microsoft
 */
typedef struct cursorheader {
    WORD        xhotspot;
    WORD        yhotspot;
    WORD        width;          /* the width and height fields */
    WORD        height;         /* may be reversed */
    DWORD       I_dont_know_what_the_hell_this_is;
} CursorHeader;

/*
 * PaintCursor - takes a cursor converts it to an icon and
 *               displays it
 */

static void PaintCursor( HWND hwnd, HDC dc, CursorHeader *cursor ) {

    char                *and_mask;
    char                *xor_mask;
    HICON               icon;
    BITMAPINFOHEADER    *tmp;
    RECT                area;
    WORD                width;
    WORD                cursor_width;
    HBRUSH              brush;
    WORD                save_width;

    tmp = (BITMAPINFOHEADER *) ( (char *)cursor + 4 );
    if( tmp->biSize == sizeof( BITMAPINFOHEADER ) ) {
        and_mask = (char *) cursor + 4 + sizeof( BITMAPINFOHEADER ) +
                   2 * sizeof( RGBQUAD );
        xor_mask =  and_mask + ( tmp->biWidth * tmp->biHeight ) / 16;
        icon = CreateIcon( Instance, tmp->biWidth, tmp->biHeight/2,
                        1, 1, and_mask, xor_mask );
    } else {
        and_mask = (char *) cursor + sizeof( CursorHeader );
        xor_mask = and_mask + ( cursor->width * cursor->height ) / 8;
        icon = CreateIcon( Instance, cursor->width, cursor->height,
                            1, 1, and_mask, xor_mask );
    }
    GetClientRect( hwnd, &area );
    cursor_width = GetSystemMetrics( SM_CXCURSOR );
    if( cursor_width * 2 > area.right ) {
        width = cursor_width;
    } else {
        width = area.right / 2;
    }
    save_width = area.left;
    area.left = width;
    brush = GetStockObject( BLACK_BRUSH );
    FillRect( dc, &area, brush );
    area.left = save_width;
    area.right = width;
    brush = GetStockObject( WHITE_BRUSH );
    FillRect( dc, &area, brush );
    SetMapMode( dc, MM_TEXT );
    DrawIcon( dc, 0, 0, icon );
    DrawIcon( dc, width, 0, icon );
    DestroyIcon( icon );
}

static void PaintIcon( HDC dc, ResInfo *info ) {

    BITMAPINFO          *btinfo;
    HICON               icon;
    unsigned            clr_cnt;
    char                *and_mask;
    char                *xor_mask;
    RECT                area;
    WORD                i;
    HBRUSH              brush;

    btinfo = (BITMAPINFO *) (info->res);
    if( btinfo->bmiHeader.biSize == sizeof( BITMAPINFOHEADER ) ) {
        clr_cnt = ColorCount( btinfo->bmiHeader.biBitCount,
                  btinfo->bmiHeader.biClrUsed );
        and_mask = (char *)btinfo + sizeof( BITMAPINFOHEADER ) +
                   clr_cnt * sizeof( RGBQUAD );
        xor_mask = and_mask +
                   ( btinfo->bmiHeader.biWidth * btinfo->bmiHeader.biHeight )
                   / ( 2 * ( 8 / btinfo->bmiHeader.biBitCount ) );
        icon = CreateIcon( Instance, btinfo->bmiHeader.biWidth,
               btinfo->bmiHeader.biHeight/2, 1, 1, and_mask, xor_mask );
        SetMapMode( dc, MM_TEXT );
        brush = GetStockObject( WHITE_BRUSH );
        area.top = 0;
        area.bottom = btinfo->bmiHeader.biHeight;
        area.right = btinfo->bmiHeader.biWidth;
        area.left = area.right + btinfo->bmiHeader.biWidth;
        DrawIcon( dc, btinfo->bmiHeader.biWidth, 0, icon );
        DestroyIcon( icon );
        /* take the mirror image of the icon */
        for( i = 0; i < btinfo->bmiHeader.biHeight / 2; i++ ) {
            BitBlt( dc, 0, btinfo->bmiHeader.biHeight / 2 - i,
                    btinfo->bmiHeader.biWidth, 1, dc,
                    btinfo->bmiHeader.biWidth, i, SRCCOPY );
        }
        FillRect( dc, &area, brush );
    } else {
        icon = info->hdl;
        SetMapMode( dc, MM_TEXT );
        DrawIcon( dc, 0, 0, icon );
    }
}

static void AddRes( HWND hwnd ) {

    WORD        i;

    for( i = 0; i < MAX_RES; i++ ){
        if( ResHwnd[i] == NULL ) {
            ResHwnd[i] = hwnd;
        }
    }
} /* AddRes */

static void DeleteRes( HWND hwnd ) {

    WORD        i;

    for( i=0; i < MAX_RES; i++ ) {
        if( ResHwnd[i] == hwnd ) {
            ResHwnd[i] = NULL;
            break;
        }
    }
} /* DeleteRes */

BOOL __export FAR PASCAL ItemDisplayProc( HWND hwnd, WORD msg, WORD wparam,
                                    DWORD lparam )
{
    ResInfo             *info;
    HDC                 dc;
    PAINTSTRUCT         paint;
    HMENU               menu;
    char                buf[40];
    RECT                area;

    info = (ResInfo *)GetWindowLong( hwnd, 0 );
    switch( msg ) {
    case WM_PAINT:
        switch( info->type ) {
        case GD_BITMAP:
            dc = BeginPaint( hwnd, &paint );
            PaintBitMap( (BITMAPINFOHEADER *) info->res, dc );
            EndPaint( hwnd, &paint );
            break;
        case GD_ICON:
            dc = BeginPaint( hwnd, &paint );
            PaintIcon( dc, info );
            EndPaint( hwnd, &paint );
            break;
        case GD_CURSOR:
            dc = BeginPaint( hwnd, &paint );
            PaintCursor( hwnd, dc, (CursorHeader *)(info->res) );
            EndPaint( hwnd, &paint );
        default:
            return( DefWindowProc( hwnd, msg, wparam, lparam ) );
            break;
        }
        break;
    case WM_SIZE:
        if( info->type == GD_CURSOR ) {
            GetClientRect( hwnd, &area );
            InvalidateRect( hwnd, &area, TRUE );
        }
        return( DefWindowProc( hwnd, msg, wparam, lparam ) );
    case WM_COMMAND:
        if( info->type == GD_MENU ) {
            if( IsWindow( info->menu_const ) ) {
                DestroyWindow( info->menu_const );
            }
            if( DialCount == 0 ) {
                DialProc = MakeProcInstance( (FARPROC)DialogDispProc, Instance );
            }
            info->menu_const = JCreateDialog( Instance, "MENU_CONST", hwnd, (DLGPROC)DialProc );
            menu = GetMenu( hwnd );
            GetMenuString( menu, wparam, buf, 40, MF_BYCOMMAND );
            SetStaticText( info->menu_const, MENU_ITEM, buf );
            sprintf( buf, "0x%04X", wparam );
            SetStaticText( info->menu_const, MENU_CONSTANT, buf );
        }
        break;
    case WM_CLOSE:
        if( info->hdl != NULL ) {
            UnlockResource( info->hdl );
        }
        MemFree( info );
        DeleteRes( hwnd );
        DestroyWindow( hwnd );
        break;
    default:
        return( DefWindowProc( hwnd, msg, wparam, lparam ) );
    }
    return( NULL );
}

void ShowHeapObject( HWND lbhandle )
{
    heap_list   *hl;
    LRESULT     index;
    HWND        dispwnd;
    HWND        memhdl;
    BOOL        is_res;
    char        *rcstr;

    dispwnd = NULL;
    index = SendMessage( lbhandle, LB_GETCURSEL, 0 , 0L );
    if( index == LB_ERR ) {
        rcstr = AllocRCString( STR_SHOW );
        RCMessageBox( HeapWalkMainWindow, STR_NO_ITEM_SELECTED,
                        rcstr, MB_OK | MB_ICONEXCLAMATION );
        FreeRCString( rcstr );
        return;
    }
    hl = HeapList[ index ];
    if( hl->is_dpmi ) {
        memhdl = DispMem( Instance, HeapWalkMainWindow, hl->info.mem.sel, TRUE );
    } else if( hl->info.ge.hBlock != NULL ) {
        memhdl = DispMem( Instance, HeapWalkMainWindow, (WORD)hl->info.ge.hBlock, FALSE );
    }
    if( memhdl == NULL ) return;
    is_res = TRUE;
    if( !hl->is_dpmi && hl->info.ge.wType == GT_RESOURCE &&
                Config.disp_res ) {
        switch( hl->info.ge.wData ) {
        case GD_CURSORCOMPONENT:
            dispwnd = ShowCursorHeapItem( hl, memhdl );
            break;
        case GD_BITMAP:
            dispwnd = ShowBitmapHeapItem( hl, memhdl );
            break;
        case GD_ICONCOMPONENT:
            dispwnd = ShowIconHeapItem( hl, memhdl );
            break;
        case GD_MENU:
            dispwnd = ShowMenuHeapItem( hl, memhdl );
            break;
        case GD_DIALOG:
            dispwnd = ShowDialogHeapItem( hl, memhdl );
            break;
        default:
            dispwnd = NULL;
            is_res = FALSE;
        }
        if( is_res ) {
            if( dispwnd == NULL ) {
                ErrorBox( HeapWalkMainWindow, STR_UNABLE_TO_DISP_GRAPHIC,
                          MB_OK | MB_ICONINFORMATION );
            } else {
                AddRes( dispwnd );
            }
        }
    }
}

⌨️ 快捷键说明

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