Jump to content

Skin UDF


Yashied
 Share

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
Link to comment
Share on other sites

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
Link to comment
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
Link to comment
Share on other sites

  • 6 months later...
  • 1 month later...
  • 2 months later...

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

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 11 months later...
  • 1 year later...
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

Link to comment
Share on other sites

  • 10 months later...

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

×
×
  • Create New...