Sign in to follow this  
Followers 0
GEOSoft

Use an Icon as a button

25 posts in this topic

It would be really nice if we could give an icon a button styleor use an icon on the button face instead of text. :D:huh2:


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!"

Share this post


Link to post
Share on other sites



It's trying to get the Pic to look like a button as in a toolbar button. Secondly if I could use an icon then I could include an icon library and call them from there.


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!"

Share this post


Link to post
Share on other sites

At the moment I try to change the GUISetControl-function for the "button", so if you use the "BS_ICON"-style then instead of the text it will be used to define the iconlocation and index (like the icon-GUISetControl):

For instance it could be like:

...
$BS_ICON = 0x00000040
$BS_BITMAP = 0x00000080
...
$buttonok = GUISetControl("button","OK",50,50,70,20); normal 'text'-button
$buttonchoosefolder = GUISetControl("button","shell32.dll|150",50,100,70,30,$BS_ICON)

We will see if it works :D

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So this is how it looks at the moment:

This script:

$BS_ICON = 0x00000040
$BS_BITMAP = 0x00000080
GUICreate("test",240,120)
$button1 = GUISetControl("button","shell32.dll|5",0,0,40,40,$BS_ICON)
$button2 = GUISetControl("button","shell32.dll|7",40,00,40,40,$BS_ICON)
$button3 = GUISetControl("button","shell32.dll|22",80,00,40,40,$BS_ICON)
$button4 = GUISetControl("button","shell32.dll|23",120,0,40,40,$BS_ICON)
$button5 = GUISetControl("button","shell32.dll|32",160,0,40,40,$BS_ICON)
$buttonclose = GUISetControl("button","shell32.dll|28",200,0,40,40,$BS_ICON)
$buttonok = GUISetControl("button","OK",90,80,70,20)
GUIShow()
GUIWaitClose()
GUIDelete()
Exit

would bring up (XP):

http://www.autoitscript.com/fileman/users/public/Holger/buttonswithicon.jpg

Maybe I find a way to load bitmap resources index pictures, you know, like in Explorer or Winzip,etc...

Edited by Holger

Share this post


Link to post
Share on other sites

Were can i find the buttons like that?

Would you mind to zip and post them here?


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

How did you get that to work?

I only get this and i'm using XP aswell.

Posted Image


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

Do you know if there is a register of all icons in winshell?

If so, were can i find it?


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

@Doxie: ohhh, I don't really know what you mean :) I'm a programming-beginner you know :huh2:

However, at the moment it would look like:

http://www.autoitscript.com/fileman/users/public/Holger/buttonscurrent.jpg

So cause I didn't know how to split the functions I changed the current "CreateButton" to that:

////////////////////////////////////////////////////////////////////////////////////////////////
//
// CreateBUTTON()
//
////////////////////////////////////////////////////////////////////////////////////////////////

HWND CGuiBox::CreateBUTTON(const char* Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)
{
    HWND  A;
    bool  bDefault = false;
    HICON  hIcon;
    char  szBuffer[_MAX_PATH+1];
    const char  *szDelim, *szToken;
    int     nTemp;
    HINSTANCE   hInstance=NULL;
    HBITMAP  hBitmap;

    if (Style == -1)
  Style = 0;

    Style = ResolveGroupStyle(Style | WS_TABSTOP | BS_PUSHBUTTON | BS_NOTIFY);

    // If the default button style is requested make a note of it and remove it (we will set it later).
    if (Style & BS_DEFPUSHBUTTON)
    {
  bDefault = true;
  Style ^= BS_DEFPUSHBUTTON;
    }

    if ( Exstyle==-1 )
  Exstyle=WS_EX_WINDOWEDGE;

    A = _CreateControl(Exstyle, "button", Text, Style, X, Y, W, H, hWnd, id, m_hInstance, NULL, true);

    if (Style & BS_ICON)
    {
  if ( (szDelim = strpbrk(Text, "|")) != NULL)
  {
    nTemp = (int)(szDelim-Text);
    strncpy(szBuffer, Text, nTemp);
    szBuffer[nTemp] = '\0';
    nTemp = atoi(szDelim+1);
    nTemp = nTemp - 1;
    if (nTemp==-1)
    nTemp = 0;
    szToken = szBuffer;

    hIcon=(HICON) ExtractIcon(hInstance,szToken,nTemp);
    SendMessage(A,(UINT)BM_SETIMAGE,(WPARAM)IMAGE_ICON,(LPARAM)hIcon);
  }
  else
  {
    hBitmap=(HBITMAP) LoadImage(0,Text,IMAGE_ICON,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    SendMessage(A,(UINT)BM_SETIMAGE,(WPARAM)IMAGE_ICON,(LPARAM)hBitmap);
  }
    }
    if (Style & BS_BITMAP)
    {
  hBitmap=(HBITMAP) LoadImage(0,Text,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  SendMessage(A,(UINT)BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBitmap);
    }

    // If the Default button style was specified then set it as the default button now that it
    // has been created
    if (bDefault)
  SendMessage(m_hWndGUI, DM_SETDEFID, id, 0);

    if (m_nGUIResizeMode == 0)
  GUICtrl[m_nMaxCtrl].nSizeable = GUI_SZ_DOCKWIDTH | GUI_SZ_DOCKHEIGHT;

    return A;

} // CreateBUTTON()

and that was the sample-au3 (don't forget that these pics and so on on my local hd).

$BS_ICON = 0x00000040
$BS_BITMAP = 0x00000080
GUICreate("test",240,180)
$button1 = GUISetControl("button","shell32.dll|5",0,0,40,40,$BS_ICON)
$button2 = GUISetControl("button","shell32.dll|7",40,00,40,40,$BS_ICON)
$button3 = GUISetControl("button","shell32.dll|22",80,00,40,40,$BS_ICON)
$button4 = GUISetControl("button","shell32.dll|23",120,0,40,40,$BS_ICON)
$button5 = GUISetControl("button","shell32.dll|32",160,0,40,40,$BS_ICON)
$buttonclose = GUISetControl("button","shell32.dll|28",200,0,40,40,$BS_ICON)
$buttonok = GUISetControl("button","OK",85,60,70,20)
$buttonani = GUISetControl("button",@ScriptDir & "\horse.ani",0,40,40,40,$BS_ICON)
$buttonpic = GUISetControl("button",@ScriptDir & "\setup.bmp",25,100,50,50,$BS_BITMAP + $BS_FLAT)
$buttonpic = GUISetControl("button",@ScriptDir & "\share.bmp",95,100,50,50,$BS_BITMAP + $BS_DEFPUSHBUTTON)
$buttonpic = GUISetControl("button",@ScriptDir & "\sync.bmp",165,100,50,50,$BS_BITMAP)
GUIShow()
GUIWaitClose()
GUIDelete()
Exit

Without any garanties :lol:

No...no problem, I tested it , but maybe there are errors or it could be easier to realize... :D

FORGET: the 'horse.ani' doesn't move (if you think about it) :)

Edited by Holger

Share this post


Link to post
Share on other sites

I have made some googling, and are now pretty sure this will not work at the moment.

In some way, you need to call the windows API, and the only way i found so far is by using delphi, C or VB. I don´t think AutoIt support that.

But i'm not that good with this, so i leave it to the pro´s :D


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@Doxie: Here's one way to view all the icons in shell32.dll on Windows 2000/XP without using a third-party program.

1) Pick some shortcut that's on your Desktop or start menu.

2) Right-click it, choose Properties, click the Change Icon button.

3) Press Delete, Enter.

4) You should see a bunch of icons in shell32.dll The icons are indexed starting top-to-bottom, left-to-right starting with index 0.

5) Click Cancel, Cancel when done viewing.

If anyone is looking for a really cool set of XP Icons, look here :D

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

For fun, here's a scripted version of the process in my previous post:

;View icons in DLL file without third-party appliction
;CyberSlug - 30 June 2004 - tested on Windows XP Pro sp1

Opt("WinTitleMatchMode", 4)   ;1=start, 2=subStr, 3=exact, 4=...
Opt("WinWaitDelay", 50)       ;50 milliseconds

FileCreateShortcut("","C:\tmpIconScript.lnk")
Run("explorer.exe /n,/select,C:\tmpIconScript.lnk")
WinWaitActive("classname=CabinetWClass")
Send("{AppsKey}r")
WinClose("classname=CabinetWClass")

WinWaitActive("tmpIconScript Properties")
ControlClick("tmpIconScript Properties","","&Change Icon...")
WinSetState("tmpIconScript Properties","", @SW_HIDE)

WinWaitActive("Change Icon")
WinSetTitle("Change Icon","","Icon Viewer")
ControlHide("Icon Viewer","","OK")

$pos = WinGetPos("Icon Viewer")
WinMove("Icon Viewer","", 100,100 ,400+$pos[2],$pos[3])

$pos = ControlGetPos("Icon Viewer","","ListBox1")
ControlMove("Icon Viewer","","ListBox1", $pos[0],$pos[1], 400+$pos[2],$pos[3])

ControlSend("Icon Viewer","","Edit1","{Delete}{Enter}")

#cs -- Anyone know how to get the item index instead of the item "text" ?
$sel = ""
While WinExists("Icon Viewer")
   sleep(100)
   If ControlCommand("Icon Viewer","", "ListBox1","GetCurrentSelection","") <> $sel Then
      $sel = ControlCommand("Icon Viewer","", "ListBox1","GetCurrentSelection","")
      WinSetTitle("Icon Viewer","","Icon Viewer:  " & $sel) 
   EndIf
WEnd
#ce

FileDelete("C:\tmpIconScript.lnk")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

so that is an add on then Holger? It looks like more C++ code. do we need to wait for it to be included by Jon? or is it something we should be using some GnuC++ compiler co complile into a command.. and if so where would it need to go? are there specific .h files and so on that we would need?

I thought we could already use images as buttons.. I've not tried it yet.. but it seems to me Larry suggested it to someone else a few weeks ago in annother thread..

moo

Share this post


Link to post
Share on other sites

@cowsmanaut: I can work it only at home, but sometimes I'm so late at home after work that I don't have time.

I will try to send the changes to Jon.

I have to change the html-files and make a change-text-file and so on.

Maybe I find the time today in the evening...we will see... cause I'm making that for fun and have a 'privat life' you know :huh2::D

Share this post


Link to post
Share on other sites

Maybe I find the time today in the evening...we will see... cause I'm making that for fun and have a 'privat life' you know  :lol:  :D

Tell me about it. My girlfriend has got me tied up pretty much every night at the moment :):huh2:

Share this post


Link to post
Share on other sites

tied up.. hmmm sounds kinky (heh.. sorry couldn't resist)

unless you are serious :D

moo

Share this post


Link to post
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
Sign in to follow this  
Followers 0