通过窗口句柄获取窗口图标的几种办法

1.枚举窗口 ---->获得窗口句柄---->GetClassLong

 

2.枚举窗口(EnumWindows)---->获取窗口ID(GetWindowThreadProcessId)---->通过进程ID获取进程句柄(OpenProcess)---->进程对应的可执行文件路径(GetModuleFileNameEx)---->提取图标(ExtractIconEx)

 

 

 

3.HIMAGELIST hil;
   SHFILEINFO sfiTemp;

   ZeroMemory(&sfiTemp,sizeof(sfiTemp));

   hil = (HIMAGELIST)SHGetFileInfo(abc, FILE_ATTRIBUTE_DIRECTORY, &sfiTemp, sizeof(sfiTemp), SHGFI_SHELLICONSIZE | SHGFI_ICON | SHGFI_SMALLICON);

            tImageList.Add(sfiTemp.hIcon);

 

 

4.下面的第四种方法,该方法获得的图标比较好,但是也要和上述的方法一同配合使用。

 

if (!SendMessageTimeout(thIcon->next->hWnd, WM_GETICON, 0, 0,
    SMTO_BLOCK | SMTO_ABORTIFHUNG, ICON_FETCH_TIMEOUT, (PULONG_PTR) &m_hSmallIcon)
    || NULL == m_hSmallIcon)
   {
    m_hSmallIcon = (HICON)(LONG_PTR)GetClassLongPtr(thIcon->next->hWnd, GCLP_HICONSM);
   }
   if (!SendMessageTimeout(thIcon->next->hWnd, WM_GETICON, 1, 0,
    SMTO_BLOCK | SMTO_ABORTIFHUNG, ICON_FETCH_TIMEOUT, (PULONG_PTR) &m_hLargeIcon)
    || NULL == m_hLargeIcon)
   {
    m_hLargeIcon = (HICON)(LONG_PTR)GetClassLongPtr(thIcon->next->hWnd, GCLP_HICON);
   }

你可能感兴趣的:(File,null)