Jump to content
Yashied

Skin UDF

Recommended Posts

Yashied

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
  • Like 2

Share this post


Link to post
Share on other sites
gil900

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 gil900

Share this post


Link to post
Share on other sites
Yashied

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
  • Like 1

Share this post


Link to post
Share on other sites
topten

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
Kira16651

Awesome work, thanks man :D that is just what I needed.

Edited by Kira16651

Share this post


Link to post
Share on other sites
lorenkinzel

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
Damein

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
Yashied
incepator

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

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

    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • thoms
      By thoms
      Hello Forum,
      As said in the title, I'm searching a way to disable all tabstops in a GUI. My GUI includes 15 buttons and 3 edit controls.
      My questions:
      - is there a way to disable all tabstops at a time
      - is there a way to list all controls of a GUI and then disable tabstops one by one
      - or should I use the following line after each button creation:
      _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) Thanks in advance for your valuable help!
      Thoms
      Edit: or maybe disable TAB key? I don't remember how to do!
    • AppSoftwareVld
      By AppSoftwareVld
      Hello,
       
      I need this for a project and I don't find a method for the next problem.
      I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
       
      Do you have an idea ? 
      Thank you for your attention !
×