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

📄 icon.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 2 页
字号:


/*
 * @implemented
 */
BOOL
STDCALL
DestroyIcon(
  HICON hIcon)
{
  return (BOOL)NtUserDestroyCursorIcon((HANDLE)hIcon, 0);
}


/*
 * @implemented
 */
BOOL
STDCALL
DrawIcon(
  HDC hDC,
  int X,
  int Y,
  HICON hIcon)
{
  return DrawIconEx(hDC, X, Y, hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_DEFAULTSIZE);
}

/*
 * @implemented
 */
BOOL
STDCALL
DrawIconEx(
  HDC hdc,
  int xLeft,
  int yTop,
  HICON hIcon,
  int cxWidth,
  int cyWidth,
  UINT istepIfAniCur,
  HBRUSH hbrFlickerFreeDraw,
  UINT diFlags)
{
  return (BOOL)NtUserDrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth,
                                   istepIfAniCur, hbrFlickerFreeDraw, diFlags,
                                   0, 0);
}


/*
 * @implemented
 */
BOOL
STDCALL
GetIconInfo(
  HICON hIcon,
  PICONINFO IconInfo)
{
  /* FIXME - copy bitmaps */
  return (BOOL)NtUserGetCursorIconInfo((HANDLE)hIcon, IconInfo);
}


/*
 * @implemented
 */
HICON
STDCALL
LoadIconA(
  HINSTANCE hInstance,
  LPCSTR lpIconName)
{
  return(LoadImageA(hInstance, lpIconName, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
}


/*
 * @implemented
 */
HICON
STDCALL
LoadIconW(
  HINSTANCE hInstance,
  LPCWSTR lpIconName)
{
  return(LoadImageW(hInstance, lpIconName, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
}


/*
 * @implemented
 */
int
STDCALL
LookupIconIdFromDirectory(
  PBYTE presbits,
  BOOL fIcon)
{
    return LookupIconIdFromDirectoryEx(presbits,
                                       fIcon,
                                       fIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
                                       fIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR),
                                       LR_DEFAULTCOLOR);
}





/*
 *  The following macro function accounts for the irregularities of
 *   accessing cursor and icon resources in files and resource entries.
 */
typedef BOOL
(*fnGetCIEntry)(LPVOID dir, int n, int *width, int *height, int *bits );

/**********************************************************************
 *	    CURSORICON_FindBestIcon
 *
 * Find the icon closest to the requested size and number of colors.
 */
static int
CURSORICON_FindBestIcon(LPVOID dir,
                        fnGetCIEntry get_entry,
                        int Width,
                        int Height,
                        int ColorBits)
{
    int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
    UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
    UINT iTempXDiff, iTempYDiff, iTempColorDiff;

    /* Find Best Fit */
    iTotalDiff = 0xFFFFFFFF;
    iColorDiff = 0xFFFFFFFF;
    for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
    {
        iTempXDiff = abs(Width - cx);
        iTempYDiff = abs(Height - cy);

        if(iTotalDiff > (iTempXDiff + iTempYDiff))
        {
            iXDiff = iTempXDiff;
            iYDiff = iTempYDiff;
            iTotalDiff = iXDiff + iYDiff;
        }
    }

    /* Find Best Colors for Best Fit */
    for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
    {
        if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
        {
            iTempColorDiff = abs(ColorBits - Bits);
            if(iColorDiff > iTempColorDiff)
            {
                BestEntry = i;
                BestBits = Bits;
                iColorDiff = iTempColorDiff;
            }
        }
    }

    DPRINT("Best Icon: ResId: %d, bits : %d\n", BestEntry, BestBits);

    return BestEntry;
}



/**********************************************************************
 *	    CURSORICON_FindBestCursor
 *
 * Find the cursor closest to the requested size.
 * FIXME: parameter 'color' ignored and entries with more than 1 bpp
 *        ignored too
 */
static int
CURSORICON_FindBestCursor(LPVOID dir,
                          fnGetCIEntry get_entry,
                          int Width,
                          int Height,
                          int ColorBits)
{
    int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
    UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
    UINT iTempXDiff, iTempYDiff, iTempColorDiff;

    /* Find Best Fit */
    iTotalDiff = 0xFFFFFFFF;
    iColorDiff = 0xFFFFFFFF;
    for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
    {
        iTempXDiff = abs(Width - cx);
        iTempYDiff = abs(Height - cy);

        if(iTotalDiff > (iTempXDiff + iTempYDiff))
        {
            iXDiff = iTempXDiff;
            iYDiff = iTempYDiff;
            iTotalDiff = iXDiff + iYDiff;
        }
    }

    /* Find Best Colors for Best Fit */
    for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
    {
        if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
        {
            iTempColorDiff = abs(ColorBits - Bits);
            if(iColorDiff > iTempColorDiff)
            {
                BestEntry = i;
                BestBits = Bits;
                iColorDiff = iTempColorDiff;
            }
        }
    }

    DPRINT("Best Cursor: ResId: %d, bits : %d\n", BestEntry, BestBits);

    return BestEntry;
}


static BOOL
CURSORICON_GetResIconEntry(LPVOID dir,
                           int n,
                           int *Width,
                           int *Height,
                           int *Bits)
{
    GRPCURSORICONDIR *ResDir = dir;
    ICONRESDIR *Icon;

    if (ResDir->idCount <= n)
        return FALSE;

    Icon = &ResDir->idEntries[n].ResInfo.icon;
    *Width = Icon->bWidth;
    *Height = Icon->bHeight;
    *Bits = ResDir->idEntries[n].wBitCount;
    return TRUE;
}

static BOOL
CURSORICON_GetResCursorEntry(LPVOID dir,
                             int n,
                             int *Width,
                             int *Height,
                             int *Bits)
{
    GRPCURSORICONDIR *ResDir = dir;
    CURSORRESDIR *Cursor;

    if (ResDir->idCount <= n)
        return FALSE;

    Cursor = &ResDir->idEntries[n].ResInfo.cursor;
    *Width = Cursor->wWidth;
    *Height = Cursor->wHeight;
    *Bits = ResDir->idEntries[n].wBitCount;
    return TRUE;
}

static GRPCURSORICONDIRENTRY *
CURSORICON_FindBestIconRes(GRPCURSORICONDIR * dir,
                           int Width,
                           int Height,
                           int ColorBits)
{
    int n;
    n = CURSORICON_FindBestIcon(dir,
                                CURSORICON_GetResIconEntry,
                                Width,
                                Height,
                                ColorBits);
    if (n < 0)
        return NULL;

    return &dir->idEntries[n];
}

static GRPCURSORICONDIRENTRY *
CURSORICON_FindBestCursorRes(GRPCURSORICONDIR *dir,
                             int Width,
                             int Height,
                             int ColorBits)
{
    int n;
    n = CURSORICON_FindBestCursor(dir,
                                  CURSORICON_GetResCursorEntry,
                                  Width,
                                  Height,
                                  ColorBits);
    if (n < 0)
        return NULL;

    return &dir->idEntries[n];
}


INT WINAPI
LookupIconIdFromDirectoryEx(PBYTE xdir,
                            BOOL bIcon,
                            INT width,
                            INT height,
                            UINT cFlag)
{
    GRPCURSORICONDIR *dir = (GRPCURSORICONDIR*)xdir;
    UINT retVal = 0;
    if(dir && !dir->idReserved && (IMAGE_ICON == dir->idType || IMAGE_CURSOR == dir->idType))
    {
        GRPCURSORICONDIRENTRY *entry = NULL;
        int ColorBits;

        if (cFlag & LR_MONOCHROME)
        {
            ColorBits = 1;
        }
        else
        {
            HDC hdc = CreateICW(NULL, NULL, NULL, NULL);
            ColorBits = GetDeviceCaps(hdc, BITSPIXEL);
            DeleteDC(hdc);
        }

        if(bIcon)
            entry = CURSORICON_FindBestIconRes(dir, width, height, ColorBits);
        else
            entry = CURSORICON_FindBestCursorRes(dir, width, height, 1);

        if (entry)
            retVal = entry->nID;
    }
    else
        DPRINT1("%s() : Invalid resource directory\n", __FUNCTION__);

    return retVal;
}

⌨️ 快捷键说明

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