Jump to content

_GUIImageList*() functions: how to use correctly?


rudi
 Share

Recommended Posts

Hi.

From the help files I tried my luck and despetately fail.

I think I got, that _GUIImageList_AddIcon() adds an image to a list, previously created using _GUIImageList_Create().

But how to ADDRESS the 2nd / 3rd image of the list? From the help files I can't see it right now, sorry!

I obviously miss, what exatly IS an ImageList? Elements can be added, but it's not an array...

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

; %systemroot%\system32\shell32.dll
; 22 = search
;131 = delete
;146 = green arrow

Global $hImage, $hSearch, $hDel, $hGreen, _
        $BtnSearch, $BtnDel, $BtnAdd, _
        $h, $w, _
        $Title


$hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($hImage, "shell32.dll", 22, True)
_GUIImageList_AddIcon($hImage, "shell32.dll", 131, True)
_GUIImageList_AddIcon($hImage, "shell32.dll", 146, True)

If IsArray($hImage) Then
    $Title = "is an array"
Else
    $Title = "is *NOT* an array"
EndIf

MsgBox(0, $Title, "Ubound of the Image List is " & UBound($hImage))

$w = 300
$h = 200
GUICreate("Manage Entries", $w, $h)
GUISetState()


$BtnSearch = GUICtrlCreateButton("Lookup Entry", 20, 20, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnSearch, $hImage)
Opt("guicoordmode", 2)
$BtnDel = GUICtrlCreateButton("Delete Entry", -1, 10, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnDel, $hImage)
$BtnAdd = GUICtrlCreateButton("Add Entry", -1, 10, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnAdd, $hImage)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

This one explains what an Imagelist is under "Remarks":

http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx

And this explains the behavior of an Imagelist assigned to a button under "Remarks":

http://msdn.microsoft.com/en-us/library/bb775975%28VS.85%29.aspx

Link to comment
Share on other sites

Hi.

Thanks for your reply.

http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx

http://msdn.microsoft.com/en-us/library/bb775975%28VS.85%29.aspx

Hm. This doesn't help me :huggles: how to make use of the 2nd and 3rd element in my imagelist.

Would you mind :D to change the script I wrote, so that just the 2nd button will display the 2nd imagelist icon?

After seeing how to do so I hope, that I can sort out myself how to do it for the 3rd and every eventually following icon in the imagelist.

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Buttons use a special way of interpreting ImageLists. Each Button has its own imagelist. Then, the first 5 or 6 images of the imagelist belong to the different states of the button (normal, hover, pressed, focused, disable, ...). This means, you can specify one iamge for each state. To use different mages for different buttons you have to create multiple image lists.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Each Button has its own imagelist.

Ahhhh! :

Then, the first 5 or 6 images of the imagelist belong to the different states of the button (normal, hover, pressed, focused, disable, ...).

:D:) Ahhhhhhh! :D :D

Now I get what this means:

enum PUSHBUTTONSTATES {
    PBS_NORMAL = 1,
    PBS_HOT = 2,
    PBS_PRESSED = 3,
    PBS_DISABLED = 4,
    PBS_DEFAULTED = 5,
    PBS_STYLUSHOT = 6,
};

This means, you can specify one iamge for each state.

I see. And when I just define the PBS_NORMAL, then that image propably is the "active" one, regardless of the button's state. I'll try that right now :huggles:

To use different mages for different buttons you have to create multiple image lists.

Great, :D thanks, really great explanation. From the help file I had no chance to get this.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi again.

My initial task is solved now: Different icons for different buttons.

Due to this here

_GUICtrlButton_SetImageList()
...
$hImage A handle to the image list.
  Should contain either a single image to be used for all states or individual images for each state listed in the following:
    1 - Normal
    2 - Hot
    3 - Pressed
    4 - Disabled
    5 - Defaulted
    6 - Stylus Hot (tablet computers only) 
...

... I'd expect, that an image map, that's holding not just the initial image, would "service" different icons to different states of a button? This is not required for what I coded right now, but I'm interested in how to use that one as well.

; %systemroot%\system32\shell32.dll
; 22 = search
;131 = delete
;146 = green arrow
;147-151 = just any different icons

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>


Global $h1Image, $h2Image, $h3Image, _
        $hSearch, $hDel, $hGreen, _
        $BtnSearch, $BtnDel, $BtnAdd, _
        $h, $w, _
        $Title


$h1Image = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($h1Image, "shell32.dll", 22, True)

$h2Image = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($h2Image, "shell32.dll", 131, True)

$h3Image = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 146, True)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 147, True)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 148, True)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 149, True)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 150, True)
_GUIImageList_AddIcon($h3Image, "shell32.dll", 151, True)

$w = 300
$h = 200
GUICreate("Manage Entries", $w, $h)
GUISetState()

$BtnSearch = GUICtrlCreateButton("Lookup Entry", 20, 20, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnSearch, $h1Image)
Opt("guicoordmode", 2)
$BtnDel = GUICtrlCreateButton("Delete Entry", -1, 10, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnDel, $h2Image)
$BtnAdd = GUICtrlCreateButton("Add Entry", -1, 10, $w - 40, 40)
_GUICtrlButton_SetImageList($BtnAdd, $h3Image)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi.

Pls let me bump the 2nd question:

From the help file I thought, that the images #2-#6 are fixed associated with the different states of a button.

I couldn't get this working. What's my mistake? (see posting above)

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Adjusted your example a little, this behaves as I expect. What exactly did you expect to behave different?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.2.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

Opt("guicoordmode", 2)

Global $hImage, _
        $Btn1, $Btn2, $Btn3, _
        $h, $w

$w = 300
$h = 300
GUICreate("Manage Entries", $w, $h)

$Btn1 = GUICtrlCreateButton("Button1", 20, 20, $w - 40, 40)
$Btn2 = GUICtrlCreateButton("Button2", -1, 20, $w - 40, 40)
$Btn3 = GUICtrlCreateButton("Button3", -1, 20, $w - 40, 40)
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateInput("", -1, 20, $w - 40, 20)

$hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($hImage, "shell32.dll", 3, True) ; 1 - Normal => Closed Folder
_GUIImageList_AddIcon($hImage, "shell32.dll", 4, True) ; 2 - Hot => Open Folder
;_GUIImageList_AddIcon($hImage, "shell32.dll", 50, True) ; Empty in shell32.dll for me => "no icon"
_GUIImageList_AddIcon($hImage, "shell32.dll", 128, True) ; 3 - Pressed => Music Folder
_GUIImageList_AddIcon($hImage, "shell32.dll", 109, True) ; 4 - Disabled => Disabled Sign
_GUIImageList_AddIcon($hImage, "shell32.dll", 129, True) ; 5 - Defaulted => Media Folder
;_GUIImageList_AddIcon($hImage, "shell32.dll", 129, True) ; 6 - Stylus Hot (tablet computers only)

_GUICtrlButton_SetImageList($Btn1, $hImage)
_GUICtrlButton_SetImageList($Btn2, $hImage)
_GUICtrlButton_SetImageList($Btn3, $hImage)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

If you don't want to switch the icons, just assign the same icon to different states.

Edited by KaFu
Link to comment
Share on other sites

Hi.

Adjusted your example a little, this behaves as I expect. What exactly did you expect to behave different?

I expected, that this way the Icon should change, depending on the state of the button: "mouse over", "pressed", "Button focus", "Button disabled" ...

For me also your modified example presents the "Folder" icon, independent of the current button state.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi.

I expected, that this way the Icon should change, depending on the state of the button: "mouse over", "pressed", "Button focus", "Button disabled" ...

For me also your modified example presents the "Folder" icon, independent of the current button state.

Regards, Rudi.

Th different icons for different button states work only when visual styles are enabled. Otherwise, the image is always the

'normal' image.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Link to comment
Share on other sites

Hi.

You live and you learn :huggles:...

Not fast enough :D (the learning. Living speed is fine : )

so that throws the next question: Howto enable visual styles:

http://msdn.microsoft.com/en-us/library/5d1acks5(VS.80).aspx doesn't help me.

Autoit Help: Some hits for these[1] topics, but I defenitely don't get it right now:

So how to enable visual styles to make use of the full capacity these imagemaps offer?

Regards, Rudi.

[1] these topics didn't help me:

1.) "User Defined Function Reference" -> GUIToolTip_SetWindowTheme: Sets the visual style (I don't want a tooltip)

2.) "GUI Control Styles" -> $TCS_RIGHT (not available, if visual styles are enabled)

3.) "_GUICtrlTab_Create" -> same as 1.)

4.) "User Defined Function Reference" -> "_GUICtrlToolbar_SetWindowTheme" -> confusing.

5.) -"- -> "$tagMargins" -> Defines the margins of windows that have visual styles applied

6.) Keyword Reference -> $tagMargins (same as 5.)

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

You are not able to enable it, this must be done by the user since this is an OS-setting. You can only disable the style for (parts of) your script.

You could try to automate the task of enabling visual styles for the OS, but this would affect the whole UI.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

http://msdn.microsoft.com/en-us/library/y6kzhf8d%28VS.80%29.aspx

With Visual Styles (also known as Windows XP Themes) Windows XP introduced a new look and feel to the Windows user interface, with controls that have rounded corners and that change color when you pause your mouse over them.

Visual styles are enabled by default.

What OS are you running on :D?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...