Author Topic: Extracting Icons  (Read 1825 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Extracting Icons
« on: May 30, 2018, 01:13:19 AM »
Hello,

this is a small app which displays the icons of a dll or exe file in a ListView. It uses the Winapi function ExtractIcon. Line 56 starts an array with dll files, line 64 starts an array with exe files. The arrays can be modified. To see the icons in the original size, line 197 can be used instead of line 198.

It is only a test code, but it could be extended in several ways.

Roland

Code: OxygenBasic
  1. $ filename "Windows_Icons.exe"
  2.  
  3. 'uses rtl32
  4. 'uses rtl64
  5.  
  6. uses WinUtil
  7.  
  8. % SM_CXICON=11
  9. % SM_CYICON=12
  10. % LVS_ICON=0
  11. % LVIF_TEXT=1
  12. % LVIF_IMAGE=2
  13. % LVSIL_NORMAL=0
  14. % LVM_SETIMAGELIST=4099
  15. % LVM_INSERTITEM=4103
  16. % LVM_DELETEALLITEMS=4105
  17. % LVM_ARRANGE=4118
  18. % ILC_COLOR32=32
  19. % ILC_MASK=1
  20. % LVA_ALIGNTOP=2
  21.  
  22. type LVITEM  
  23.   uint   mask
  24.   int    iItem
  25.   int    iSubItem
  26.   uint   state
  27.   uint   stateMask
  28.   char*  pszText
  29.   int    cchTextMax
  30.   int    iImage       ' index of the list view item's icon
  31.  sys    lParam       ' 32-bit value to associate with item
  32.  int    iIndent
  33.   int    iGroupId
  34.   uint   cColumns
  35.   uint   *puColumns
  36.   int    *piColFmt
  37.   int    iGroup
  38. end type
  39. typedef LVITEM LV_ITEM
  40.  
  41.  
  42. ' create a structure of INITCOMMONCONTROLSEX
  43. INITCOMMONCONTROLSEXt iccex
  44. iccex.dwSize=sizeof(iccex)
  45. 'Register Common Controls
  46. iccex.dwICC= 0xffff
  47.  
  48. 'Menu Ids
  49. % IDM_EXIT=1000  
  50. % ID_DLLs=2000
  51. % ID_EXEs=3000  
  52.  
  53. sys hListView=0
  54.  
  55. string DllFiles[]={
  56. "Shell32.dll", "MorIcons.dll", "ImageRes.dll", "IeFrame.dll", "Netshell.dll",
  57. "GameUx.dll", "User32.dll", "Cryptui.dll", "AccessibilityCpl.dll", "mmcndmgr.dll",
  58. "mmres.dll", "netCenter.dll", "networkexplorer.dll", "pifmgr.dll", "pniDui.dll",
  59. "remotepg.dll", "sdcpl.dll", "setupAPI.dll", "SensorsCpl.dll", "shellbrd.dll",
  60. "Actioncenter.dll", "DDORes.dll"
  61. }
  62.  
  63. string ExeFiles[]={
  64. "Explorer.exe", "Control.exe", "Mobsync.exe", "WinLogon.exe"
  65. }
  66.  
  67.  
  68.  
  69. declare function initMenu(sys hWnd) as sys
  70. declare sub DisplayIcons(sys hListView, string ResFile)
  71.  
  72. sys hInstance=inst
  73. MainWindow 580,460,WS_OVERLAPPEDWINDOW
  74.  
  75.  
  76. function WndProc(sys hwnd, uMsg, wParam, lParam) as sys callback
  77.  
  78.    select uMsg
  79.    
  80.        case WM_CREATE
  81.           SetWindowText(hwnd, "View Windows System Icons")
  82.           sys hMenu = InitMenu(hWnd)
  83.           if SetMenu( hWnd, hMenu ) = 0 then mbox "SetMenu hMenu failed!"
  84.  
  85.           'create a list view control
  86.          hListView=CreateWindowEx(WS_EX_CLIENTEDGE,               'extended styles
  87.                                      "SysListView32",             'class
  88.                                       null,                       'title
  89.                                       WS_CHILD + WS_VISIBLE + LVS_ICON,  'window style
  90.                                       0,0,0,0,                    'left, top, width, height
  91.                                       hwnd,                       'parent window handle
  92.                                       null,                       'handle to menu
  93.                                       hInstance,                  'application instance
  94.                                       null)                       'user defined data
  95.          if hListView=0 then mbox "Could not create ListView"
  96.          
  97.        case WM_COMMAND
  98.           sys id=loword(wParam)
  99.           'sys event=hiword(wParam)
  100.  
  101.           int dlo=ID_DLLs+1
  102.           int dhi=ID_DLLs+countof(DllFiles)
  103.           int elo=ID_EXEs+1
  104.           int ehi=ID_EXEs+countof(ExeFiles)
  105.  
  106.           select id
  107.          
  108.           case IDM_EXIT
  109.              Sendmessage(hwnd, WM_CLOSE, 0,0)
  110.          
  111.           case dlo to dhi
  112.              sys idx=id-ID_DLLs
  113.              DisplayIcons(hListView, DllFiles[idx])          
  114.           case elo to ehi          
  115.              sys idx=id-ID_EXEs
  116.              DisplayIcons(hListView, ExeFiles[idx])          
  117.  
  118.           end select
  119.          
  120.        case WM_SIZE
  121.           'resize list view to fill client area of parent
  122.          MoveWindow( hListView,0,0,loword(lParam),hiword(lParam), true )
  123.           'arrange items
  124.          SendMessage( hListView,LVM_ARRANGE,LVA_ALIGNTOP,0 )
  125.                
  126.        case WM_CLOSE
  127.           DestroyWindow(hwnd)
  128.        
  129.        case WM_DESTROY
  130.           PostQuitMessage(0)
  131.        
  132.        case else
  133.           return DefWindowProc(hwnd, uMsg, wParam, lParam)
  134.            
  135.     end select
  136.    
  137.     return 0
  138. end function
  139.  
  140. ==========================================================
  141.  
  142. function initMenu(sys hWnd) as sys
  143.    sys hMenu, hMenupopup
  144.    int x, id
  145.  
  146.    hMenu = CreateMenu
  147.    hMenuPopup = CreateMenu
  148.    AppendMenu hMenu,      MF_POPUP,     hMenuPopup, "&File"
  149.    AppendMenu hMenuPopup, MF_STRING,    IDM_EXIT,   "E&xit"
  150.  
  151.    hMenuPopup = CreateMenu
  152.    AppendMenu hMenu,      MF_POPUP,     hMenuPopup, "&DLL Files"
  153.    id=0
  154.    for x=1 to countof(DllFiles)
  155.       id++      
  156.       AppendMenu hMenuPopup, MF_STRING, id+ID_DLLs, DllFiles[id]
  157.    next x
  158.  
  159.    hMenuPopup = CreateMenu
  160.    AppendMenu hMenu,      MF_POPUP,     hMenuPopup, "&Exe Files"
  161.    id=0
  162.    for x=1 to countof(ExeFiles)
  163.       id++      
  164.       AppendMenu hMenuPopup, MF_STRING, id+ID_EXEs, ExeFiles[id]
  165.    next x
  166.    
  167.    return hMenu
  168. end function
  169.  
  170.  
  171. sub DisplayIcons(sys hListView, string ResFile)
  172.    indexbase 0
  173.    int numIcons
  174.    
  175.    numIcons = ExtractIcon( null, ResFile, -1 )
  176.      
  177.    if numIcons=null then
  178.       mbox "No Icons in " ResFile " or " ResFile " does not exist"
  179.       exit sub
  180.    end if
  181.      
  182.    redim int resource_icons(0)
  183.    redim int resource_icons(numIcons)
  184.  
  185.    int iIcon
  186.    for iIcon =  0 to <numIcons
  187.       resource_icons[iIcon] = ExtractIcon(null, ResFile, iIcon)
  188.    next iIcon
  189.  
  190.    static sys hIcons
  191.    if hIcons then
  192.       SendMessage(hListView, LVM_DELETEALLITEMS, 0,0)
  193.       ImageList_Destroy(hIcons)
  194.    end if
  195.    
  196.    'create the new image lists
  197.   'hIcons=ImageList_Create( GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ), ILC_COLOR32 | ILC_MASK,1,1 )
  198.   hIcons=ImageList_Create( 48, 48, ILC_COLOR32 | ILC_MASK,1,1 )
  199.  
  200.    'add icons to imagelists.
  201.   LV_ITEM lvi
  202.    int i
  203.    for i = 0 to <numIcons
  204.       ImageList_AddIcon( hIcons,resource_icons[i] )
  205.       DestroyIcon( resource_icons[i] )
  206.    next i
  207.        
  208.    'attach image lists to list view common control
  209.   SendMessage( hListView, LVM_SETIMAGELIST, LVSIL_NORMAL, hIcons )
  210.        
  211.    'add the items to the the list view common control
  212.   lvi.mask = LVIF_TEXT | LVIF_IMAGE
  213.    for i=0 to <numIcons
  214.       'the zero-based item index
  215.      lvi.iItem=i
  216.       'convert item index to string (+1)
  217.      string pText=str(i+1)
  218.       lvi.pszText = pText
  219.       lvi.cchTextMax = len(pText)
  220.       lvi.iImage = i
  221.       SendMessage( hListView,LVM_INSERTITEM,0, &lvi )
  222.     next i
  223.     SetWindowText(GetParent(hListView), ResFile)        
  224. end sub
  225.  

Charles Pegge

  • Guest
Re: Extracting Icons
« Reply #1 on: May 30, 2018, 05:22:17 AM »
Thank you, Roland.

I would like to include this in examples\WinGui :)

Arnold

  • Guest
Re: Extracting Icons
« Reply #2 on: May 30, 2018, 06:59:58 AM »
Hi Charles,

you can use anything from me if it should be worth it.

At the moment I am trying to do some code which would need Laurent's O2debugger to examine it. But until now it seems that for this kind of program it will be sufficient to use print statements. This does not mean that the debugger would be unnecessary. I just have to find the right problem.

Roland

Charles Pegge

  • Guest
Re: Extracting Icons
« Reply #3 on: May 30, 2018, 08:47:12 AM »
I have a new feature which might be useful to you.

#insert

This is intended for simple Aspect-Oriented-Programming, and run-time debugging. It directs the compiler to insert code at the start of each subsequent procedure, until the next #insert is encountered, which may be new code to insert, or no code.

#insert myTracer

where myTracer is a procedure (or macro) taking the literal name of each function as its single argument.

Invoke #insert only where you need it, and beware indirect #insert recursions!

2 Examples:

Code: [Select]
'TRACER UTILITY SUB
'
uses console
sub tracer(string s)
  color 0x0e
  output s cr
  color 0x07
end sub

#Insert tracer
function ff(){
printl "native"}
function gg(){ff}
#insert 'ending #insert
gg
printl "ok"
wait

Code: [Select]
'2018-05-28T04:09:43
'TRACER UTILITY MACRO
'
uses console
macro tracer(pn)
  color 0x0e
  #ifdef i
    output pn tab i cr
  #else
    output pn cr
  #endif
  color 0x07
end macro

#Insert tracer
function ff(int i=1){
printl "native"
}
'#insert 'ending #insert
function gg(int i=2){ff(0x65)}
gg()
printl "ok"
wait
« Last Edit: May 30, 2018, 09:05:15 AM by Charles Pegge »

JRS

  • Guest
Re: Extracting Icons
« Reply #4 on: May 30, 2018, 09:34:18 AM »
Nice Charles!

Looking forward to giving it a try.


Charles Pegge

  • Guest
Re: Extracting Icons
« Reply #5 on: May 30, 2018, 10:33:50 AM »
My PC received a Windows10 update last week, which caused a mysterious breakage in OxIde project handling, so I will be putting the #insert instruction to good use.