power1power1 Posted January 26, 2014 Posted January 26, 2014 Hello, I am trying to write a piece of text in systray. Looking at various web pages across the internet, I came up with the following code to create a bitmap, write the text in that bitmap and set the bitmap as a systray icon. Here are my questions: - The code doesn't do it and I only get a black icon. Can you see what is missing? - It seems too many code lines for such a task. Maybe you guys have a better solution. #include <WinAPIGdi.au3> #include <FontConstants.au3> #include <WinAPIShellEx.au3> $Text = "100" $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmapEx($hDC, 32, 32, 0) $hBitmapMask = _WinAPI_CreateCompatibleBitmapEX($hDC, 32, 32, 0) $hOldBitmap = _WinAPI_SelectObject($hMemDC, $hBitmap) $hFont = _WinAPI_CreateFont(10, 0) ;$hOldFont = _WinAPI_SelectObject($hDC, $hFont) _WinAPI_SetTextColor($hOldBitmap, 0xFF0000) _WinAPI_TextOut( $hOldBitmap, 0, 0, $Text) $hIcon = _WinAPI_CreateIconIndirect($hBitmap, $hBitmapMask) $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA) DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA)) DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle())) DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON) DllStructSetData($tNOTIFYICONDATA, 'ID', 2) DllStructSetData($tNOTIFYICONDATA, 'hIcon', $hIcon) _WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA) sleep(3000) _WinAPI_DeleteObject($hFont) _WinAPI_DeleteObject($hBitmapMask) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) DllStructSetData($tNOTIFYICONDATA, 'ID', 2) _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
l3ill Posted January 26, 2014 Posted January 26, 2014 Try Toast '?do=embed' frameborder='0' data-embedContent>> My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
power1power1 Posted January 26, 2014 Author Posted January 26, 2014 Thanks for the reply. It seems "Toast.au3" creates a pop up window above systray. I am trying to write text in the systray, where the icons are ...
FrankwazHere Posted January 26, 2014 Posted January 26, 2014 I saw an application once that changed the system time in the tray to like... "Evning" or "Half Past 7" or just "Weekend"/ so i know its possible, I think it was in c++ I just dont know how they did it, sorry. http://www.softpedia.com/get/Desktop-Enhancements/Clocks-Time-Management/FuzzyClock.shtml ;Frank.
power1power1 Posted January 27, 2014 Author Posted January 27, 2014 (edited) Thanks Frank. Well, I made some progress: Now the script works and I have a timer (text in red, background in black) in the systray. Still, these are things to do, if someone could help: - I can't get the background color of the bitmap to be transparent and I can't set it to another color, say green. - The text is at top-left corner of the bitmap and I can't move the text to the middle of the bitmap. - The code really seems to be too big for such a purpose. expandcollapse popup#include <WindowsConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIShellEx.au3> OnAutoItExitRegister("_OnAutoItExit") $Text = 0 While 1 _CreateSmallIcon($Text) Sleep(1000) $Text += 1 WEnd Func _CreateSmallIcon($Text) $hDC = _WinAPI_GetDC(0) $hDCMem = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmapEx($hDC, 32, 32, 0) $hBitmapMask = _WinAPI_CreateCompatibleBitmapEx($hDC, 32, 32, 0) _WinAPI_ReleaseDC(0, $hDC) $hOldBitmap = _WinAPI_SelectObject($hDCMem, $hBitmap) ;_WinAPI_PatBlt($hDCMem, 0, 0, 32, 32, $WHITENESS) _WinAPI_PatBlt($hDCMem, 0, 0, 32, 32, $BLACKNESS) $hFont = _WinAPI_CreateFont(22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial") $hFont = _WinAPI_SelectObject($hDCMem, $hFont) _WinAPI_SetTextColor($hDCMem, 0x0000FF) ;_WinAPI_SetBkColor($hDCMem, 0x00FF00) _WinAPI_SetBkMode($hDCMem, $TRANSPARENT) _WinAPI_TextOut($hDCMem, 0, 0, $Text) _WinAPI_SelectObject($hDC, $hOldBitmap) $hOldBitmap = 0 $hIcon = _WinAPI_CreateIconIndirect($hBitmap, $hBitmapMask) _WinAPI_DeleteObject(_WinAPI_SelectObject($hDCMem, $hFont)) _WinAPI_DeleteDC($hDCMem) _WinAPI_DeleteDC($hDC) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBitmapMask) Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA) DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA)) DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle())) DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON) DllStructSetData($tNOTIFYICONDATA, 'ID', 1) DllStructSetData($tNOTIFYICONDATA, 'hIcon', $hIcon) _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNOTIFYICONDATA) EndFunc Func _OnAutoItExit() DllStructSetData($tNOTIFYICONDATA, 'ID', 1) _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA) EndFunc Edited January 27, 2014 by power1power1
Solution power1power1 Posted January 27, 2014 Author Solution Posted January 27, 2014 (edited) I have an updated code ... It works now ... May be there is a more efficient way of doing this. expandcollapse popup#include <WinAPIGdi.au3> #include <WinAPIShellEx.au3> #include <WindowsConstants.au3> OnAutoItExitRegister("_RemoveSysTrayIcon") $Text = 0 $TextColor = 0x0000FF $BackColor = 0x00FF00 While 1 _CreateSysTrayIcon($Text, $TextColor, $BackColor) Sleep(1000) $Text += 1 WEnd Func _CreateSysTrayIcon($Text, $TextColor, $BackColor) $hDC = _WinAPI_GetDC(0) $hDCMem = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, 32, 32) _WinAPI_ReleaseDC(0, $hDC) $hOldBitmap = _WinAPI_SelectObject($hDCMem, $hBitmap) _WinAPI_PatBlt($hDCMem, 0, 0, 32, 32, $PATCOPY) $hFont = _WinAPI_CreateFont(32, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calibri") $hFont = _WinAPI_SelectObject($hDCMem, $hFont) _WinAPI_DeleteObject($hFont) _WinAPI_SetTextColor($hDCMem, $TextColor) _WinAPI_SetBkColor($hDCMem, $BackColor) _WinAPI_SetBkMode($hDCMem, $TRANSPARENT) _WinAPI_TextOut($hDCMem, 0, 0, $Text) $hBitmapMask = _WinAPI_SelectObject($hDCMem, $hOldBitmap) _WinAPI_DeleteDC($hDCMem) _WinAPI_DeleteObject($hOldBitmap) $hIcon = _WinAPI_CreateIconIndirect($hBitmap, $hBitmapMask) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBitmapMask) Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA) DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA)) DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle())) DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON) DllStructSetData($tNOTIFYICONDATA, 'ID', 1) DllStructSetData($tNOTIFYICONDATA, 'hIcon', $hIcon) _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNOTIFYICONDATA) EndFunc Func _RemoveSysTrayIcon() DllStructSetData($tNOTIFYICONDATA, 'ID', 1) _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA) EndFunc Edited January 28, 2014 by power1power1
richie1985 Posted February 4, 2014 Posted February 4, 2014 hi, i get this error: C:Program Files (x86)AutoIt3IncludeWinAPIGdi.au3 (25) : ==> Variable used without being declared.: Global Const $tagDIBSECTION = $tagBITMAP & ';' & $tagBITMAPINFOHEADER & ';dword dsBitfields[3];ptr dshSection;dword dsOffset' Global Const $tagDIBSECTION = $tagBITMAP & ';' & ^ ERROR What could be the reason? Thx!
power1power1 Posted February 16, 2014 Author Posted February 16, 2014 Well, I am not that expert in these stuff ... May be using the latest version of Autoit is needed.
guinness Posted February 16, 2014 Posted February 16, 2014 hi, i get this error: C:Program Files (x86)AutoIt3IncludeWinAPIGdi.au3 (25) : ==> Variable used without being declared.:Global Const $tagDIBSECTION = $tagBITMAP & ';' & $tagBITMAPINFOHEADER & ';dword dsBitfields[3];ptr dshSection;dword dsOffset'Global Const $tagDIBSECTION = $tagBITMAP & ';' & ^ ERROR What could be the reason? Thx!The message is pretty clear or don't you understand English? You're using an older version of AutoIt. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
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