kosamja Posted May 26, 2019 Share Posted May 26, 2019 (edited) Bitmap351.bmp What function can be used to get icons from this bmp file? Edited May 26, 2019 by kosamja Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2019 Developers Share Posted May 26, 2019 1 hour ago, kosamja said: What function can be used to get icons from this bmp file? Define "Get". Do you mean to display them in a GUI? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kosamja Posted May 26, 2019 Author Share Posted May 26, 2019 i mean to get icon handle or something that can be used with TraySetIcon Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2019 Developers Share Posted May 26, 2019 Ok, so what have you tried that isn't working? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kosamja Posted May 26, 2019 Author Share Posted May 26, 2019 Tried to ask for help here . Since obviously this dont work and i dont know what else to try i dont see what were other options: TraySetState($TRAY_ICONSTATE_SHOW) For $i = 1 to 100 Sleep(500) TraySetIcon(@ScriptDir & "\Bitmap351.bmp", $i) Next Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2019 Developers Share Posted May 26, 2019 Is this an proper ICO file or just a bunch of icons combined into one image? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kosamja Posted May 26, 2019 Author Share Posted May 26, 2019 bunch of icons combined into 1 image, extracted from batmeter.dll Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2019 Developers Share Posted May 26, 2019 So, why do you think it will work then as it is simply one single image? YOu obviously need to have a properly formatted file for this to work as there is no miracle parameter available. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Subz Posted May 26, 2019 Share Posted May 26, 2019 Use an icon tool (I use IcoFx 1.6 this version is free) and create multiple .ico files, then follow the link below which shows you how to add the icons to your compiled exe and then display them in the system tray: https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/adding-extra-icons-to-the-program-resources.html Link to comment Share on other sites More sharing options...
Gianni Posted May 27, 2019 Share Posted May 27, 2019 such kind of images (strips) can also be handled by the _GUIImageList* functions. Have a look to this link for an example of use https://www.autoitscript.com/forum/topic/165083-question-on-_guiimagelist-usage/. In your case posted here, since you want to use it with the TraySetIcon() function, and since that function accepts a filename as parameter, you should convert the frames of the strip at least in single icons, and save them to disk, or, by the workaround from this post (https://www.autoitscript.com/forum/topic/97902-trayseticon-with-handle/) you can manage it by the image handle. here a quick and dirty example: expandcollapse popup#include <GuiImageList.au3> #include <WinAPI.au3> #include <GDIPlus.au3> ; ---------------------- ; https://www.autoitscript.com/forum/topic/97902-trayseticon-with-handle/ Global Const $tagNOTIFYICONDATAW = _ 'dword cbSize;' & _ 'hwnd hWnd;' & _ 'uint uID;' & _ 'uint uFlags;' & _ 'uint uCallbackMessage;' & _ 'hwnd hIcon;' & _ 'wchar szTip[128];' & _ 'dword dwState;' & _ 'dword dwStateMask;' & _ 'wchar szInfo[256];' & _ 'uint uVersion;' & _ 'wchar szInfoTitle[64];' & _ 'dword dwInfoFlags;' ; & $tagGUID Global $tNID = DllStructCreate($tagNOTIFYICONDATAW), $pNID = DllStructGetPtr($tNID) Global $hWnd = WinGetHandle(AutoItWinGetTitle()), $hIcon ; ---------------------- Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "Quit") Example() Func Example() _GDIPlus_Startup() ; Load Image Local $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & ".\Bitmap351.bmp") Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ; convert GDIPlus bitmap to GDI format which is usable for _GUIImageList* functions ; there are 31 images (frames) in strip Local $iFramesInStrip = 31 Local $iFrameWidth = _GDIPlus_ImageGetWidth($hBitmap) / $iFramesInStrip Local $iFrameHeight = _GDIPlus_ImageGetHeight($hBitmap) _GDIPlus_BitmapDispose($hBitmap) ; release GDIPlus bitmap because not needed anymore $hImages = _GUIImageList_Create($iFrameWidth, $iFrameHeight, 5) ; create image list in 32-bit which supports transparency _GUIImageList_Add($hImages, $hGDIBitmap) ; add the whole strip to the ImageList ; Create a little GUI $hGUI = GUICreate("Demo", 150, 80) GUICtrlCreateLabel("see the tray icon...", 10, 10, 140) GUICtrlSetFont(-1, 12) GUICtrlCreateButton("Quit", 40, 40, 80) GUICtrlSetOnEvent(-1, "Quit") GUISetState(@SW_SHOW) Do For $i = 0 To $iFramesInStrip - 1 ; loop all frames $hIcon = _GUIImageList_GetIcon($hImages, $i) DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID)) DllStructSetData($tNID, 'hWnd', $hWnd) ;HWnd($hGUI)) ; DllStructSetData($tNID, 'uID', 1) DllStructSetData($tNID, 'uFlags', 2) DllStructSetData($tNID, 'hIcon', $hIcon) _Shell_NotifyIcon(1, $pNID) ; TraySetIcon() Sleep(250) Next Until False EndFunc ;==>Example Func Quit() ; free memory _GDIPlus_Shutdown() _WinAPI_DestroyIcon($hIcon) GUIDelete() Exit EndFunc ;==>Quit Func _Shell_NotifyIcon($iMessage, $pdata) Local $aRet $aRet = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', $pdata) If @error Then Return SetError(1, 0, 0) Return $aRet[0] EndFunc ;==>_Shell_NotifyIcon kosamja 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
kosamja Posted May 27, 2019 Author Share Posted May 27, 2019 (edited) Perfect. thanks. Just 1 more question, is it possible to make background color of images transparent instead of black with _GUIImageList_SetBkColor or something else? Edited July 28, 2019 by kosamja Link to comment Share on other sites More sharing options...
Gianni Posted May 28, 2019 Share Posted May 28, 2019 To use transparency, the image must already contain transparent areas, if it does not contain them, it must be modified with a program that can manage transparency and choose the areas that must be transparent * . In short, transparency must already be present in the image. If you don't have or don't want to install a proper editing program, you can simply use an online image editor. A quick and simple example: open this site: http://www.online-image-editor.com/ upload the image to be modified; browse button and upload button (to keep the BMP format check "Convert during upload" and select BMP even if the image is already BMP otherwise it will be saved in PNG) select the "wizads" tab choose the "transparency" icon (the diamond) Click on the background of the image to make it transparent. save the modified image and use it in the script instead of the previous one. have fun kosamja and Exit 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
RTFC Posted May 28, 2019 Share Posted May 28, 2019 (edited) 7 hours ago, Chimp said: transparency must already be present in the image. This might be a bit confusing. Images are commonly stored in several layers, for the colors (for example, Red/Green/Blue) and may additionally contain an alpha layer that enodes transparency, from 0 for totally transparent, to 255 for completely opaque. If an image is stored as RGB, an extra alpha layer can be added to make it RGBA, for example. Free image processing software such as GIMP will show these layers in a panel (on right), allowing you to edit them individually, add/remove/show/hide them, etc. In your case, you would select by color (the black background), mask->add layer mask (pick "selection"), export to a new file, done. Alternatively, you can use Layer->Color to Alpha, allowing you to fiddle more with threshold values for opaqueness. Edited May 28, 2019 by RTFC My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
UEZ Posted May 28, 2019 Share Posted May 28, 2019 (edited) I modified @Chimp's example. expandcollapse popup#include <GuiImageList.au3> #include <WinAPI.au3> #include <GDIPlus.au3> ; ---------------------- ; https://www.autoitscript.com/forum/topic/97902-trayseticon-with-handle/ Global Const $tagNOTIFYICONDATAW = _ 'dword cbSize;' & _ 'hwnd hWnd;' & _ 'uint uID;' & _ 'uint uFlags;' & _ 'uint uCallbackMessage;' & _ 'hwnd hIcon;' & _ 'wchar szTip[128];' & _ 'dword dwState;' & _ 'dword dwStateMask;' & _ 'wchar szInfo[256];' & _ 'uint uVersion;' & _ 'wchar szInfoTitle[64];' & _ 'dword dwInfoFlags;' ; & $tagGUID Global $tNID = DllStructCreate($tagNOTIFYICONDATAW), $pNID = DllStructGetPtr($tNID) Global $hWnd = WinGetHandle(AutoItWinGetTitle()), $hIcon DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID)) DllStructSetData($tNID, 'hWnd', $hWnd) ;HWnd($hGUI)) ; DllStructSetData($tNID, 'uID', 1) DllStructSetData($tNID, 'uFlags', 3) ; ---------------------- Global $hBmp_Anim, $hGfx, $hFrames Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "Quit") Example() Func Example() _GDIPlus_Startup() ; Load Image Local $hBitmap_l = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\Bitmap351.png") Local $iW = _GDIPlus_ImageGetWidth($hBitmap_l), $iH = _GDIPlus_ImageGetHeight($hBitmap_l) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;convert black to transparent color - not really needed here as there are not much opaque background pixels visible Local $aRemapTable[2][2] $aRemapTable[0][0] = 1 $aRemapTable[1][0] = 0xFF000000 ;black $aRemapTable[1][1] = 0 ;transparent Local $hIA = _GDIPlus_ImageAttributesCreate() _GDIPlus_ImageAttributesSetRemapTable($hIA, $aRemapTable) _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hBitmap_l, 0, 0, $iW, $iH, 0, 0, $iW, $iH, $hIA) _GDIPlus_ImageDispose($hBitmap_l) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageAttributesDispose($hIA) ; there are 31 images (frames) in strip Local $iFramesInStrip = 31 Local $iFrameWidth = 18 Local $iFrameHeight = 32 $hFrames = _GDIPlus_BitmapCreateFromScan0($iFrameWidth * $iFramesInStrip, $iFrameHeight) $hGfx = _GDIPlus_ImageGetGraphicsContext($hFrames) Local $sx = 0, $dx = 0 For $i = 1 To $iFramesInStrip - 3 _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hBitmap, 20 + $sx, 22, $iFrameWidth, $iFrameHeight, $dx, 0, $iFrameWidth, $iFrameHeight) $sx += 32 $dx += $iFrameWidth Next ;the last 3 images have a different offset $sx -= 8 For $i = $iFramesInStrip - 2 To $iFramesInStrip _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hBitmap, 20 + $sx, 22, $iFrameWidth, $iFrameHeight, $dx, 0, $iFrameWidth, $iFrameHeight) $sx += 32 $dx += $iFrameWidth Next _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) ; release GDIPlus bitmap because not needed anymore ;_GDIPlus_ImageSaveToFile($hFrames, @ScriptDir & "\TestStripe.png") $hBmp_Anim = _GDIPlus_BitmapCreateFromScan0(16, 16) $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp_Anim) ; Create a little GUI $hGUI = GUICreate("Demo", 150, 80) GUICtrlCreateLabel("see the tray icon...", 10, 10, 140) GUICtrlSetFont(-1, 12) GUICtrlCreateButton("Quit", 40, 40, 80) GUICtrlSetOnEvent(-1, "Quit") GUISetState(@SW_SHOW) $sx = 0 Do For $i = 1 To $iFramesInStrip ; loop all frames _GDIPlus_GraphicsClear($hGfx, 0) _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hFrames, $sx, 0, $iFrameWidth, $iFrameHeight, 2, 0, 12, 16) $sx += $iFrameWidth If $sx > $iFrameWidth * ($iFramesInStrip - 1) Then $sx = 0 $hIcon = _GDIPlus_HICONCreateFromBitmap($hBmp_Anim) DllStructSetData($tNID, 'hIcon', $hIcon) _Shell_NotifyIcon(1, $pNID) ; TraySetIcon() _WinAPI_DestroyIcon($hIcon) Sleep(250) Next Until False EndFunc ;==>Example Func Quit() ; free memory _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBmp_Anim) _GDIPlus_BitmapDispose($hFrames) _GDIPlus_Shutdown() _WinAPI_DestroyIcon($hIcon) GUIDelete() Exit EndFunc ;==>Quit Func _Shell_NotifyIcon($iMessage, $pdata) Local $aRet $aRet = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', $pdata) If @error Then Return SetError(1, 0, 0) Return $aRet[0] EndFunc ;==>_Shell_NotifyIcon The attached image above is in PNG format, anyhow if you have it in BMP format then you should modify the line 40 accordingly, which should also work. Uncomment line 80 to save new created bitmap. Edited May 28, 2019 by UEZ Gianni and kosamja 2 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now