Sign in to follow this  
Followers 0
JackDinn

GUICtrlCreateIcon background

5 posts in this topic

#1 ·  Posted (edited)

I know there are lots of posts involving this subject but is there a simple way to make the background of an icon transparent without having to add masses of code ?

im looking to put a .ico onto a coloured GUI with GUICtrlCreateIcon() but i dont want the white square with icon in middle.

sorry for not finding the info but iv been searching and reading for ages now and its all getting a bit complicated.

cheers.

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites



#Include <Icons.au3>
#Include <WinAPIEx.au3>

GUICreate('MyGUI', 350, 250)
$Pic1 = GUICtrlCreatePic('', 0, 0, 350, 250)
$hPic1 = GUICtrlGetHandle($Pic1)
$Pic2 = GUICtrlCreatePic('', 40, 40, 48, 48)
$hPic2 = GUICtrlGetHandle(-1)
GUISetState()

Dim $aVertex[2][3] = [[0, 0, 0x0000FF], [350, 250, 0x000000]]

; Set Gradient
$hDC = _WinAPI_GetDC($hPic1)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, 350, 250)
_WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_GradientFill($hMemDC, $aVertex, 0, -1, 1)
_WinAPI_ReleaseDC($hPic1, $hDC)
_WinAPI_DeleteDC($hMemDC)
_SetHImage($Pic1, $hBitmap)
_WinAPI_FreeObject($hBitmap)

; Set Icon
$hDC = _WinAPI_GetDC($hPic2)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, 48, 48)
_WinAPI_SelectObject($hMemDC, $hBitmap)
$hIcon = _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 130, 48, 48)
_WinAPI_DrawIconEx($hMemDC, 0, 0, $hIcon, 48, 48, 0, 0, 2)
_WinAPI_ReleaseDC($hPic2, $hDC)
_WinAPI_DeleteDC($hMemDC)
_SetHImage($Pic2, $hBitmap)
_WinAPI_FreeObject($hBitmap)
_WinAPI_FreeIcon($hIcon)

Do
Until GUIGetMsg() = -3

GUIDelete()

Icons.au3

WinAPIEx.au3

Share this post


Link to post
Share on other sites

ok many thx, not quite the "simple" method i was hoping for but still i do appreciate the help.

It works fine, i just need to spend a bit of time understanding how it works and what all the added UDF's are about included with you WinAPIEx.au3, ( I dont like just using script iv been given without a proper understanding, which is the least i can do when someone has done so much work to produce.)

looks like autoit is moving more and more towards VB ! having to read the MSDN library more and more, but it's all good.

many thx.


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

great stuff :). iv pulled it about a bit to get a function that i can easily use. I will be able to do all sorts of neat stuff now.

#include <Icons.au3>
#include <WinAPIEx.au3>

$GUIH = GUICreate('MyGUI', 350, 250)
GUISetBkColor(0xf453f5)
GUISetState()

;~ $icon1 = iconx($GUIH, "C:\Documents and Settings\Greg\desktop\JDAST pack\1256250803_Arrow Down.ico", 0, 10, 10, 40, 40);### for .ICO files
$icon1 = iconx($GUIH, @SystemDir & "\shell32.dll", 176, 70,100); for icon packs eg .DLL
$icon2 = iconx($GUIH, @SystemDir & "\shell32.dll", 11, 100,100); for icon packs eg .DLL


;#############  just some fun, but i can really play with this #########
Sleep(1000)
For $y = 0 To 5
    for $x=10 to 40
    GUICtrlSetPos($icon1, $x, 100)
    Sleep(1)
    Next
Next
GUICtrlSetPos($icon2, 100, 100)
For $x = 50 To 100
    GUICtrlDelete($icon2)
    $icon2 = iconx($GUIH, @SystemDir & "\shell32.dll", 11, 100, 100, $x, $x)
    Sleep(10)
Next
;######################################################################


Do
Until GUIGetMsg() = -3
GUIDelete()
Exit

; Set Icon
Func iconX($gui_handel, $icon_path, $icon_number = 0, $icon_x = 0, $icon_y = 0, $icon_width = 48, $icon_hight = 48)
    GUISwitch($gui_handel)
    $Pic2 = GUICtrlCreatePic('', $icon_x, $icon_y, $icon_width, $icon_hight)
    $pic_handel = GUICtrlGetHandle(-1)
    $hDC = _WinAPI_GetDC($pic_handel)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $icon_width, $icon_hight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    $hIcon = _WinAPI_ShellExtractIcons($icon_path, $icon_number, 48, 48)
    _WinAPI_DrawIconEx($hMemDC, 0, 0, $hIcon, $icon_width, $icon_hight, 0, 0, 2)
    _WinAPI_ReleaseDC($pic_handel, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetHImage($pic_handel, $hBitmap)
    _WinAPI_FreeObject($hBitmap)
    _WinAPI_FreeIcon($hIcon)
    Return $Pic2
EndFunc   ;==>iconX

again many thx.


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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