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

📄 hwdisp.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            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 <string.h>
#include "heapwalk.h"
#include <windows.h>
#include "jdlg.h"


static FARPROC  DialProc;
static WORD     DialCount = 0;

static unsigned ColorCount( WORD bitcount, WORD clrused ) {

    unsigned    color_count;

    if( bitcount == 1 ) {
        color_count = 2;
    } else if( clrused == 0 ) {
        color_count = 1 << bitcount;
        if( bitcount == 24 ) color_count = 0;
    } else {
        color_count = clrused;
    }
    return( color_count );
} /* ColorCount */

static HWND MkDisplayWin( DWORD captionid, HWND parent )
{

    HWND        hdl;
    char        *caption;

    caption = GetRCString( captionid );
    hdl = CreateWindow(
        ITEM_DISPLAY_CLASS,     /* Window class name */
        caption,                /* Window caption */
        WS_OVERLAPPED|WS_CAPTION
        |WS_SYSMENU|WS_THICKFRAME
        |WS_MAXIMIZEBOX,        /* Window style */
        0,                      /* Initial X position */
        0,                      /* Initial Y position */
        200,                    /* Initial X size */
        100,                    /* Initial Y size */
        parent,                 /* Parent window handle */
        NULL,                   /* Window menu handle */
        Instance,               /* Program instance handle */
        NULL);                  /* Create parameters */
        SetWindowLong( hdl, 0, 0L );
        return( hdl );
}

static HWND ShowBitmapHeapItem( heap_list *hl, HWND parent ) {

    HWND                hdl;
    ResInfo             *info;
    WORD                width;
    WORD                height;
    BITMAPINFOHEADER    *bmheader;

    info = MemAlloc( sizeof( ResInfo ) );
    if( info == NULL ) return( NULL );
    info->type = GD_BITMAP;
    info->hdl = hl->info.ge.hBlock;
    info->res = LockResource( hl->info.ge.hBlock );
    bmheader = (BITMAPINFOHEADER *)info->res;
    if( bmheader->biSize != sizeof( BITMAPINFOHEADER ) ) {
        UnlockResource( info->hdl );
        return( NULL );
    }
    hdl = MkDisplayWin( STR_BITMAP, parent );
    SetWindowLong( hdl, 0, (DWORD)info );
    ShowWindow( hdl, SW_SHOWNORMAL );
    width = bmheader->biWidth;
    width += 2 * GetSystemMetrics( SM_CXFRAME );
    height = bmheader->biHeight;
    height += GetSystemMetrics( SM_CYCAPTION );
    height += GetSystemMetrics( SM_CYFRAME );
    MoveWindow( hdl, 0, 0, width, height, TRUE );
    return( hdl );
}

static HWND ShowIconHeapItem( heap_list *hl, HWND parent ) {

    HWND                hdl;
    ResInfo             *info;
    BITMAPINFOHEADER    *btinfo;
    DWORD               req_size;
    WORD                width;
    WORD                height;

    info = MemAlloc( sizeof( ResInfo ) );
    if( info == NULL ) return( NULL );
    btinfo = (BITMAPINFOHEADER *)LockResource( hl->info.ge.hBlock );
    if( btinfo->biSize == sizeof( BITMAPINFOHEADER ) ) {
        req_size = sizeof( BITMAPINFOHEADER );
        req_size += ColorCount( btinfo->biBitCount, btinfo->biClrUsed ) * sizeof( RGBQUAD );
        req_size += ( btinfo->biWidth * btinfo->biHeight ) / ( 8 / btinfo->biBitCount );
        if( req_size > hl->info.ge.dwBlockSize ) return( NULL );
    }
    info->type = GD_ICON;
    info->hdl = hl->info.ge.hBlock;
    info->res = (char *)btinfo;
    hdl = MkDisplayWin( STR_ICON, parent );
    SetWindowLong( hdl, 0, (DWORD)info );
    width = GetSystemMetrics( SM_CXICON );
    height = GetSystemMetrics( SM_CYICON ) +
             2 * GetSystemMetrics( SM_CYFRAME ) +
             GetSystemMetrics( SM_CYCAPTION );
    SetWindowPos( hdl, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER );
    ShowWindow( hdl, SW_SHOWNORMAL );
    return( hdl );
}

static HWND ShowCursorHeapItem( heap_list *hl, HWND parent ) {

    HWND        hdl;
    ResInfo     *info;
    WORD        width;
    WORD        height;

    info = MemAlloc( sizeof( ResInfo ) );
    if( info == NULL ) return( NULL );
    hdl = MkDisplayWin( STR_CURSOR, parent );
    info->type = GD_CURSOR;
    info->hdl = hl->info.ge.hBlock;
    info->res = LockResource( info->hdl );
    SetWindowLong( hdl, 0, (DWORD)info );
    width = 2 * GetSystemMetrics( SM_CXCURSOR );
    height = GetSystemMetrics( SM_CYCURSOR ) +
             2 * GetSystemMetrics( SM_CYFRAME ) +
             GetSystemMetrics( SM_CYCAPTION );
    SetWindowPos( hdl, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER );
    ShowWindow( hdl, SW_SHOWNORMAL );
    return( hdl );
}

static HWND ShowMenuHeapItem( heap_list *hl, HWND parent ) {

    HWND        hdl;
    HMENU       menu;
    void far    *ptr;
    ResInfo     *info;

    info = MemAlloc( sizeof( ResInfo ) );
    if( info == NULL ) return( NULL );
    info->type = GD_MENU;
    ptr = LockResource( hl->info.ge.hBlock );
    info->hdl = hl->info.ge.hBlock;
    info->res = ptr;
    info->menu_const = NULL;
    menu = LoadMenuIndirect( ptr );
    hdl = MkDisplayWin( STR_MENU, parent );
    SetWindowLong( hdl, 0, (DWORD)info );
    SetMenu( hdl, menu );
    ShowWindow( hdl, SW_SHOWNORMAL );
    return( hdl );
}

BOOL __export FAR PASCAL DialogDispProc( HWND hwnd, WORD msg, WORD wparam,
                                    DWORD lparam )
{
    wparam = wparam;
    lparam = lparam;
    switch( msg ) {
    case WM_INITDIALOG:
        DialCount ++;
        break;
    case WM_SYSCOLORCHANGE:
        Ctl3dColorChange();
        break;
    case WM_CLOSE:
        DestroyWindow( hwnd );
        break;
    case WM_NCDESTROY:
        DialCount --;
        if( DialCount == 0 ) {
            FreeProcInstance( DialProc );
        }
        return( FALSE ); /* we need to let WINDOWS see this message or
                            fonts are left undeleted */
    default:
        return( FALSE );
    }
    return( TRUE );
}

static HWND ShowDialogHeapItem( heap_list *hl, HWND hwnd ) {

    LPSTR       ptr;
    HWND        dial;
    HWND        hdl;
    heap_list   tmp;
    ResInfo     *info;
    char        *rcstr;

    info = MemAlloc( sizeof( ResInfo ) );
    if( info == NULL ) return( NULL );
    info->type = GD_DIALOG;
    ptr = LockResource( hl->info.ge.hBlock );
    if( ptr == NULL ) {
        rcstr = AllocRCString( STR_SHOW );
        RCMessageBox( HeapWalkMainWindow, STR_CANT_LOCK_MEM,
                    rcstr, MB_OK | MB_ICONINFORMATION );
        FreeRCString( rcstr );
        return( NULL );
    }
    info->hdl = hl->info.ge.hBlock;
    info->res = ptr;
    /* this window remains invisible.  it is created only to ensure
       that system resource get freed */
    hdl = MkDisplayWin( STR_NADA, hwnd );
    SetWindowLong( hdl, 0, (DWORD)info );
    ShowWindow( hdl, SW_HIDE );
    if( DialCount == 0 ) {
        DialProc = MakeProcInstance( (FARPROC)DialogDispProc, Instance );
    }

    /*
     * A task's Instance is the same as the selector of its DGROUP
     * so use this fact to get an instance handle to display the
     * dialog
     */

    GetDGroupItem( hl->szModule, &tmp );
    dial = CreateDialogIndirect( (HANDLE) tmp.info.ge.hBlock,
                                 ptr, hdl, (DLGPROC)DialProc );
    if( dial == NULL ) {
        rcstr = AllocRCString( STR_SHOW );
        RCMessageBox( HeapWalkMainWindow, STR_CANT_CREATE_DLG,
                        rcstr, MB_OK | MB_ICONINFORMATION );
        FreeRCString( rcstr );
        return( NULL );
    }
    ShowWindow( dial, SW_SHOW );
    return( dial );
}


static HPALETTE CreateDIBPalette( BITMAPINFO *info )
{
    unsigned            num_colours, i;
    LOGPALETTE          *palette;
    HPALETTE            palette_handle;
    RGBQUAD             *quads;

    num_colours = info->bmiHeader.biClrUsed;
    if( num_colours == 0 && info->bmiHeader.biBitCount != 24 ) {
        num_colours = 1 << info->bmiHeader.biBitCount;
    }

    palette_handle = (HPALETTE)0;

    if( num_colours ) {
        palette = malloc( sizeof( LOGPALETTE ) +
                num_colours * sizeof( PALETTEENTRY ) );
        if( palette == NULL ) return( (HPALETTE)0 );
        palette->palNumEntries = num_colours;
        palette->palVersion = 0x300;

        quads = &info->bmiColors[0];
        for( i = 0; i < num_colours; i++ ) {
            palette->palPalEntry[i].peRed = quads[i].rgbRed;
            palette->palPalEntry[i].peGreen = quads[i].rgbGreen;
            palette->palPalEntry[i].peBlue = quads[i].rgbBlue;
            palette->palPalEntry[i].peFlags = 0;

⌨️ 快捷键说明

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