Jump to content

Recommended Posts

LAST VERSION - 0.2

03-Jan-15

Skin UDF allows you to create buttons from the predefined images (files, resources, etc.). I rewrote this library by using GDI+ (first version used GDI). This allowed add the many additional features and get rid of the problems related to the transparency. Nevertheless, the library has a beta status, so there is no detailed description of the functions. But I am sure that the example below gives complete information about the features of this library. I hope that many users will find it useful. If you will have any questions, please ask them in this thread.
 

Skin.png


Available functions

_Skin_AddButton
_Skin_AddButtonEx
_Skin_DeleteButton
_Skin_Destroy
_Skin_DisableButton
_Skin_EnableFocus
_Skin_EnableKBInput
_Skin_Helper
_Skin_SetButton
_Skin_SetButtonEx
_Skin_SetFocusRect

Skin Library v1.0

Skin.zip


Example

#Include <GUIConstantsEx.au3>
#Include <Skin.au3>

Global $Button[3]

$hForm = GUICreate('MyGUI', 278, 106)

GUICtrlCreatePic('background.bmp', 0, 0, 278, 106)
GUICtrlSetState(-1, $GUI_DISABLE)

; Create buttons from PNG images (images should be located in the same folder as the script)
$Button[0] = _Skin_AddButton(20 , 20, 66, 66, 'red_normal.png', 'red_hover.png', 'red_click.png', 'disable.png', 'alpha.png', 1)
$Button[1] = _Skin_AddButton(106, 20, 66, 66, 'yellow_normal.png', 'yellow_hover.png', 'yellow_click.png', 'disable.png', 'alpha.png', 1)
$Button[2] = _Skin_AddButton(192, 20, 66, 66, 'green_normal.png', 'green_hover.png', 'green_click.png', 'disable.png', 'alpha.png', 1)

#cs

; Create buttons from GDI+ HBITMAP handles
$Button[0] = _Skin_AddButtonEx(20 , 20, 64, 64, _GDIPlus_BitmapCreateFromFile('red_normal.png'), ..., 1, 1)
$Button[1] = _Skin_AddButtonEx(104, 20, 64, 64, _GDIPlus_BitmapCreateFromFile('yellow_normal.png'), ..., 1, 1)
$Button[2] = _Skin_AddButtonEx(188, 20, 64, 64, _GDIPlus_BitmapCreateFromFile('green_normal.png'), ..., 1, 1)

#ce

; Disable "Yellow" button (Optional)
_Skin_DisableButton($Button[1], 1)

; Enable keyboard input (Optional)
_Skin_EnableKBInput(1)

; Set margins for dotted focus rectangle (Optional)
For $i = 0 To 2
    _Skin_SetFocusRect($Button[$i], 5, 5, 56, 56)
Next

; Enable dotted focus rectangle (Optional)
_Skin_EnableFocus(1)

GUISetState()

; _Skin_Helper() must be called continuously in the main loop
While 1
    _Skin_Helper($hForm)
    $ID = GUIGetMsg()
    Switch $ID
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button[0]
            ConsoleWrite('Red' & @CR)
        Case $Button[1]
            ConsoleWrite('Yellow' & @CR)
        Case $Button[2]
            ConsoleWrite('Green' & @CR)
        Case Else

    EndSwitch
WEnd

; You must delete all created buttons before destroying the appropriate window
;~For $i = 0 To 2
;~  _Skin_DeleteButton($Button[$i])
;~Next
Edited by Yashied

Share this post


Link to post
Share on other sites
Guest

Thank you!
This is exactly what I was looking for.

Excellent project
You came just at the right time in perfect accuracy :)

Edit:

I need it to work with embedded images with Resources UDF

I would love if you add such support

Edit2:

My request is valid if you did not added such support ..
I'll check the UDF in more detail later..

Edited by Guest

Share this post


Link to post
Share on other sites

I need it to work with embedded images with Resources UDF

All you need is a _Skin_AddButtonEx() function. Here's an example:

#Region Resources
#AutoIt3Wrapper_Res_File_Add=background.bmp, 2, 200
#AutoIt3Wrapper_Res_File_Add=red_normal.png, PNG, RED_NORMAL
#AutoIt3Wrapper_Res_File_Add=red_hover.png, PNG, RED_HOVER
#AutoIt3Wrapper_Res_File_Add=red_click.png, PNG, RED_CLICK
#AutoIt3Wrapper_Res_File_Add=yellow_normal.png, PNG, YELLOW_NORMAL
#AutoIt3Wrapper_Res_File_Add=yellow_hover.png, PNG, YELLOW_HOVER
#AutoIt3Wrapper_Res_File_Add=yellow_click.png, PNG, YELLOW_CLICK
#AutoIt3Wrapper_Res_File_Add=green_normal.png, PNG, GREEN_NORMAL
#AutoIt3Wrapper_Res_File_Add=green_hover.png, PNG, GREEN_HOVER
#AutoIt3Wrapper_Res_File_Add=green_click.png, PNG, GREEN_CLICK
#AutoIt3Wrapper_Res_File_Add=alpha.png, PNG, ALPHA
#EndRegion Resources

#Include <GDIPlus.au3>
#Include <GUIConstantsEx.au3>
#Include <Memory.au3>
#Include <Skin.au3>
#Include <WinAPIEx.au3>

Global $hInstance = _WinAPI_GetModuleHandle('')
Global $hBitmap[10] = ['RED_NORMAL', 'RED_HOVER', 'RED_CLICK', 'YELLOW_NORMAL', 'YELLOW_HOVER', 'YELLOW_CLICK', 'GREEN_NORMAL', 'GREEN_HOVER', 'GREEN_CLICK', 'ALPHA']
Global $Button[3]

_GDIPlus_Startup()
For $i = 0 To 9
    $hBitmap[$i] = _LoadResourceImage($hInstance, 'PNG', $hBitmap[$i])
Next
_GDIPlus_Shutdown()

$hForm = GUICreate('MyGUI', 278, 106)
GUICtrlCreatePic('', 0, 0, 278, 106)
GUICtrlSendMsg(-1, 0x0172, 0, _WinAPI_LoadBitmap($hInstance, 200))
GUICtrlSetState(-1, $GUI_DISABLE)
$Button[0] = _Skin_AddButtonEx(20 , 20, 66, 66, $hBitmap[0], $hBitmap[1], $hBitmap[2], 0, $hBitmap[9], 1)
$Button[1] = _Skin_AddButtonEx(106, 20, 66, 66, $hBitmap[3], $hBitmap[4], $hBitmap[5], 0, $hBitmap[9], 1)
$Button[2] = _Skin_AddButtonEx(192, 20, 66, 66, $hBitmap[6], $hBitmap[7], $hBitmap[8], 0, $hBitmap[9], 1)
_Skin_EnableKBInput(1)
For $i = 0 To 2
    _Skin_SetFocusRect($Button[$i], 5, 5, 56, 56)
Next
_Skin_EnableFocus(1)
GUISetState()

While 1
    _Skin_Helper($hForm)
    $ID = GUIGetMsg()
    Switch $ID
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button[0]
            ConsoleWrite('Red' & @CR)
        Case $Button[1]
            ConsoleWrite('Yellow' & @CR)
        Case $Button[2]
            ConsoleWrite('Green' & @CR)
        Case Else

    EndSwitch
WEnd

Func _LoadResourceImage($hInstance, $sType, $sName, $iLanguage = 0)

    Local $hInfo, $hData, $pData, $iSize, $hMem, $pMem, $pStream, $hBitmap

    If Not $hInstance Then
        $hInstance = _WinAPI_GetModuleHandle('')
    EndIf
    If $iLanguage Then
        $hInfo = _WinAPI_FindResourceEx($hInstance, $sType, $sName, $iLanguage)
    Else
        $hInfo = _WinAPI_FindResource($hInstance, $sType, $sName)
    EndIf
    $hData = _WinAPI_LoadResource($hInstance, $hInfo)
    $iSize = _WinAPI_SizeOfResource($hInstance, $hInfo)
    $pData = _WinAPI_LockResource($hData)
    If @Error Then
        Return SetError(1, 0, 0)
    EndIf
    $hMem = _MemGlobalAlloc($iSize, $GMEM_MOVEABLE)
    $pMem = _MemGlobalLock($hMem)
    _WinAPI_MoveMemory($pMem, $pData, $iSize)
    _MemGlobalUnlock($hMem)
    $pStream = _WinAPI_CreateStreamOnHGlobal($hMem)
    _GDIPlus_Startup()
    $hBitmap = _GDIPlus_BitmapCreateFromStream($pStream)
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseStream($pStream)
    If Not $hBitmap Then
        Return SetError(2, 0, 0)
    EndIf
    Return $hBitmap
EndFunc   ;==>_LoadResourceImage

#cs

Func _GDIPlus_BitmapCreateFromStream($pStream)

    Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromStream', 'ptr', $pStream, 'handle*', 0)

    If (@Error) Or ($Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

#ce

Share this post


Link to post
Share on other sites

I will dare to answer my own question :)

There is an UDF developed for this

Just add to includes

#include "NoFocusLines.au3"
#include <ButtonConstants.au3>

; And declare in Globals

$fGlobal = True ; this will switch off all spots and lines for all controls

Already tested in WIN 8

Share this post


Link to post
Share on other sites

Thank you for this great UDF

There is a tiny select-like area around the image with button. Is it possible to remove it?

 

All you need to do is comment-out line 37 of Skin_Ex.au3.

Line 36 explains it.

Share this post


Link to post
Share on other sites

Unless I'm missing something... does this no longer work with the current AutoIt? It skins everything correctly but it doesn't seem to allow the buttons to be clicked. It flashes as if you clicked it but the Switch never works. Nothing is written to the Console.

 

Thanks!


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites
On 11/6/2016 at 1:08 PM, incepator said:

In new version of autoit..is not working this script.

What's not working, and what is it doing or not doing that is wrong?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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

  • Similar Content

    • By GillesMaisonneuve
      Good morning,
       
      I am trying to align a two-line text in a button so that it would be centered in the button but can't succeed to do it for the vertical part.
      Can someone tell me what I do wrong ?
      Here is my code:
      $btn3 = GUICtrlCreateButton("Execute " & @LF & " file 1", 100, 65, 60, 50, _ BitOr($BS_CENTER,$BS_BOTTOM,$BS_MULTILINE)) and here is the resulting layout I get in my window.
      I tried to follow the help, made a lot of different parameter combinations (here it's `$BS_BOTTOM`, but I tried `$BS_VCENTER` and `$BS_TOP`), still get the same result : vertical alignement is a no go for me.
      Can someone help ?
      TIA
      Gilles

    • By Pike
      Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG!
      To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1"
              Case 1                                                                                                                                             
                  Local $sRead = IniRead("config.ini", "Config", "One", "Default")                                
                  SoundPlay($sRead, @HotKeyPressed)                                                                     <-------------------------------
                  Run($sRead, @HotKeyPressed)                                                                                 <------------------------------- This 'Run' doesn't work even by itself!
      See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated.
       
      Much Respect,
      Pike
       
      Func _HandleButton() $iClickCount += 1 $iTimer = TimerInit() AdlibRegister("CheckButtonPress", $CheckTime) EndFunc Func CheckButtonPress() If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return Switch $iClickCount Case 1 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local $sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $sFileName) EndSwitch $iClickCount = 0 AdlibUnRegister() EndFunc  

    • By misioooo
      Hi!
       
      I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file).
      Part with button looks like this:
      $ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff) $hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1, $hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here?
    • By XinYoung
      Quick question: How can I click this "Select All" button in IE? There's no ID, and the href is "#"  
      Am I looking at the wrong html code?
      Am I looking
      Thank you all in advance!
    • By XinYoung
      Hello again 
      I need to click this Submit button, but it's in a lightbox and has no ID (i think) and I can't figure out a way to target it. _IEFormSubmit doesn't work.

       
      Thank you
×
×
  • Create New...