Esempio n. 1
0
/* WM_TASKTRAY_CH */
static
LRESULT main_tasktray_ch(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    int ret;
    HICON icon;

    if(ctx.app_conf.tray_icon_hide) {
        set_tasktray_icon(hwnd, NIM_DELETE);
        return 0;
    }

    if(ctx.app_conf.tray_icon_file != NULL) {
        if(ExtractIconExW(ctx.app_conf.tray_icon_file,
                          ctx.app_conf.tray_icon_idx,
                          NULL, &icon, 1) != 1) {
            error_message(L"ExtractIconEx() failed");
            return 0;
        }
    } else {
        icon = NULL;
    }

    DestroyIcon(ctx.tray_icon);
    ctx.tray_icon = icon;

    ret = set_tasktray_icon(hwnd, NIM_MODIFY);
    if(ret == 0) {
        error_message_le("set_tasktray_icon() failed");
    }

    return 0;
}
Esempio n. 2
0
    SEA_EXPORT bool ExportExeIconAsGif(LPCWSTR szExePath, LPCWSTR szGifPath)
    {
        UINT count = ExtractIconExW(szExePath, -1, nullptr, nullptr, 0);
        for (UINT i = 0; i < count; ++i)
        {
            HICON hIcon = nullptr;
            ExtractIconExW(szExePath, i, nullptr, &hIcon, 1);

            Gdiplus::GpBitmap* pBitmap = IconToBitmap(hIcon);
            if (!pBitmap)
                return false;
            bool res = ConvertToGif(pBitmap, szGifPath);
            GdiPlusFn::Get<FGdipDisposeImage>("GdipDisposeImage")(pBitmap);
            return res;
        }
        return false;
    }
Esempio n. 3
0
static HICON extract_icon( IShellLinkW *link )
{
    WCHAR tmp_path[MAX_PATH], icon_path[MAX_PATH], target_path[MAX_PATH];
    HICON icon = NULL;
    int index;

    tmp_path[0] = 0;
    IShellLinkW_GetIconLocation( link, tmp_path, MAX_PATH, &index );
    ExpandEnvironmentStringsW( tmp_path, icon_path, MAX_PATH );

    if (icon_path[0]) ExtractIconExW( icon_path, index, &icon, NULL, 1 );
    if (!icon)
    {
        tmp_path[0] = 0;
        IShellLinkW_GetPath( link, tmp_path, MAX_PATH, NULL, SLGP_RAWPATH );
        ExpandEnvironmentStringsW( tmp_path, target_path, MAX_PATH );
        ExtractIconExW( target_path, index, &icon, NULL, 1 );
    }
    return icon;
}
Esempio n. 4
0
/*************************************************************************
 * ExtractIconExA			[SHELL32.@]
 */
UINT WINAPI ExtractIconExA(LPCSTR lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons)
{
    UINT ret = 0;
    INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
    LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));

    TRACE("%s %i %p %p %i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);

    if (lpwstrFile)
    {
        MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
        ret = ExtractIconExW(lpwstrFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
        HeapFree(GetProcessHeap(), 0, lpwstrFile);
    }
    return ret;
}
Esempio n. 5
0
static INT
ViewTree_AddIcon(LPCWSTR pszPath, UINT nIconIndex)
{
    PVIEWTREE_ICON pAllocated;

    // return the ID if already existed
    INT nIconID = ViewTree_FindIcon(pszPath, nIconIndex);
    if (nIconID != -1)
        return nIconID;     // already exists

    // extract a small icon
    HICON hIconSmall = NULL;
    ExtractIconExW(pszPath, nIconIndex, NULL, &hIconSmall, 1);
    if (hIconSmall == NULL)
        return -1;      // failure

    // resize s_ViewTreeIcons
    size_t Size = (s_ViewTreeIconCount + 1) * sizeof(VIEWTREE_ICON);
    pAllocated = (PVIEWTREE_ICON)realloc(s_ViewTreeIcons, Size);
    if (pAllocated == NULL)
        return -1;      // failure
    else
        s_ViewTreeIcons = pAllocated;

    // save icon information
    PVIEWTREE_ICON pIcon = &s_ViewTreeIcons[s_ViewTreeIconCount];
    lstrcpynW(pIcon->szPath, pszPath, _countof(pIcon->szPath));
    pIcon->nIconIndex = nIconIndex;

    // add the icon to the image list
    ImageList_AddIcon(s_hTreeImageList, hIconSmall);

    // increment the counter
    nIconID = s_ViewTreeIconCount;
    ++s_ViewTreeIconCount;

    DestroyIcon(hIconSmall);

    return nIconID;     // newly-added icon ID
}
Esempio n. 6
0
bool SDL2Window::initialize() {

    arx_assert(!m_displayModes.empty());

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

#if ARX_PLATFORM == ARX_PLATFORM_WIN32
    // Used on Windows to prevent software opengl fallback.
    // The linux situation:
    // Causes SDL to require visuals without caveats.
    // On linux some drivers only supply multisample capable GLX Visuals
    // with a GLX_NON_CONFORMANT_VISUAL_EXT caveat.
    // see: https://www.opengl.org/registry/specs/EXT/visual_rating.txt
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#endif

    // TODO EGL and core profile are not supported yet
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);

    if(gldebug::isEnabled()) {
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
    }


    int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
    Uint32 windowFlags = getSDLFlagsForMode(m_size, m_fullscreen);
    windowFlags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;

    for(int msaa = m_maxMSAALevel; msaa > 0; msaa--) {
        bool lastTry = (msaa == 1);

        // Cleanup context and window from previous tries
        if(m_glcontext) {
            SDL_GL_DeleteContext(m_glcontext);
            m_glcontext = NULL;
        }
        if(m_window) {
            SDL_DestroyWindow(m_window);
            m_window = NULL;
        }

        SDL_ClearError();

        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa > 1 ? 1 : 0);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa > 1 ? msaa : 0);

        m_window = SDL_CreateWindow(m_title.c_str(), x, y, m_size.x, m_size.y, windowFlags);
        if(!m_window) {
            if(lastTry) {
                LogError << "Could not create window: " << SDL_GetError();
                return false;
            }
            continue;
        }

        m_glcontext = SDL_GL_CreateContext(m_window);
        if(!m_glcontext) {
            if(lastTry) {
                LogError << "Could not create GL context: " << SDL_GetError();
                return false;
            }
            continue;
        }

        // Verify that the MSAA setting matches what was requested
        int msaaEnabled, msaaValue;
        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msaaEnabled);
        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaaValue);
        if(!lastTry) {
            if(!msaaEnabled || msaaValue < msaa) {
                continue;
            }
        }
        if(msaaEnabled) {
            m_MSAALevel = msaaValue;
        } else {
            m_MSAALevel = 0;
        }

        // Verify that we actually got an accelerated context
        (void)glGetError(); // clear error flags
        GLint texunits = 0;
        glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits);
        if(glGetError() != GL_NO_ERROR || texunits < GLint(m_minTextureUnits)) {
            if(lastTry) {
                LogError << "Not enough GL texture units available: have " << texunits
                         << ", need at least " << m_minTextureUnits;
                return false;
            }
            continue;
        }

        // All good
        const char * system = "(unknown)";
        {
            ARX_SDL_SysWMinfo info;
            info.version.major = 2;
            info.version.minor = 0;
            info.version.patch = 4;
            if(SDL_GetWindowWMInfo(m_window, reinterpret_cast<SDL_SysWMinfo *>(&info))) {
                switch(info.subsystem) {
                case ARX_SDL_SYSWM_UNKNOWN:
                    break;
                case ARX_SDL_SYSWM_WINDOWS:
                    system = "Windows";
                    break;
                case ARX_SDL_SYSWM_X11:
                    system = "X11";
                    break;
#if SDL_VERSION_ATLEAST(2, 0, 3)
                case ARX_SDL_SYSWM_WINRT:
                    system = "WinRT";
                    break;
#endif
                case ARX_SDL_SYSWM_DIRECTFB:
                    system = "DirectFB";
                    break;
                case ARX_SDL_SYSWM_COCOA:
                    system = "Cocoa";
                    break;
                case ARX_SDL_SYSWM_UIKIT:
                    system = "UIKit";
                    break;
#if SDL_VERSION_ATLEAST(2, 0, 2)
                case ARX_SDL_SYSWM_WAYLAND:
                    system = "Wayland";
                    break;
                case ARX_SDL_SYSWM_MIR:
                    system = "Mir";
                    break;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 4)
                case ARX_SDL_SYSWM_ANDROID:
                    system = "Android";
                    break;
#endif
                }
            }
        }

        int red = 0, green = 0, blue = 0, alpha = 0, depth = 0, doublebuffer = 0;
        SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red);
        SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green);
        SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blue);
        SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha);
        SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
        SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer);
        LogInfo << "Window: " << system << " r:" << red << " g:" << green << " b:" << blue
                << " a:" << alpha << " depth:" << depth << " aa:" << msaa << "x"
                << " doublebuffer:" << doublebuffer;
        break;
    }

    // Use the executable icon for the window
#if ARX_PLATFORM == ARX_PLATFORM_WIN32
    {
        SDL_SysWMinfo info;
        SDL_VERSION(&info.version);
        if(SDL_GetWindowWMInfo(m_window, &info) && info.subsystem == SDL_SYSWM_WINDOWS) {
            platform::WideString filename;
            filename.allocate(filename.capacity());
            while(true) {
                DWORD size = GetModuleFileNameW(NULL, filename.data(), filename.size());
                if(size < filename.size()) {
                    filename.resize(size);
                    break;
                }
                filename.allocate(filename.size() * 2);
            }
            HICON largeIcon = 0;
            HICON smallIcon = 0;
            ExtractIconExW(filename, 0, &largeIcon, &smallIcon, 1);
            if(smallIcon) {
                SendMessage(info.info.win.window, WM_SETICON, ICON_SMALL, LPARAM(smallIcon));
            }
            if(largeIcon) {
                SendMessage(info.info.win.window, WM_SETICON, ICON_BIG, LPARAM(largeIcon));
            }
        }
    }
#endif

    setVSync(m_vsync);

    SDL_ShowWindow(m_window);
    SDL_ShowCursor(SDL_DISABLE);

    m_renderer->initialize();

    onCreate();
    onToggleFullscreen(m_fullscreen);
    updateSize(true);

    onShow(true);
    onFocus(true);

    return true;
}
Esempio n. 7
0
/*************************************************************************
 * ExtractIconEx			[SHELL32.@]
 */
HICON WINAPI ExtractIconExAW ( LPCVOID lpszFile, INT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIcons )
{	if (SHELL_OsIsUnicode())
	  return ExtractIconExW ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
	return ExtractIconExA ( lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
}
Esempio n. 8
0
VOID
CFileDefExt::InitOpensWithField(HWND hwndDlg)
{
    WCHAR wszBuf[MAX_PATH] = L"";
    WCHAR wszPath[MAX_PATH] = L"";
    DWORD dwSize = sizeof(wszBuf);
    BOOL bUnknownApp = TRUE;
    LPCWSTR pwszExt = PathFindExtensionW(m_wszPath);

    if (RegGetValueW(HKEY_CLASSES_ROOT, pwszExt, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS)
    {
        bUnknownApp = FALSE;
        StringCbCatW(wszBuf, sizeof(wszBuf), L"\\shell\\open\\command");
        dwSize = sizeof(wszPath);
        if (RegGetValueW(HKEY_CLASSES_ROOT, wszBuf, L"", RRF_RT_REG_SZ, NULL, wszPath, &dwSize) == ERROR_SUCCESS)
        {
            /* Get path from command line */
            ExpandEnvironmentStringsW(wszPath, wszBuf, _countof(wszBuf));
            PathRemoveArgs(wszBuf);
            PathUnquoteSpacesW(wszBuf);
            PathSearchAndQualify(wszBuf, wszPath, _countof(wszPath));

            HICON hIcon;
            if (ExtractIconExW(wszPath, 0, NULL, &hIcon, 1))
            {
                HWND hIconCtrl = GetDlgItem(hwndDlg, 14025);
                HWND hDescrCtrl = GetDlgItem(hwndDlg, 14007);
                ShowWindow(hIconCtrl, SW_SHOW);
                RECT rcIcon, rcDescr;
                GetWindowRect(hIconCtrl, &rcIcon);
                if (rcIcon.left == rcIcon.right)
                    ERR("Icon control has invalid width: %d-%d\n", rcIcon.left, rcIcon.right);
                MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rcIcon, 2);
                GetWindowRect(hDescrCtrl, &rcDescr);
                MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rcDescr, 2);
                INT cxOffset = rcIcon.right + 2 - rcDescr.left;
                SetWindowPos(hDescrCtrl, NULL,
                             rcDescr.left + cxOffset, rcDescr.top,
                             rcDescr.right - rcDescr.left - cxOffset, rcDescr.bottom - rcDescr.top,
                             SWP_NOZORDER);
                SendMessageW(hIconCtrl, STM_SETICON, (WPARAM)hIcon, 0);
            } else
                ERR("Failed to extract icon\n");

            if (PathFileExistsW(wszPath))
            {
                /* Get file description */
                CFileVersionInfo VerInfo;
                VerInfo.Load(wszPath);
                LPCWSTR pwszDescr = VerInfo.GetString(L"FileDescription");
                if (pwszDescr)
                    SetDlgItemTextW(hwndDlg, 14007, pwszDescr);
                else
                {
                    /* File has no description - display filename */
                    LPWSTR pwszFilename = PathFindFileNameW(wszPath);
                    PathRemoveExtension(pwszFilename);
                    pwszFilename[0] = towupper(pwszFilename[0]);
                    SetDlgItemTextW(hwndDlg, 14007, pwszFilename);
                }
            }
            else
                bUnknownApp = TRUE;
        } else
            WARN("RegGetValueW %ls failed\n", wszBuf);
    } else
        WARN("RegGetValueW %ls failed\n", pwszExt);

    if (bUnknownApp)
    {
        /* Unknown application */
        LoadStringW(shell32_hInstance, IDS_UNKNOWN_APP, wszBuf, _countof(wszBuf));
        SetDlgItemTextW(hwndDlg, 14007, wszBuf);
    }
}