Jump to content

GUICtrlCreateIcon


GEOSoft
 Share

Recommended Posts

OK so I've used it a hundred or so times.

What's the big secret (that I missed) that will allow them to work on a child window??

They work fine on a standard window but I had to replace them with buttons to get the icons to show on a child window and that is NOT an impressive look.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Far as I know it works on child winodws.

How about a short script that can duplicate the problem your having.

I'll put one together because the script it's in is far from short. It's at almost 4000 lines now an only about 40% of the code is in.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Now I'm really confuzzled!!!! Like I said before the icon is not an issue when it's in a standalone gui. It only became a problem after I converted it to a child window. The code below will show the proble. While I was putting this little demo together I discovered that if I change the image source from user32.dll to shell32.dll then all will be well ?????. I'm really interested in finding out why it happens. Now that I know what the issue is I know how to fix it but it is confussing. I'd pull my hair out but I don't have any left.

#cs
   AutoIt;          3.2.1.13
   Language;        English(US)
   Platform;        All
   Author;          GEOSoft
   Function;        
#ce
;#NoTrayIcon
#Include <GuiConstants.au3>
Opt ("TrayIconDebug", 1)
Opt ("GUICoordMode", 2)

Const $Gh = 425
Const $Gph = $Gh - 60
Const $Gw = 600
Const $Gpw = $Gw / 2 - 10;290
Const $Tvw = $Gpw - 5;285
Const $Oh = $Gh / 21
Const $Bw = $Gw / 7.5
Const $Bh = $Oh + 10

;;<<=====================  Create the main frame
$Form_Main = GuiCreate ('This is just a test GUI', $Gw, $Gh + 100)
GuiSetBkColor (0xFFFFFF)
$Menu = GuiCtrlCreateMenu('&File')
$Menu_T = GUICtrlCreateMenuItem('&Click here', $Menu)
$Menu_Exit = GUICtrlCreateMenuItem('E&xit', $Menu)

GUISetState () 

;;<<=====================  Create the top frame
$Form_Top = GuiCreate ("Project", $Gw, 40, 0, 0, $Ws_Child + $Ws_Dlgframe, -1, $Form_Main)
GuiSetBkColor (0x578BC8)
$Lbl_Proj = GuiCtrlCreateLabel ('This is for dummy purposes', 15, 10, 300, $Oh, 1)
GuiCtrlSetFont ($Lbl_Proj, 10, 800)
GuiCtrlSetColor ($Lbl_Proj, 0xFFFFFF)
GUISetState ()

;;<<==================== Create bottom frame 
$Form_Btns = GuiCreate ("Standard Buttons", $Gw, 45, 0, $Gh + 35, $Ws_Child, -1, $Form_Main)
GuiSetBkColor (0x578BC8)
$Btn_Proceed = GuiCtrlCreateButton ('Proceed', 60, 8, $Bw, $Bh, 0x0001)
GuiCtrlSetState ($Btn_Proceed, 128)
GuiSetCoord ($Gw / 2 + 80, 8)
$Btn_Cancel = GuiCtrlCreateButton ('Cancel', -1, -1, $Bw, $Bh, 0x0040)
$Btn_Exit = GuiCtrlCreateButton ('Exit', 10, -1, $Bw, $Bh)
GuiSetState ()

$Form_Tabs = GuiCreate ("Tabs Window", $Gw, $Gh - 10, 0, 45, $Ws_Child + $Ws_Dlgframe, -1, $Form_Main)
Global $Tab = GuiCtrlCreateTab (0, 0, $Gw + 3, $Gh, 0x0010)

;;*******************  Create some Tabs  ***********************
Global $Tab_1 = GuiCtrlCreateTabItem ('Tab 0')
GUISetCoord (10, $Oh + 15)
GuiCtrlCreateLabel('Just for effect',-1,-1,100,20)
$Btn_1 = GUICtrlCreateButton("Click first",-1,10,$Bw,$Bh)
$Btn_2 = GUICtrlCreateButton("Click second",-1,10,$Bw,$Bh)

Global $Tab_2 = GuiCtrlCreateTabItem ('Tab 1')


Global $Tab_3 = GuiCtrlCreateTabItem ('Tab 2')
GUISetState()

While 1
    $Msg = GuiGetMsg ()
Switch $Msg
Case -3, $Menu_Exit, $Btn_Exit
Exit
Case $Menu_T, $Btn_1
    Test_Window()
Case $Btn_2
    Test_Window2()
EndSwitch
Wend

Func Test_Window()
    
    GUICtrlSetState($Btn_Proceed,80)
    $Form_Top_2 = GuiCreate("Test Top", $Gw, 40, 0, 0, $WS_CHILD + $WS_DLGFRAME, -1, $Form_Main)
    GuiSetBkColor(0x578BC8)
    $Lbl_11 = GuiCtrlCreateLabel('This one uses a button ' ,15,10,$Gw-30,20)
    GuiCtrlSetFont($Lbl_11,11,800)
    GuiCtrlSetColor($Lbl_11,0xFFFFFF)
    GUISetState()
    $Form_1 = GUICreate ('Problem ', $Gw, $Gh, 0, 45, $WS_CHILD, -1, $Form_Main)
    GuiSetBkColor(0xeceef5)
    GUISetCoord (20, 20)
    $Icon = GUICtrlCreateButton ('',-1,-1,32,32,0x0040)
    GUISetCoord(100,130)
    GUiCtrlCreateLabel('Click Exit to Return',-1,-1,100,20)

    GUICtrlSetImage($Icon,'User32.dll',1,0)


    GUISetState (@Sw_Hide,$Form_Tabs)
    GUISetState(@SW_Show, $Form_1)

    While 1
        $Msg = GUIGetMsg ()

        Switch $Msg
            Case -3, $Menu_Exit
                Exit
            Case $Btn_Proceed, $Btn_Cancel, $Btn_Exit
                GUICtrlSetData($Btn_Proceed, 'Proceed')
                GUIDelete ($Form_1)
                GuiDelete($Form_Top_2)
                GUISetState (@SW_Show,$Form_Tabs)
                GuiSetState(@SW_SHOW, $Form_Top)
                ExitLoop
        EndSwitch

    Wend
EndFunc

Func Test_Window2()
    
    GUICtrlSetState($Btn_Proceed,80)
    $Form_Top_2 = GuiCreate("Test Top", $Gw, 40, 0, 0, $WS_CHILD + $WS_DLGFRAME, -1, $Form_Main)
    GuiSetBkColor(0x578BC8)
    $Lbl_12 = GuiCtrlCreateLabel('This one uses an Icon ' ,15,10,$Gw-30,20)
    GuiCtrlSetFont($Lbl_12,11,800)
    GuiCtrlSetColor($Lbl_12,0xFFFFFF)
    GUISetState()
    $Form_2 = GUICreate ('Problem ', $Gw, $Gh, 0, 45, $WS_CHILD, -1, $Form_Main)
    GuiSetBkColor(0xeceef5)
    GUISetCoord (20, 20)
    $Icon = GUICtrlCreateIcon ('', -1, -1, -1, 42, 42)
    GUISetCoord(100,130)
    GUiCtrlCreateLabel('Click Exit to Return',-1,-1,100,20)

    GUICtrlSetImage($Icon,'User32.dll',1,0)


    GUISetState (@Sw_Hide,$Form_Tabs)
    GUISetState(@SW_Show, $Form_2)

    While 1
        $Msg = GUIGetMsg ()

        Switch $Msg
            Case -3, $Menu_Exit
                Exit
            Case $Btn_Proceed, $Btn_Cancel, $Btn_Exit
                GUICtrlSetData($Btn_Proceed, 'Proceed')
                GUIDelete ($Form_2)
                GuiDelete($Form_Top_2)
                GUISetState (@SW_Show,$Form_Tabs)
                GuiSetState(@SW_SHOW, $Form_Top)
                ExitLoop
        EndSwitch

    Wend
EndFunc

When you click a button to change to a demo window just click Exit to return to the main frames.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I've solved this as far as my end is concerned but I still don't know why it happened with user32.dll. I'm not about to test all of the dll's on my system to see if it happens with others too. Since I had the icons I needed saved as png files from past use, I just created new icons from thode and added them into my icon library which is already being called by this script anyway.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I understand now what you want to say .

Why GuiCtrlSetImage works on Button control and not on Icon control?

That is what is demonstrating your long example.

This as nothing todo with child windows

#Include <GuiConstants.au3>
Opt ("TrayIconDebug", 1)
Opt ("GUICoordMode", 2)

Const $Gh = 425
Const $Gw = 600
Const $iconfile='user32.dll'

    $Form_2 = GUICreate ('Problem ', $Gw, $Gh, 0, 45)
    GuiSetBkColor(0xeceef5)
    GUISetCoord (20, 20)
    $Icon = GUICtrlCreateIcon ('', -1,-1, -1, 32, 32)
    GUISetCoord(100,130)
    GUiCtrlCreateLabel('Click Exit to Return',-1,-1,100,20)

    $_n2=GUICtrlSetImage($Icon,$iconfile,1,0)

    GUISetState(@SW_Show, $Form_2)

    While 1
        $Msg = GUIGetMsg ()

        Switch $Msg
            Case -3
                Exit
        EndSwitch

    Wend

In fact the recent beta callow now to retrieve icon by name or by ordinal. See the beta doc.

The change was needed as the release was not very deterministic.

You can read that positive number act as name now. and negative number select the icon by ordinal reference.

name/positive number select the icon in the "icon group" as shown by "reshacker" tool. "@icon shushi" tools does the same. This allow to select the best icon according to the size you selected.

back to your user32.dll/ sheel32.dll, the point is there is no icon name equal to "1" so the icon creation is aborted. Just check the return value.

in user32.dll the first legal name is "100" which can be selected with the ordinal numbering selection with a negative number -1. In this case the best iconsize will not be selected but will be resize to the selected size.

so

$_n2=GUICtrlSetImage($Icon,$iconfile,100,0)

or

$_n2=GUICtrlSetImage($Icon,$iconfile,-1,0)

will work ;)

Link to comment
Share on other sites

I understand now what you want to say .

Why GuiCtrlSetImage works on Button control and not on Icon control?

That is what is demonstrating your long example.[/qoute] Had to make it long to demonnstarte but I could have cleaned up the empty lines

I did read the latest docs. Calling by name is an issue since reshacker reports the first name as 100 and Icon Workshop reports the first name as Icon 1. When I created the icons from my images and added them to my icon library they were named 023 through 026 each containing 6 images. The first icon in that library is named 000 also containing 6 images.

Since I wasn't using the first icon in user32 then

GUICtrlSetImage($Icon,'user32.dll',1)oÝ÷ ÚÈhºWp¢¹ºÚ"µÍÝZPÝÙ][XYÙJ    ÌÍÒXÛÛ ÌÎNÜÚ[ÌÌÎNË
oÝ÷ ۥج¦V²¶»-Ê't¡zYwÙ«­¢+ÙU%
ÑɱMÑ%µ ÀÌØí%½¸±MÉ¥ÁѥȵÀìÌäìÀäÈíAáÁÉÍ̹¥°Ìäì°ÈÌoÝ÷ ۥج¦V²¶©®^®'(
Þʬk(§ØZµ«­¢+ÙU%
ÑɱMÑ%µ ÀÌØí%½¸±MÉ¥ÁѥȵÀìÌäìÀäÈíAáÁÉÍ̹¥°Ìäì°´ÈФ

would also have displayed the right image?

And BTW, why does it work properly if $Icon is a button?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

it works for the button because AutoIt call different API for button. We cannot manage to use the same as the button will be badly filled with the code use for icon control.

Icon Workshop is certainly showing the internal number not the Icon name as reshacker does.

For .icl there is no such internal naming so positive number will reference the 0-based and negative number the 1-based.

I hope that answer all your questions.

I did a change for the next beta in the doc. ;)

Link to comment
Share on other sites

I hope that answer all your questions.

I did a change for the next beta in the doc. :evil:

My mind is a bit foggy today but I have this tingling in the back of my neck that says "There's a problem coming" One of the Options in Icon Express is to customize the project folders with icons and tips. At the moment the only icons used are in Pxpress.icl which does not seem affected by this change and I don't think I'm even going to consider changes to that after reading you reply. As a second note, not everyone uses resource hacker or anyother app that will return the icon name. Most apps call icons by the 0 based index.

:lmao:

;)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Icon Workshop is certainly showing the internal number not the Icon name as reshacker does.

Just for the heck of it I just checked a couple of DLL's i GConvert and it dorsn't give icon names at all. ;)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...