<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JScript: Извлечение иконок из файлов ресурсов]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=580&amp;type=atom" />
	<updated>2007-08-03T17:58:22Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=580</id>
		<entry>
			<title type="html"><![CDATA[JScript: Извлечение иконок из файлов ресурсов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=3838#p3838" />
			<content type="html"><![CDATA[<p>Автор примера - <strong>Poltergeyst</strong>.<br />Используются библиотеки <a href="http://www.script-coding.com/dynwrap.html">dynwrap.dll</a> и <a href="http://www.script-coding.com/AutiItX.html">AutoItX3.dll</a>.<br /></p><div class="codebox"><pre><code>//Никаких гарантий!Используете на свой страх и риск!
//--------------------------------------------------------------------------------------------
//Данный скрипт предназначен для извлечений иконок из 
//файлов ресурсов с последующим отображением этих иконок
//в действительном контексте экрана.В данном примере
//в качестве контейнера ресурсов используется shell32.dll
//--------------------------------------------------------------------------------------------
//Примечание:Интересная возможность-в случае пустого
//параметра filename будут загружены стандартные иконки.
//--------------------------------------------------------------------------------------------
//Lang.:JScript
//Используется библиотека dynwrap.dll
//Используется вспомогательная библиотека AutoItX3.dll,v3.2.0.1
//--------------------------------------------------------------------------------------------

    IMAGE_ICON    =1
    DI_MASK         =1
    DI_IMAGE    =2
    DI_NORMAL       =3
    DI_COMPAT       =4
    DI_DEFAULTSIZE  =8
//--------------------------------------------------------------------------------------------
    //Вызов функции
    renderResourceIcon(&#039;shell32.dll&#039;)
//--------------------------------------------------------------------------------------------
function renderResourceIcon(filename)    
{
try
{

    var ghost=new ActiveXObject(&quot;AutoItX3.Control&quot;)
    ghost.sleep(100)
        ghost.WinMinimizeAll()
    ghost.sleep(100)
        ghost.mouseMove(650,20)
    ghost.sleep(100)
//--------------------------------------------------------------------------------------------
//Получение дескриптора общего контекста экрана или окна
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;USER32.DLL&quot;,&quot;GetWindowDC&quot;,&quot;i=h&quot;,&quot;f=s&quot;,&quot;r=h&quot;)
    hDC=dllWrap.GetWindowDC(0)
    dllWrap=0
    ghost.sleep(100)
//--------------------------------------------------------------------------------------------
//Загрузка библиотеки содержащей графические ресурсы
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;KERNEL32.DLL&quot;,&quot;LoadLibraryA&quot;,&quot;i=s&quot;,&quot;f=s&quot;,&quot;r=l&quot;)
    hLib=dllWrap.LoadLibraryA(filename)
    dllWrap=0
    ghost.sleep(100)
//--------------------------------------------------------------------------------------------
//Создание фоновой заливки для иконок
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;GDI32.DLL&quot;,&quot;CreateSolidBrush&quot;,&quot;i=l&quot;,&quot;f=s&quot;,&quot;r=l&quot;)
    colorRef=eval(&#039;0xfbc284&#039;)
    hBrush=dllWrap.CreateSolidBrush(colorRef)
    dllWrap=0
    ghost.sleep(100)
//--------------------------------------------------------------------------------------------
//Создание подложки
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;GDI32.DLL&quot;,&quot;Rectangle&quot;,&quot;i=luuuu&quot;,&quot;f=s&quot;,&quot;r=l&quot;)
    res=dllWrap.Rectangle(hDC,2,2,610,400)
    dllWrap=0
    ghost.sleep(100)
//--------------------------------------------------------------------------------------------
threshold=200    //Этот параметр определяет максимальное значение
        //идентификатора иконки

    for (i=0,index=1,j=0;index&lt;threshold;index++)
    {
    //------------------------------------------------------------------------------------
    //Извлечение иконки
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;USER32.DLL&quot;,&quot;LoadImageA&quot;,&quot;i=llllll&quot;,&quot;f=s&quot;,&quot;r=l&quot;)
    hIM=dllWrap.LoadImageA(
                hLib,        //Дескриптор модуля содержащего ресурсы
                index,        //Идентификатор ресурса
                IMAGE_ICON,    //Тип загружаемого объекта
                32,        //Ширина иконки
                32,        //Высота иконки
                0)        //Параметр
    dllWrap=0
    ghost.sleep(20)
    //------------------------------------------------------------------------------------    
        if(hIM)
        {
            //Прорисовка иконки в контекст экрана или окна
            dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
            dllWrap.Register(&quot;USER32.DLL&quot;,&quot;DrawIconEx&quot;,&quot;i=lllllllll&quot;,&quot;f=s&quot;,&quot;r=l&quot;)
            hIM=dllWrap.DrawIconEx(
                        hDC,    //Дескриптор контекста
                        10+40*i,//Координата левого угла
                        10+40*j,//Координата левого угла
                        hIM,    //Дескриптор иконки
                        32,    //Отображаемая ширина иконки
                        32,    //Отображаемая высота иконки
                        0,    //Номер кадра AVI ресурса(не используется)
                        hBrush,    //Дескриптор фоновой заливки
                        DI_IMAGE//Дополнительный флаг
                        )
            dllWrap=0
            ghost.sleep(20)
            ghost.ToolTip(    &#039;===========================\n&#039;+ 
                    &#039;Иконка номер: [&#039;+index+&#039;]\n&#039;+
                    &#039;===========================&#039;,2,400)
            i++
            if (i==15){i=0;j++}
        }
    //------------------------------------------------------------------------------------
    }
    //Освобождение библиотеки из памяти
    dllWrap=new ActiveXObject(&quot;DynamicWrapper&quot;)
    dllWrap.Register(&quot;KERNEL32.DLL&quot;,&quot;FreeLibrary&quot;,&quot;i=l&quot;,&quot;f=s&quot;)
    hLib=dllWrap.FreeLibrary(hLib)
    dllWrap=0
    //------------------------------------------------------------------------------------
    //Стандартный цикл отслеживания перемещения мыши
        posX_0=ghost.MouseGetPosX()
        posY_0=ghost.MouseGetPosY()

        ghost.ToolTip(    &#039;===========================\n&#039;+ 
                &#039;Чтобы убрать список иконок\n&#039;+ 
                &#039;сдвиньте курсор мыши на\n&#039;+
                &#039;достаточное расстояние\n&#039;+
                &#039;===========================\n&#039;,2,400)
        while (1)
        {
            posX=ghost.MouseGetPosX()
            posY=ghost.MouseGetPosY()

            if ((Math.abs(posX-posX_0)&gt;10)||(Math.abs(posY-posY_0)&gt;10))
            {
                ghost.send(&quot;{F5}&quot;)
                ghost.sleep(100)
                ghost.ToolTip(    &#039;===========================\n&#039;+ 
                        &#039;Выполнение завершено\n&#039;+ 
                        &#039;===========================&#039;,2,400)
                ghost.sleep(1000)
                WScript.Quit(0)
            }
        }
//--------------------------------------------------------------------------------------------
}
    catch(err)
{
    errorHandler(err)
}

}
//--------------------------------------------------------------------------------------------
function errorHandler(err)
{
erroDesc=    &quot;Произошла ошибка:\n&quot;+
                &quot;Номер:        &quot;+err.number+&#039;.\n&#039;+
                &quot;Описание:    &quot;+err.description+&#039;.&#039;
        WScript.Echo(erroDesc)
        WScript.Quit(0)
}
//--------------------------------------------------------------------------------------------
//Примерно таким же путем,при создании скриптовых проектов,возможно извлекать из файлов 
//ресурсов курсоры и графические изображения.
//--------------------------------------------------------------------------------------------
//poltergeyst</code></pre></div>]]></content>
			<author>
				<name><![CDATA[The gray Cardinal]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2</uri>
			</author>
			<updated>2007-08-03T17:58:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=3838#p3838</id>
		</entry>
</feed>
