示例#1
0
HDC get_display_dc(void)
{
    static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};

    if(!display_dc) {
        HDC hdc;

        hdc = CreateICW(displayW, NULL, NULL, NULL);
        if(InterlockedCompareExchangePointer((void**)&display_dc, hdc, NULL))
            DeleteObject(hdc);
    }

    return display_dc;
}
示例#2
0
static PSETTINGS_ENTRY
GetPossibleSettings(IN LPCWSTR lpDeviceName,
                    OUT DWORD* pSettingsCount,
                    OUT PSETTINGS_ENTRY* CurrentSettings)
{
    DEVMODEW devmode;
    DWORD NbSettings = 0;
    DWORD iMode = 0;
    DWORD dwFlags = 0;
    PSETTINGS_ENTRY Settings = NULL;
    HDC hDC;
    PSETTINGS_ENTRY Current;
    DWORD bpp, xres, yres, checkbpp;

    /* Get current settings */
    *CurrentSettings = NULL;
    hDC = CreateICW(NULL, lpDeviceName, NULL, NULL);
    bpp = GetDeviceCaps(hDC, PLANES);
    bpp *= GetDeviceCaps(hDC, BITSPIXEL);
    xres = GetDeviceCaps(hDC, HORZRES);
    yres = GetDeviceCaps(hDC, VERTRES);
    DeleteDC(hDC);

    /* List all settings */
    devmode.dmSize = (WORD)sizeof(DEVMODE);
    devmode.dmDriverExtra = 0;

    if (!EnumDisplaySettingsExW(lpDeviceName, ENUM_CURRENT_SETTINGS, &devmode, dwFlags))
        return NULL;

    while (EnumDisplaySettingsExW(lpDeviceName, iMode, &devmode, dwFlags))
    {
        if (devmode.dmBitsPerPel==8 ||
            devmode.dmBitsPerPel==16 ||
            devmode.dmBitsPerPel==24 ||
            devmode.dmBitsPerPel==32)
        {
            checkbpp=1;
        }
        else
            checkbpp=0;

        if (devmode.dmPelsWidth < 640 ||
            devmode.dmPelsHeight < 480 || checkbpp == 0)
        {
            iMode++;
            continue;
        }

        Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY));
        if (Current != NULL)
        {
            /* Sort resolutions by increasing height, and BPP */
            PSETTINGS_ENTRY Previous = NULL;
            PSETTINGS_ENTRY Next = Settings;
            Current->dmPelsWidth = devmode.dmPelsWidth;
            Current->dmPelsHeight = devmode.dmPelsHeight;
            Current->dmBitsPerPel = devmode.dmBitsPerPel;
            while (Next != NULL &&
                   (Next->dmPelsWidth < Current->dmPelsWidth ||
                    (Next->dmPelsWidth == Current->dmPelsWidth && Next->dmPelsHeight < Current->dmPelsHeight) ||
                    (Next->dmPelsHeight == Current->dmPelsHeight &&
                     Next->dmPelsWidth == Current->dmPelsWidth &&
                     Next->dmBitsPerPel < Current->dmBitsPerPel )))
            {
                Previous = Next;
                Next = Next->Flink;
            }
            Current->Blink = Previous;
            Current->Flink = Next;
            if (Previous == NULL)
                Settings = Current;
            else
                Previous->Flink = Current;
            if (Next != NULL)
                Next->Blink = Current;
            if (devmode.dmPelsWidth == xres && devmode.dmPelsHeight == yres && devmode.dmBitsPerPel == bpp)
            {
                *CurrentSettings = Current;
            }
            NbSettings++;
        }
        iMode++;
    }

    *pSettingsCount = NbSettings;
    return Settings;
}
示例#3
0
/*****************************************************************************
 * SIC_Initialize            [internal]
 */
BOOL SIC_Initialize(void)
{
    HICON hSm = NULL, hLg = NULL;
    INT cx_small, cy_small;
    INT cx_large, cy_large;
    HDC hDC;
    INT bpp;
    DWORD ilMask;
    BOOL result = FALSE;

    TRACE("Entered SIC_Initialize\n");

    if (sic_hdpa)
    {
        TRACE("Icon cache already initialized\n");
        return TRUE;
    }

    sic_hdpa = DPA_Create(16);
    if (!sic_hdpa)
    {
        return FALSE;
    }

    hDC = CreateICW(L"DISPLAY", NULL, NULL, NULL);
    if (!hDC)
    {
        ERR("Failed to create information context (error %d)\n", GetLastError());
        goto end;
    }

    bpp = GetDeviceCaps(hDC, BITSPIXEL);
    DeleteDC(hDC);

    if (bpp <= 4)
        ilMask = ILC_COLOR4;
    else if (bpp <= 8)
        ilMask = ILC_COLOR8;
    else if (bpp <= 16)
        ilMask = ILC_COLOR16;
    else if (bpp <= 24)
        ilMask = ILC_COLOR24;
    else if (bpp <= 32)
        ilMask = ILC_COLOR32;
    else
        ilMask = ILC_COLOR;

    ilMask |= ILC_MASK;

    cx_small = GetSystemMetrics(SM_CXSMICON);
    cy_small = GetSystemMetrics(SM_CYSMICON);
    cx_large = GetSystemMetrics(SM_CXICON);
    cy_large = GetSystemMetrics(SM_CYICON);

    ShellSmallIconList = ImageList_Create(cx_small,
                                          cy_small,
                                          ilMask,
                                          100,
                                          100);
    if (!ShellSmallIconList)
    {
        ERR("Failed to create the small icon list.\n");
        goto end;
    }

    ShellBigIconList = ImageList_Create(cx_large,
                                        cy_large,
                                        ilMask,
                                        100,
                                        100);
    if (!ShellBigIconList)
    {
        ERR("Failed to create the big icon list.\n");
        goto end;
    }
    
    /* Load the document icon, which is used as the default if an icon isn't found. */
    hSm = (HICON)LoadImageW(shell32_hInstance,
                            MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT),
                            IMAGE_ICON,
                            cx_small,
                            cy_small,
                            LR_SHARED | LR_DEFAULTCOLOR);
    if (!hSm)
    {
        ERR("Failed to load small IDI_SHELL_DOCUMENT icon!\n");
        goto end;
    }

    hLg = (HICON)LoadImageW(shell32_hInstance,
                            MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT),
                            IMAGE_ICON,
                            cx_large,
                            cy_large,
                            LR_SHARED | LR_DEFAULTCOLOR);
    if (!hLg)
    {
        ERR("Failed to load large IDI_SHELL_DOCUMENT icon!\n");
        goto end;
    }

    if(SIC_IconAppend(swShell32Name, IDI_SHELL_DOCUMENT-1, hSm, hLg, 0) == INVALID_INDEX)
    {
        ERR("Failed to add IDI_SHELL_DOCUMENT icon to cache.\n");
        goto end;
    }
    if(SIC_IconAppend(swShell32Name, -IDI_SHELL_DOCUMENT, hSm, hLg, 0) == INVALID_INDEX)
    {
        ERR("Failed to add IDI_SHELL_DOCUMENT icon to cache.\n");
        goto end;
    }
    
    /* Everything went fine */
    result = TRUE;
    
end:
    /* The image list keeps a copy of the icons, we must destroy them */
    if(hSm) DestroyIcon(hSm);
    if(hLg) DestroyIcon(hLg);
    
    /* Clean everything if something went wrong */
    if(!result)
    {
        if(sic_hdpa) DPA_Destroy(sic_hdpa);
        if(ShellSmallIconList) ImageList_Destroy(ShellSmallIconList);
        if(ShellBigIconList) ImageList_Destroy(ShellSmallIconList);
        sic_hdpa = NULL;
        ShellSmallIconList = NULL;
        ShellBigIconList = NULL;
    }

    TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList);

    return result;
}
示例#4
0
INT
Test_NtGdiSaveDC(PTESTINFO pti)
{
    HDC hdc, hdc2;
    HWND hwnd;
    HBITMAP hbmp1, hbmp2, hOldBmp;

    /* Test 0 hdc */
    TEST(NtGdiSaveDC(0) == 0);

    /* Test info dc */
    hdc = CreateICW(L"DISPLAY",NULL,NULL,NULL);
    TEST(hdc);
    TEST(NtGdiSaveDC(hdc) == 1);
    TEST(NtGdiSaveDC(hdc) == 2);
    DeleteDC(hdc);

    /* Test display dc */
    hdc = GetDC(0);
    TEST(hdc);
    TEST(NtGdiSaveDC(hdc) == 1);
    TEST(NtGdiSaveDC(hdc) == 2);
    ReleaseDC(0, hdc);

    /* Test a mem DC */
    hdc = CreateCompatibleDC(0);
    TEST(hdc);
    TEST(NtGdiSaveDC(hdc) == 1);
    TEST(NtGdiSaveDC(hdc) == 2);
    DeleteDC(hdc);

    /* Create a window */
    hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                         10, 10, 100, 100,
                         NULL, NULL, g_hInstance, 0);
    hdc = GetDC(hwnd);
    TEST(hdc);
    TEST(NtGdiSaveDC(hdc) == 1);
    NtGdiRestoreDC(hdc, 1);
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);

    /* test behaviour when a bitmap is selected */
    hbmp1 = CreateBitmap(2, 2, 1, 1, NULL);
    TEST(hbmp1);
    hbmp2 = CreateBitmap(2, 2, 1, 1, NULL);
    TEST(hbmp2);
    hdc = CreateCompatibleDC(0);
    TEST(hdc);
    hdc2 = CreateCompatibleDC(0);
    TEST(hdc2);
    hOldBmp = SelectObject(hdc, hbmp1);
    TEST(hOldBmp);
    TEST(NtGdiSaveDC(hdc) == 1);
    TEST(SelectObject(hdc, hbmp2) == hbmp1);
    TEST(SelectObject(hdc2, hbmp1) == NULL);
    SelectObject(hdc, hOldBmp);
    NtGdiRestoreDC(hdc, 1);
    TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
    /* Again, just to be sure */
    TEST(NtGdiSaveDC(hdc) == 1);
    TEST(NtGdiSaveDC(hdc) == 2);
    TEST(SelectObject(hdc, hbmp2) == hbmp1);
    TEST(SelectObject(hdc2, hbmp1) == NULL);
    SelectObject(hdc, hOldBmp);
    NtGdiRestoreDC(hdc, 2);
    TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
    /*Cleanup */
    SelectObject(hdc, hOldBmp);
    DeleteDC(hdc);
    DeleteDC(hdc2);
    DeleteObject(hbmp1);
    DeleteObject(hbmp2);

    return APISTATUS_NORMAL;
}