Jump to content

Button Icon size


Rhyono
 Share

Recommended Posts

I wanted to put icons on buttons and I used the following to achieve that:

$var = GUICtrlCreateButton("txt",0,0,62,80,$BS_ICON)
GUICtrlSetImage(-1,"icon.ico")
 
Which worked fine, until it came time to compile, so I included the ico file using #AutoIt3Wrapper_Res_Icon_Add and then changed the set image to GUICtrlSetImage(-1,@ScriptFullPath,201). This half works: it puts a 32x32 icon right in the center of the button, but the icon was originally 62x80, just like the button. Since it worked before compilation, I'm assuming there's some setting that I don't have set so that it will maintain its aspect ratio.
 
Side question: is there a way of including the files in a way that allow them to be called by their original file name instead of the new number? Not a big concern; just curious.
 
Ok, here's some test code (I just made it an escape close because I was lazy for this example):
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
$Main = GUICreate("Test", 200,100,0,0)
$btn = GUICtrlCreateButton("text",0,0,62,80,$BS_ICON)
GUICtrlSetImage(-1,"test.ico")
GUISetState(@SW_SHOW)
 
GUIRegisterMsg($wm_command,'_return')
 
While 1
Sleep(10)
WEnd
 
Func _return($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(BitAND($wparam,0x0000ffff) & @LF)
    if BitAND($wparam,0x0000ffff) = $wm_destroy Then Exit
EndFunc
 
Which shows this:
 
150831be58.jpg
 
which is exactly what I want.
 
Now to switch it to (what I thought) was the right way when including icons for compilation:
 
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=test.ico
#AutoIt3Wrapper_Outfile=.\icon_test.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Icon_Add=.\test.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
 
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
$Main = GUICreate("Test", 200,100,0,0)
$btn = GUICtrlCreateButton("text",0,0,62,80,$BS_ICON)
GUICtrlSetImage(-1,@ScriptFullPath,201)
GUISetState(@SW_SHOW)
 
GUIRegisterMsg($wm_command,'_return')
 
While 1
Sleep(10)
WEnd
 
Func _return($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(BitAND($wparam,0x0000ffff) & @LF)
    if BitAND($wparam,0x0000ffff) = $wm_destroy Then Exit
EndFunc
 
960a269efc.jpg
 
Note: I did not use the same icon for the program and in the program in my real program, so that is not the cause of this problem.
Edited by Rhyono
Link to comment
Share on other sites

You are missing the last parameter - usually 0 or 1 (small or normal). Check the Help file.

GUICtrlSetImage(-1,"icon.ico", 0)

 

Just noticed the 201 etc on a re-read.

I'm not aware you can go outside the standard Windows icon sizes.

P.S. Actually you were missing the last two optional parameters in the first instance.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Can you attach an example with the resources please?

Br,

UEZ

I updated the post with source and pictures; did you want the actual icon file? I used a new one for this example to the same end.

 

You are missing the last parameter - usually 0 or 1 (small or normal). Check the Help file.

 

Just noticed the 201 etc on a re-read.

I'm not aware you can go outside the standard Windows icon sizes.

P.S. Actually you were missing the last two optional parameters in the first instance.

 

Aren't those parameters referred to as optional because they are optional? Using them didn't improve anything and if I can do outside of the default sizes before compilation, I was hoping there would be a way to do so after.

Link to comment
Share on other sites

I wasn't sure you had played with those options.

Strictly speaking I guess, you are applying a small image to a button, and not an icon, which may be being converted to a standard sized icon on compile.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I figured that might be what I was running into, then I realized I could just use GUICtrlCreatePic and change the format of the image instead of using an icon. I'm still curious if there was a right way of applying that icon to the button, but it's no longer a concern since I can do it differently.

Link to comment
Share on other sites

Try something like this here (I used >ResourceEx.au3):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=test.ico
#AutoIt3Wrapper_Outfile=.\icon_test.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_File_Add=Test.ico, RT_ICON, ICO_1, 0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "ResourcesEx.au3"

_GDIPlus_Startup()
$Main = GUICreate("Test", 200, 100, 0, 0)
$btn = GUICtrlCreateButton("", 0, 0, 62, 80, $BS_BITMAP)
$hIcon = _Resource_GetAsIcon('ICO_1')
$hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon)
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($btn), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
_WinAPI_DestroyIcon($hIcon)
_GDIPlus_BitmapDispose($hBitmap)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $btn
            MsgBox(0, "Info", "Button was clicked")
    EndSwitch
WEnd

What you can do is to use a bitmap instead of an icon and add it to the exe using #AutoIt3Wrapper_Res_File_Add or embed the bitmap as a binary string.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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