Jump to content

Problem With Quality of ICONs on Buttons with this _GUIImageList and Disappear at XP!


IgImAx
 Share

Recommended Posts

Hi All :D

Update: (thanks to AZJIO Posted Image, until now, the only answer I found is !! But I still like to solve the problem by using and showing my icons in icon format and do not like to convert them to BMP+BmpMask! Posted Image)

Before starting, I'm new ( :sweating:) in Autoit programing and this is my first project with it so sorry for my simple or noob questions!! Also sorry for my bad grammar too!But I'm not new in programing world and forum activities! ;).

I have a problem with showing Icon(should be a Mask! icon) on a Button with Text on it! My Icons are bigger than 70x70 pixels and have transparent parts! Past 2 days, I was searching too many Topics of this forum with Google and found some new ways or answers, but none of them solve my problem! already I found these posts(these were the best ones!):

First Problem:

I was using some 72x72 pixel or higher Icon with color depth '32bit XP-RGB + Alpha' on Buttons. (For bellow example I Upload this icon for your test) I was using [section 1] functions at bellow sample code for first time.

These functions (GUICtrlCreateButton and GUICtrlSetImage) work fine together and as you can see at Picture 1 my sample program show icon of "Instal 1" button correctly with right quality inside Windows 7. Only think I do not like about this way was that Text will place above Icon! and I did not found any way to exchange their positions! anyway:

But when I tested my program at Windows XP SP3, all buttons with Icon+Text were only showing text! Please look at Picture 2 and "install 1" button. I know I can use '$BS_ICON' at GUICtrlCreateButton function and my Icon will show at XP but by using that parameter Text will disappear!!? Also I do not like use BMP of my Icon! be cause It will lose transparent parts!

Second Problem:

After too many searching, I did learn about how to using GUIImageList with GUICtrlCreateButton and the resualt was [section 2] of bellow sample.

This new method have three advantage on previous one:

  • I can put Button Text anywhere I like without effecting my Icon position!

  • I can use more than one image for different events!

  • XP problem solved!
But! again :(!!! My biggest problem was that all of those Icons have poor quality in both OS!!! please look at both "Install 2" buttons on Picture 1 and Picture 2!

Posted ImageMy Questions:

******************

  • How can I solve [section 1] at XP without losing MASK capability of icons!?

  • How can I show Icons with their original qualities by using [section 2] codes!?

#include <GUIButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>

Local $hGUI = GUICreate("Autoit v" & @AutoItVersion & " OS: " & @OSVersion,300,130)

FileInstall("install-win.ico" , @TempDir & "\install-win.ico",1)

;~ ----------------------------------------------------------------------
;~ [Section 1]
GUICtrlCreateButton('Install 1', 10, 10, 85, 105, $BS_BOTTOM)
GUICtrlSetImage(-1,@TempDir & "\install-win.ico")


;~ ----------------------------------------------------------------------
;~ [Section 2]
GUICtrlCreateButton('Install 2', 205, 10, 85, 105, $BS_BOTTOM)
Local $hImageList = _GUIImageList_Create(72, 72, 5, 1)
_GUIImageList_AddIcon($hImageList, @TempDir & "\install-win.ico",0,True)
_GUICtrlButton_SetImageList(-1, $hImageList, 2)

GUISetState(@SW_SHOW, $hGUI)

While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
         ExitLoop

EndSwitch
WEnd
GUIDelete($hGUI)

Download link for 'Install-Win.ico' file

Posted Image

Picture 1

Image from Windows 7

Posted Image

Picture 2

Image from Windows XP SP3 (VMware)

Thanks in Advanced

IgImAx

Edited by IgImAx

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

Link to comment
Share on other sites

#include <GUIButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>

Local $hGUI = GUICreate("Autoit v" & @AutoItVersion & " OS: " & @OSVersion,300,130)

; FileInstall("install-win.ico" , @TempDir & "\install-win.ico",1)

;~ ----------------------------------------------------------------------
;~ [Section 1]
GUICtrlCreateButton('Install 1', 10, 10, 85, 105, $BS_ICON)
GUICtrlSetImage(-1,"shell32.dll", 4)


;~ ----------------------------------------------------------------------
;~ [Section 2]
GUICtrlCreateButton('Install 2', 205, 10, 85, 105, $BS_BOTTOM)
Local $hImageList = _GUIImageList_Create(72, 72, 5, 3)
_GUIImageList_AddIcon($hImageList, "shell32.dll", 4,True)
_GUICtrlButton_SetImageList(-1, $hImageList, 2)

GUISetState(@SW_SHOW, $hGUI)

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

Link to comment
Share on other sites

Welcome to the forum. I wanted to stop and say, that that is the best first post I have ever seen. Wish others would learn from this - including me.

2¢

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Hi Frinds

@AZJIO

Wow! Thanks for fast reply!

Well! previously, I found out about "$BS_ICON" option before! if you use "$BS_ICON", your Icons inside buttons will be display at XP, but It make another problem! when you use it, your text will be not show on button!

In fact by using "$BS_ICON" one problem will be solve and another one will be rise!

About this line:

_GUIImageList_AddIcon($hImageList, "shell32.dll", 4,True)

I still see that Icon in bad quality!!? also as I mention I have several large icons -like that one I put at post #1- in my program and none of them are from windows DLL or ... and some of them made by myself! Unfortunately when I use GUIImageList all of them show in very poor quality! :(

@nitekram

Thanks brooo <3 for your warm welcome ... Well maybe one of the reasons is I'm an old forum geek!!! loool ... I have some Guide and Book in Persian forums that you can see them over here and a special topic for Automation Applications over here.

Since you mention it!, For these 4 or 5 past days I learn and use great Idea and UDFs from you guys over here and I like to thanks you all for these great forum (I'm trying to use "Like" but it seems i lack of some permissions!? ;) )

Thanks again guys ...

IgImAx

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

Link to comment
Share on other sites

Dear AZJIO

The first option may be only without the text. I had already tried all the styles or icon only, or text..

Yes! It's seems it is a downside for this function! well, at first I think maybe it's my little knowledge about coding at Autoit cause this problem in my program! then when I search I found no answer for It and I ask about it here so maybe I miss something!?

Therefore, If this is a small problem in this function, I hope we will see it disappear in new update ;)

The second version shows the icon properly (Windows XP).

You need to specify the icon 32x32, otherwise it stretches them.

_GUIImageList_Create(72, 72, 5, 3)

Yes I notice, but what about my Icons!? That one is 72x72 and I do not see it in good quality at 7 or XP!? (I uploaded two picture at post#1) If you could, Please download that icon and test it to see my point!

Thanks

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

Link to comment
Share on other sites

IgImAx,

Save BMP, it works well

#include <GUIButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>

; $sPath = @ScriptDir&'\icons.ico'
; $sPath = @ScriptDir&'\Install-Win.ico'
$sPath = @ScriptDir&'\Install-Win.bmp'

Local $hGUI = GUICreate("Autoit v" & @AutoItVersion & " OS: " & @OSVersion,300,130)

; FileInstall("install-win.ico" , @TempDir & "\install-win.ico",1)

;~ ----------------------------------------------------------------------
;~ [Section 1]
GUICtrlCreateButton('Install 1', 10, 10, 85, 105, $BS_ICON)
GUICtrlSetImage(-1,"shell32.dll", 4)


;~ ----------------------------------------------------------------------
;~ [Section 2]
GUICtrlCreateButton('Install 2', 205, 10, 95, 105, $BS_BOTTOM)
Local $hImageList = _GUIImageList_Create(72, 72, 5, 3)
; _GUIImageList_AddIcon($hImageList, $sPath, 0,True)
_GUIImageList_AddBitmap($hImageList, $sPath)
_GUICtrlButton_SetImageList(-1, $hImageList, 2, 0, 10)

GUISetState(@SW_SHOW, $hGUI)

While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
         ExitLoop
EndSwitch
WEnd
GUIDelete($hGUI)
Link to comment
Share on other sites

AZJIO

Aha! ;) you mean convert ICO file to a BMP file? or take a snapshot of a button while text and icon show on it in a good quality then use that snapshot as a bitmap and put it on the button!?

Well that a good Idea and will work. But, Dose it not better that Autoit show Icons without problems in above situations!? Since when it dose show some Icons in proper ways and if they have MASK so they show all changes of windows Themes in right ways, but BMP (Still Images) do not have that capability! am I right?

Anyway, that was a good idea and thank you again for keep try to help me and I will keep it that in my mind for the last moments, just in case If some how with some helps the _GUIImageList problem did solved! (cause I like capabilities of these functions)

P.S.: Just two things: Showing Text on buttons and Icons(png) Mask capability are important for me too! as I mention before.

Cheeeers

Edited by IgImAx

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

Link to comment
Share on other sites

Hi AZJIO

Thanks for image.

You can convert icon to bmp

__GUICtrlMenuEx_CreateBitmapFromIcon_XP

_CreateBitmapFromIcon

Thanks for links, I did check both of them and test them . second link is not complete code while first link is so much better and it think about windows XP and others to separate functions for each OS.

But I do not know how to use "__GUICtrlMenuEx_CreateBitmapFromIcon_XP" at my sample code!??! unfurtunetlay all samples over there are for how to use GUICtrlMenuEx for creating Menus and not Buttons!

(Update: Please saw better way to use Mask at the bottom of this post)

Posted Image While I try to figure out how to use GUICtrlMenuEx UDF, suddenly I saw $sMask="" parameter at :

_GUIImageList_AddBitmap($hWnd, $sImage [, $sMask=""])

Then I try it, and create a BMP file from Install-Win.ico and with Corel PhotoPaint create a BMP Mask for it and the result at XP was like this:

Posted Image

Picture 1 Posted Image

As you can see at above image, BMP+Mask showed as I like it on Button! I mean it has transparent border. That was the advantage of it but about disadvantage of it :
  • Now, icons (They are bmp now!) do not have a sharp edges. (there are some bad pixels!) Need more work at Corel PhotoPaint to build smother Mask! Posted Image

  • I had to add two BMP files to my exe file for each Icon that have above problem!!! Posted Image
To solve both above disadvantages, I think we could use some features inside Autoit!? for example use an UDF to Create a BMP and MASK-BMP of an Icon!!? I found but I did not find out how can I use it!?

Anyway, The code I use that make above output at Picture 1 was this one:

; Link: http://www.autoitscript.com/forum/topic/147794-problem-with-quality-of-icons-on-buttons-with-this-guiimagelist-and-disappear-at-xp/
#include <GUIButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>


Local $hGUI = GUICreate("Autoit v" & @AutoItVersion & " OS: " & @OSVersion,300,130)

Local $Filename = "install-win.bmp"
Local $MaskFilename = "install-win-mask2.bmp"

;~ ----------------------------------------------------------------------
;~ [Section 2]
GUICtrlCreateButton('Install 2', 205, 10, 85, 105, $BS_BOTTOM)
Local $hImageList = _GUIImageList_Create(72, 72, 5,1)
_GUIImageList_AddBitmap($hImageList, $Filename,$MaskFilename)
_GUICtrlButton_SetImageList(-1, $hImageList, 2,"",10)

GUISetState(@SW_SHOW, $hGUI)

While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
         ExitLoop

EndSwitch
WEnd

GUIDelete($hGUI)

For your Test I put both BMPs here:

Icon converted To BMP:

Install-Win.bmp

Create BMP Mask for Icon:

Install-Win-Mask2.bmp

Posted Image(Update)

Well! I found a better way to creat a MASK for an Icon/PNG file with Transparent color. Usually a mask should have two color! White & Black. White color will be transparent part of your Icon/PNG and Black part will be Image(visible) part of those files! as you can see at above links I use that method too! but the resualt picture has not greate sharp border!

So, I try to examine this way and It answer very well!!: Just use Only one BMP file as Original file and Mask file! The only trick is that you should make transparent part White and hope your image do not have White color in its visible parts!! (Pure! White = RGB (255,255,255) = 0xFFFFFF) here a full screen shot of my app and its new look for Icons that convert to one BMP MASK File:

Posted Image

Picture 2

Those Buttons that have Text on them,

are using this new MASK method

Last Button create as usual with $BS_ICON option, cause it do not have Text on it!

If you like to see what I mean in action! Just download bellow file which is like to "Install-Win.bmp" but I did these changes before make it:
  • Convert ICON file to PNG by using 'Microangelo Toolset 6' then open PNG file into Corel PhotoPaint. (you can use Microangelo Toolset to do the rest process but for some shapes its harder to do so!)
  • Deselect current Mask and Select better MASK for it by selection Smooth Border = 1 inside Corel settings and by this option Mask will go to near of first and very very dark visible pixels!
  • Select Default Background Color to White
  • Reverse Mask so visible part selecting now.
  • Now, If I press Delete key, none-selected parts will be cleared and fill with White color.

Please download and look this new "Install-Win-BetterMasked.bmp":

Install-Win-BetterMasked.bmp

and change these two lines at above sample to see how it get better borders:

Local $Filename = "install-win.bmp"
Local $MaskFilename = "install-win-mask2.bmp"

With these lines (Both variables use the same file):

Local $Filename = "Install-Win-BetterMasked.bmp"
Local $MaskFilename = "Install-Win-BetterMasked.bmp"

The rest lines are the same as before. Posted Image

Thanks again for your Helps

Edited by IgImAx

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

Link to comment
Share on other sites

Hi all

I found a better method for creating MASK file! Therefor, I updated my Post#10 with new method. (Win XP show it too!)

But, Still, I like to know how can I solve the problem of GUIImageList function as I describe its problem at Post#1... Cause using and Icon without need to convert it to anything is much easier/better quality results/Less Time Consumer .... Posted Image

Thanks Again

Teach Others to learn more yourself

My eBooks and Articles in Persian: IgImAx Home! * and more here

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