Leaderboard
Popular Content
Showing content with the highest reputation on 12/20/2011 in all areas
-
Greetings KaFu You can get most* of the icons from the notification area using shared memory code. The traydata struct in the TBBUTTON/TBBUTTONINFO structs Param element has a handle to the toolbar button icon. The traydata struct is undocumented but works in XP, Vista and Win 7 x86/x64 I use this in my _RefreshNotificationAreaIcons and _RefreshTrayIcon() UDFs The SysTray UDF only retrieves the owner window handle from the traydata struct. Get and use Imagelist From Another Process http://www.xtremevbtalk.com/showthread.php?t=128730 I ran the above struct code, and it does return some systray (XP) imagelist info (image count, icon size, etc.). The bitmap and memdc handles as mentioned are not accessible outside of the explorer process. The imagelist struct is different from the standard imagelist, _GUICtrlToolbar_GetImageList returns a handle, but ImageList_GetImageCount() returns 0. *As pointed out in that vb forum, some apps that frequently update their icons (temp, cpu use, etc.) will update the icon image in the notification areas imagelist with Shell_NotifyIcon + NIM_MODIFY, then destroy the icon handle, so the notification area imagelist has the current icon, but the handle in the traydata struct is not valid. Taskmgr replacements Process Explorer and Process Hacker 2 have process history tray icons that return invalid icon handles. I wrote some tray icon retrieval code a few years back, here's an updated example. For XP/2003,Vista/2008,Win7/2008R2 x86/x64 ;coded by rover 2k11 #NoTrayIcon #Include <WinAPIEx.au3> #include <WinAPI.au3> #include <Process.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <Constants.au3> #Include <APIConstants.au3> #include <WindowsConstants.au3> #Include <ToolBarConstants.au3> #Include <ProcessConstants.au3> #include <MemoryConstants.au3> Opt("MustDeclareVars", 1) Global Const $PROCESS_ACCESS = BitOR($PROCESS_VM_OPERATION, $PROCESS_VM_READ) Global $iTbar = 0 Global $hOwnerWin, $hTrayWnd, $hTrayNotifyWnd, $hSysPager, $hToolbar, _ $iDLLUser32 = DllOpen("user32.dll"), $iDLLKrnl32 = DllOpen("kernel32.dll"), _ $tTBBUTTON, $pTBBUTTON, $iTBBUTTON, $tTRAYDATA, $pTRAYDATA, $iTRAYDATA, _ $iImg = 0, $iIdx = 0, $iCount, $iPIDExp, $hProcess, $pAddress, $iPID, $aRet, $sRet, $hIconTray, $hIcon $hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]") $hTrayNotifyWnd = ControlGetHandle($hTrayWnd, "", "[CLASS:TrayNotifyWnd]") $hSysPager = ControlGetHandle($hTrayNotifyWnd, "", "[CLASS:SysPager]") $hToolbar = ControlGetHandle($hSysPager, "", "[CLASS:ToolbarWindow32; INSTANCE:1]");User Promoted Notification Area/Notification Area/SysTray Switch @OSVersion Case "WIN_2008R2", "WIN_7" Switch $iTbar Case 1 ;Overflow Notification Area $hToolbar = ControlGetHandle(WinGetHandle("[CLASS:NotifyIconOverflowWindow]"), "", "[CLASS:ToolbarWindow32; INSTANCE:1]") Case 2 ;System Promoted Notification Area $hToolbar = ControlGetHandle($hTrayNotifyWnd, "", "[CLASS:ToolbarWindow32; INSTANCE:2]") EndSwitch EndSwitch $tTBBUTTON = DllStructCreate("int Bitmap;int Command;byte State;byte Style;align;dword_ptr Param;int_ptr String") $pTBBUTTON = DllStructGetPtr($tTBBUTTON) $iTBBUTTON = DllStructGetSize($tTBBUTTON) $tTRAYDATA = DllStructCreate("hwnd hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];ptr hIcon") $pTRAYDATA = DllStructGetPtr($tTRAYDATA) $iTRAYDATA = DllStructGetSize($tTRAYDATA) $iPIDExp = WinGetProcess($hToolbar) If @error Or $iPIDExp = -1 Then exit $aRet = DllCall($iDLLKrnl32, "ptr", "OpenProcess", "dword", _ $PROCESS_ACCESS, "int", 0, "int", $iPIDExp) If @error Or $aRet[0] = 0 Then Exit $hProcess = $aRet[0] $aRet = DllCall($iDLLUser32, "lparam", "SendMessageW", "hwnd", _ $hToolbar, "int", $TB_BUTTONCOUNT, "wparam", 0, "lparam", 0) If @error Or $aRet[0] < 1 Then DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProcess) Exit EndIf $iCount = $aRet[0] - 1 $aRet = DllCall($iDLLKrnl32, "ptr", "VirtualAllocEx", "ptr", $hProcess, "ptr", 0, "ulong_ptr", _ $iTBBUTTON, "dword", BitOR($MEM_RESERVE, $MEM_COMMIT), "dword", $PAGE_READWRITE) If @error Or $aRet[0] = 0 Then DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProcess) Exit EndIf $pAddress = $aRet[0] GUICreate("Notification Icons", 600, 600) GUISetBkColor(0x494949) Global $hListView = GUICtrlCreateListView("", 2, 2, 596, 596) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) Global $hImage = _GUIImageList_Create(16,16,5,5) _GUICtrlListView_SetImageList($hListView, $hImage, 1) _GUICtrlListView_AddColumn($hListView, "Tray", 38) _GUICtrlListView_AddColumn($hListView, "Proc", 38) _GUICtrlListView_AddColumn($hListView, "Process", 138) _GUICtrlListView_AddColumn($hListView, "Module", 138) _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER) GUISetState() For $iID = 0 To $iCount If IsHWnd($hToolbar) = False Then ExitLoop $aRet = DllCall($iDLLUser32, "lparam", "SendMessageW", "hwnd", $hToolbar, _ "int", $TB_GETBUTTON, "wparam", $iID, "lparam", $pAddress) If @error Or $aRet[0] <> 1 Then ContinueLoop $aRet = DllCall($iDLLKrnl32, "int", "ReadProcessMemory", "ptr", $hProcess, _ "ptr", $pAddress, "ptr", $pTBBUTTON, "ulong_ptr", $iTBBUTTON, "ulong_ptr*", -1) If @error Or $aRet[5] <> $iTBBUTTON Then ContinueLoop ;If BitAND(DllStructGetData($tTBBUTTON, "State"), $TBSTATE_HIDDEN) = $TBSTATE_HIDDEN Then ContinueLoop $aRet = DllCall($iDLLKrnl32, "int", "ReadProcessMemory", "ptr", $hProcess, _ "dword_ptr", DllStructGetData($tTBBUTTON, "Param"), "ptr", $pTRAYDATA, "ulong_ptr", $iTRAYDATA, "ulong_ptr*", -1) If @error Or $aRet[5] <> $iTRAYDATA Then ContinueLoop $hOwnerWin = DllStructGetData($tTRAYDATA, 1) If @error Or $hOwnerWin = 0 Then ContinueLoop $iPID = WinGetProcess($hOwnerWin) If @error Or $iPID = -1 Then ContinueLoop $hIconTray = DllStructGetData($tTRAYDATA, 5) ;returned icon handles shared $sRet = "" If Not _IsIconHandle($hIconTray, $sRet) Then ;ConsoleWrite('!VarGetType($hIconTray) = ' & VarGetType($hIconTray) & @CRLF) If IsPtr($hIconTray) Then $hIconTray = _WinAPI_Create32BitHICON($hIconTray) ;some icons like HDDLife's temp icons return an invalid icon handle, and won't display, but will when formatted by _WinAPI_Create32BitHICON If Not _IsIconHandle($hIconTray, $sRet) Then $hIconTray = _GetTrayIconHandle($hOwnerWin) ConsoleWrite("- Invalid Icon handle: OwnerWin: " & _WinAPI_GetClassName($hOwnerWin) & " Process Name: " & _ProcessGetName($iPID) & @crlf) EndIf EndIf ;$hIconTray = _WinAPI_CopyImage($hIconTray, $IMAGE_ICON, 16, 16) _GUIImageList_ReplaceIcon($hImage, -1, $hIconTray) $hIcon = _WinAPI_ShellExtractAssociatedIcon(_WinAPI_GetProcessFileName($iPID), 1) $iImg = _GUIImageList_ReplaceIcon($hImage, -1, $hIcon) _GUICtrlListView_InsertItem($hListView, "", -1, $iImg-1) _GUICtrlListView_AddSubItem($hListView, $iIdx, "", 1, $iImg) _GUICtrlListView_AddSubItem($hListView, $iIdx, _ProcessGetName($iPID), 2) If $sRet = "" Then $sRet = _WinAPI_GetProcessFileName($iPID) _GUICtrlListView_AddSubItem($hListView, $iIdx, $sRet, 3) $iIdx += 1 ;ToolTip(_WinAPI_GetClassName($hOwnerWin), 1030, 850, $sRet, $hIconTray, 5) ;Sleep(500) _WinAPI_DestroyIcon($hIcon) _WinAPI_DestroyIcon($hIconTray) ;does not destroy traydata handles Next DllCall($iDLLKrnl32, "int", "VirtualFreeEx", "ptr", $hProcess, "ptr", $pAddress, "ulong_ptr", 0, "dword", $MEM_RELEASE) DllCall($iDLLKrnl32, "int", "CloseHandle", "ptr", $hProcess) DllClose($iDLLUser32) DllClose($iDLLKrnl32) ToolTip("") While GUIGetMsg() <> -3 WEnd _GUIImageList_Destroy($hImage) Exit Func _GetTrayIconHandle($hWnd, $hDLLUser32 = "User32.dll") If Not IsHWnd($hWnd) Then Return SetError(1, 1, -1) Local $iPID, $ParentPID, $aWinList $hIcon = _GetIcon($hWnd, $hDLLUser32) If Not @error And $hIcon <> -1 Then Return SetError(0, 0, $hIcon) $ParentPID = WinGetProcess($hWnd) If @error Or $ParentPID = -1 Then Return SetError(2, 2, -1) $aWinList = WinList() For $i = 1 to $aWinList[0][0] $iPID = WinGetProcess($aWinList[$i][1]) If @error Or $iPID = -1 Then ContinueLoop If $iPID = $ParentPID Then $hIcon = _GetIcon($aWinList[$i][1], $hDLLUser32) If Not @error And $hIcon <> -1 Then Return SetError(0, 0, $hIcon) EndIf Next Return SetError(2, 2, -1) EndFunc ;modified from ModernMenu Win2Tray - by Holger Kotsch Func _GetIcon(ByRef $hWnd, $hDLLUser32 = "User32.dll") If Not IsHWnd($hWnd) Then Return SetError(1, 1, -1) Local Const $GCL_HICON = -14 Local Const $GCL_HICONSM = -34 Local $hIcon $hIcon = _SendMessage($hWnd, $WM_GETICON, 2, 0) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _SendMessage($hWnd, $WM_GETICON, 0, 0) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _WinAPI_GetClassLongEx($hWnd, $GCL_HICONSM) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _WinAPI_GetClassLongEx($hWnd, $GCL_HICON) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) Return SetError(2, 2, -1) EndFunc Func _IsIconHandle($hIcon, ByRef $sMod) ;rover 2k11 Local $aRet Switch @OSVersion Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" $aRet = _WinAPI_GetIconInfoEx($hIcon) If @error Then Return SetError(1, 1, False) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", $aRet[3]) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", $aRet[4]) If $aRet[0] = 0 Then Return SetError(2, 2, False) $sMod = $aRet[6] Return SetError(0, 0, True) Case "WIN_2003", "WIN_XP" Local $tIconInfo = DllStructCreate("int fIcon;int xHotspot;int yHotspot;ptr hbmMask;ptr hbmColor") Local $aRet = DllCall("User32.dll", "int", "GetIconInfo", "ptr", $hIcon, "ptr", DllStructGetPtr($tIconInfo)) If @error Or UBound($aRet) <> 3 Or $aRet[0] = 0 Then Return SetError(1, 1, False) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", DllStructGetData($tIconInfo, 4)) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", DllStructGetData($tIconInfo, 5)) If Not DllStructGetData($tIconInfo, 1) Then Return SetError(2, 2, False) Return SetError(0, 0, True) EndSwitch EndFunc3 points
-
Negative bases
jvanegmond reacted to JohnQSmith for a topic
That's correct and you can use any symbol to represent it, not just 1 (at least that's what a professor told me).I've been lurking for 7 years. Finally decided to post.1 point -
I completely forgot to repost here that I created the project at; http://code.google.com/p/mft2csv/downloads/list One of the important things missing is the filename to mftnumber resolving. Apart from that it is possible to recover deleted files, as long as the sectors are not overwritten and the MFT entry (with the runs information) is also there.1 point
-
Get text from random line to the last line ?
MrVietA2 reacted to Blue_Drache for a topic
If you give a man a fire, he's warm for a day. If you set a man on fire, he's warm for the rest of his life.1 point -
@Blue_Drache Thanks, you understood perfectly what I was trying to do. I have seen his post where he was asking for an example and I decided to not answer and to give him a chance to understand what I did there. Unfortunately for him, somebody else took the nanny role. I can see that my "example" was good enough for Malkey because he only changed it just a little bit1 point
-
I`ve just tried this over a film playing with VLC and it seems to work ok. This is a modified version of UEZ simple clock posted elsewhere on the forum, but its all his work. #include <Date.au3> #Include <Timers.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> #include <String.au3> #include <GuiMenu.au3> #include <Misc.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Global $hGUI, $hGraphics, $hBackbuffer, $hBitmap, $hPen1, $hPen2, $hPen3, $hPen4 Global $iWidth = 600, $iHeight = $iWidth, $iW = $iWidth, $iH = $iHeight Global Const $p2_hm = $iWidth / 35 Global Const $p3_hm = $iWidth / 35 Global Const $p4_hm = $iWidth / 100 Global $newY = $iWidth, $newX = $iHeight Global Const $minSize = $iWidth * 0.25 Global Const $maxSize = $iWidth * 1.5 Global Const $cX = $iWidth * 0.5, $cY = $iHeight * 0.5 Global Const $deg = ACos(-1) / 180 Global Const $radius = $iWidth * 0.85, $cR = $radius * 0.50 Global Const $cR1 = $cR * 0.90, $cR2 = $cR * 0.20 Global Const $cR3 = $cR * 0.80, $cR4 = $cR * 0.15 Global Const $cR5 = $cR * 0.50, $cR6 = $cR * 0.10 Global $sek = @SEC * 6 - 90 Global $min = @MIN * 6 + (@SEC / 10) - 90 Global $std = @HOUR * 30 + (@MIN / 2) - 90 Global Const $fs = $iHeight / 30, $tms = $iHeight / 20, $tmh = $iHeight * 0.725 Global $x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4, $x5, $x6, $y5, $y6, $tm Global $T_Font, $T_Brush, $T_Format, $T_Family, $T_Layout, $T_String Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap Global $contextmenu, $button, $buttoncontext, $buttonitem Global $newsubmenu, $textitem, $fileitem, $saveitem, $infoitem Global $SliderGUI,$Trans, $Trans_Handle, $Size, $Size_Handle, $TransValue, $SizeValue Global Enum $item1 = 1000, $item2, $item3 Global $title = "GDI+ Simple Clock by UEZ 2011 / " Opt("GUIOnEventMode", 1) ; ====== Create Properties GUI but hide it ===================== $SliderGUI =GUICreate("Properties", 220, 150, 100, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "SliderGUIhide",$SliderGUI) GUICtrlCreateLabel("Transparency",20,5) $Trans = GUICtrlCreateSlider(10, 20, 200, 20) $Trans_Handle = GUICtrlGetHandle(-1) GUICtrlSetLimit(-1, 255, 0) ; change min/max value GUICtrlSetData($Trans, 125) ; set cursor GUICtrlCreateLabel("Size",20,50) $Size = GUICtrlCreateSlider(10, 65, 200, 20) $Size_Handle = GUICtrlGetHandle(-1) GUICtrlSetLimit(-1, 100, 10) ; change min/max value GUICtrlSetData($Size, 100) ; set cursor GUISetState(@SW_HIDE, $SliderGUI) GUIRegisterMsg($WM_HSCROLL, "WM_H_Slider") ;============================================================== ; Initialize GDI+ _GDIPlus_Startup() $hGUI = GUICreate($title, $iWidth, $iHeight, -1, -1, 0, $WS_EX_LAYERED + $WS_EX_TOPMOST) ;If @OSBuild < 7600 Then WinSetTrans($hGui,"", 0xFF) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") ;Adjust Trans $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; _WinAPI_UpdateLayeredWindow parameters $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $iWidth) DllStructSetData($tSize, "Y", $iHeight) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) Global $alpha =200 Global $alpha_steps = 5 $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $alpha) DllStructSetData($tBlend, "Format", 1) $tPoint = DllStructCreate($tagPOINT) ; For Custom Line Caps $pPoint = DllStructGetPtr($tPoint) DllStructSetData($tPoint, "X", 0) DllStructSetData($tPoint, "Y", 0) GuiSetState() Global $aPos = WinGetPos($hGUI) GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") ;Drag Window GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") ;Adjust Trans GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") $ScreenDc = _WinAPI_GetDC($hGUI) $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hbitmap) $dc = _WinAPI_CreateCompatibleDC($ScreenDc) _WinAPI_SelectObject($dc, $gdibitmap) ; Using antialiasing _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hBackbuffer, "int", 3) ; Create a Pen object $hPen1 = _GDIPlus_PenCreate(0xFF800010, 4) $hPen2 = _GDIPlus_PenCreate(0xA01010F0, $p2_hm) $hPen3 = _GDIPlus_PenCreate(0xA01010F0, $p3_hm) $hPen4 = _GDIPlus_PenCreate(0x9010D040, $p4_hm) Global Const $LineCapRound = 2, $LineCapTriangle = 3, $DashCapFlat = 0 Global $hPath, $hCustomLineCap, $avCaps Global $avPoints[3][2] = [[2], [0, 0], [0, 0]] $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddLines($hPath, $avPoints) $hCustomLineCap = _GDIPlus_CustomLineCapCreate(0, $hPath) _GDIPlus_CustomLineCapSetStrokeCaps($hCustomLineCap, $LineCapTriangle, $LineCapRound) $avCaps = _GDIPlus_CustomLineCapGetStrokeCaps($hCustomLineCap) _GDIPlus_PenSetLineCap($hPen2, $avCaps[0], $avCaps[1], $DashCapFlat) _GDIPlus_PenSetLineCap($hPen3, $avCaps[0], $avCaps[1], $DashCapFlat) _GDIPlus_PenSetLineCap($hPen4, $avCaps[0], $avCaps[1], $DashCapFlat) Global $ws = WinGetPos($hGUI) Global $ratio = $ws[3] / $ws[2] Global $font = "Comic Sans MS" If FileExists(@WindowsDir & "fontsshowg.ttf") Then $font = "Showcard Gothic" ;Time init $T_Brush = _GDIPlus_BrushCreateSolid(0xFF008080) $T_Format = _GDIPlus_StringFormatCreate() $T_Family = _GDIPlus_FontFamilyCreate("Verdana") $T_Font = _GDIPlus_FontCreate ($T_Family, 32, 3) $T_Layout = _GDIPlus_RectFCreate(0, 0, $iWidth, 80) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") AdlibRegister("Ticker", 50) Global $timer = 100, $speak = False, $speak_init = True, $SpeakingClock = True Global $oVoice = ObjCreate("SAPI.SpVoice") If @error Then $speak_init = False Else $oVoice.Rate = -3 EndIf GUIRegisterMsg($WM_TIMER, "Draw") ;$WM_TIMER = 0x0113 DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $timer, "int", 0) AdlibRegister( "SpeakingClock", 1000) While Sleep(100000000) WEnd Func Draw() _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000) _GDIPlus_GraphicsDrawLine($hBackbuffer, $cX - $cR, $cY, $cX - $cR + 35, $cY, $hPen1) _GDIPlus_GraphicsDrawLine($hBackbuffer, $cX + $cR, $cY, $cX + $cR - 35, $cY, $hPen1) _GDIPlus_GraphicsDrawLine($hBackbuffer, $cX, $cY - $cR, $cX, $cY - $cR + 35, $hPen1) _GDIPlus_GraphicsDrawLine($hBackbuffer, $cX, $cY + $cR, $cX, $cY + $cR - 35, $hPen1) _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $cX - $cR, $cY - $cR, $radius, $radius, $hPen1) For $i = 0 To 11 _GDIPlus_GraphicsDrawString($hBackbuffer, $i + 1, -$fs / 2 + $cX + Cos(-45 + $i * 29.7 * $deg) * $cR3, -$fs * 0.9 + $cY + Sin(-45 + $i * 29.7 * $deg) * $cR3, $font, $fs) Next If Int(StringLeft(_NowTime(4), 2) / 12) Then $tm = "PM" Else $tm = "AM" EndIf _GDIPlus_GraphicsDrawString($hBackbuffer, $tm, -$tms * 1.1 + $cX, $tmh, $font, $tms) $x5 = $cX + Cos($std * $deg) * $cR5 $y5 = $cY + Sin($std * $deg) * $cR5 _GDIPlus_GraphicsDrawLine($hBackbuffer, $x5, $y5, $cX, $cY, $hPen2) ;hours $x3 = $cX + Cos($min * $deg) * $cR3 $y3 = $cY + Sin($min * $deg) * $cR3 _GDIPlus_GraphicsDrawLine($hBackbuffer, $x3, $y3, $cX, $cY, $hPen3) ;minutes $x1 = $cX + Cos($sek * $deg) * $cR1 $y1 = $cY + Sin($sek * $deg) * $cR1 $x2 = $cX + Cos(($sek + 180) * $deg) * $cR2 $y2 = $cY + Sin(($sek + 180) * $deg) * $cR2 _GDIPlus_GraphicsDrawLine($hBackbuffer, Floor($x1), Floor($y1), Floor($x2), Floor($y2), $hPen4) ;seconds _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $cX - 3, $cY - 3, 6, 6, $hPen1) ; <<<< ================= Digital Time ======================= DrawTime() ; ========= Update layered Window ============================ ; creates an empty bitmap with the new size, This bitmap will be used for the transparent GUI. Local $hBmp = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) $hBmp = $hBmp[6] Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, 0, 0, $iW, $iH) $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _WinAPI_SelectObject($dc, $gdibitmap) DllStructSetData($tSize, "X", $iW) DllStructSetData($tSize, "Y", $iH) _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2) _WinAPI_DeleteObject($gdibitmap) _WinAPI_RedrawWindow($hGUI) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_BitmapDispose($hBmp) EndFunc ;================================================================= ; ================== Draw the digital time ============================= Func DrawTime() Local $sString, $aSize ; WinSetTitle($hGui, "", $title & @HOUR & ":" & @MIN & ":" & @SEC) $sString = StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC) $aSize = _GDIPlus_GraphicsMeasureString($hBackbuffer, $sString, $T_Font, $T_Layout, $T_Format) DllStructSetData($T_Layout, "X", (DllStructGetData($aSize[0], "Width")* 0.77)) ; Middle of Window DllStructSetData($T_Layout, "Y", (DllStructGetData($aSize[0], "Height")- 64 )) ; Clock at Top _GDIPlus_GraphicsDrawStringEx($hBackbuffer, $sString, $T_Font, $T_Layout, $T_Format, $T_Brush) EndFunc ; ============= Handle the WM_NCHITTEST message =============== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) Local $hMenu, $Win, $WinX, $WinY, $mX, $mY if $hWnD = $hGUI and _IsPressed (01) then Return $HTCAPTION if $hWnd = $hGUI and _IsPressed (02) then ; ConsoleWrite($GUI &" HIT!! "&@CRLF) #cs $WinPos = WingetPos($GUI) $WinX = $WinPos[0] $WinY = $WinPos[0] $aPos = MouseGetPos() $mX = $aPos [0] $mY = $aPos [1] ConsoleWrite("MouseCoords = " &$WinX + $mX &" " &$WinY + $mY &@CRLF) #ce $hMenu = _GUICtrlMenu_CreatePopup () _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Properties", $item1) _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Item 2", $item2) _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "", 0) _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Exit", $item3) _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGUI, -1,-1 ,1,0 ) _GUICtrlMenu_DestroyMenu ($hMenu) Return True endif EndFunc ;================================================================== ; ========= Handle WM_COMMAND messages ======================= Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case $item1 Properties() ConsoleWrite("Item 1 = " &$item1 &@CRLF) Case $item2 ConsoleWrite("Item 2 = " &$item2 &@CRLF) Case $item3 _Exit() ConsoleWrite("Item 3 = " &$item3 &@CRLF) EndSwitch EndFunc ;==>WM_COMMAND ;============================================================= Func Properties() GUISetState(@SW_SHOW, $SliderGUI) EndFunc Func SliderGUIhide() GUISetState(@SW_HIDE, $SliderGUI) EndFunc ; ============ React to slider movement ======================== Func WM_H_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam If $lParam = $Trans_Handle Then $TransValue = GUICtrlRead($Trans) DllStructSetData($tBlend, "Alpha", $TransValue) ; Set Alpha (Transparency) Level DllStructSetData($tBlend, "Format", 1) ToolTip($TransValue) EndIf If $lParam = $Size_Handle Then $SizeValue = GUICtrlRead($Size) $iW = $iWidth * $SizeValue * 0.01 $iH = $iHeight * $SizeValue * 0.01 EndIf Return "GUI_RUNDEFMSG" EndFunc ;=============================================================== ; MouseWheel for Win Trans Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) Local $mouseData, $n1 $mouseData = _WinAPI_HiWord($wParam) ;/ $WHEEL_DELTA Select ;WM_MOUSEWHEEL = 0x020A Case WinActive($hGUI) If $mouseData > 0 Then ;wheel up If $alpha + $alpha_steps <= 512 Then $alpha += $alpha_steps Switch $alpha Case 0 To 255 DllStructSetData($tBlend, "Alpha", $alpha) ; Set Alpha (Transparency) Level DllStructSetData($tBlend, "Format", 1) Case 256 To 512 DllStructSetData($tBlend, "Alpha", $alpha - 256) DllStructSetData($tBlend, "Format", 0) EndSwitch Else ;wheel down If $alpha - $alpha_steps > 0 Then $alpha -= $alpha_steps Switch $alpha Case 0 To 255 DllStructSetData($tBlend, "Alpha", $alpha) ;wheel up DllStructSetData($tBlend, "Format", 1) Case 256 To 512 DllStructSetData($tBlend, "Alpha", $alpha - 256) ;wheel up DllStructSetData($tBlend, "Format", 0) EndSwitch EndIf ConsoleWrite($alpha & @CRLF) EndSelect EndFunc ;==>WM_MOUSEWHEEL Func SpeakingClock() ; If $min = -90.00 And $speak_init And $SpeakingClock Then $oVoice.Speak("It is " & Mod(@HOUR, 12) & " " & $tm, 1) EndFunc Func Ticker() $sek = @SEC * 6 - 90 $min = @MIN * 6 + (@SEC * 0.10) - 90 $std = @HOUR * 30 + (@MIN * 0.50) - 90 EndFunc Func _Exit() AdlibUnRegister("Ticker") AdlibUnRegister("SpeakingClock") $oVoice = 0 GUIRegisterMsg($WM_TIMER, "") GUIRegisterMsg($WM_GETMINMAXINFO, "") GUIRegisterMsg($WM_SIZE, "") GUIRegisterMsg($WM_ERASEBKGND, "") GUIRegisterMsg($WM_SIZING, "") _WinAPI_DeleteDC($dc) _WinAPI_ReleaseDC($hGUI, $ScreenDc) ; Clean up GDI+ resources _GDIPlus_CustomLineCapDispose($hCustomLineCap) _GDIPlus_PathDispose($hPath) _GDIPlus_PenDispose($hPen1) _GDIPlus_PenDispose($hPen2) _GDIPlus_PenDispose($hPen3) _GDIPlus_PenDispose($hPen4) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_FontDispose ($T_Font ) _GDIPlus_FontFamilyDispose ($T_Family) _GDIPlus_StringFormatDispose($T_Format) _GDIPlus_BrushDispose ($T_Brush) ; Uninitialize GDI+ _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Func _GDIPlus_PathCreate($iFillMode = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", $iFillMode, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[2] EndFunc ;==>_GDIPlus_PathCreate Func _GDIPlus_PathAddLines($hPath, $aPoints) Local $iI, $iCount, $pPoints, $tPoints, $aResult $iCount = $aPoints[0][0] $tPoints = DllStructCreate("float[" & $iCount * 2 & "]") $pPoints = DllStructGetPtr($tPoints) For $iI = 1 To $iCount DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1) DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2) Next $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathLine2", "hwnd", $hPath, "ptr", $pPoints, "int", $iCount) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_PathAddLines Func _GDIPlus_PathDispose($hPath) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_PathDispose Func _GDIPlus_CustomLineCapCreate($hPathFill, $hPathStroke, $iLineCap = 0, $nBaseInset = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateCustomLineCap", "hwnd", $hPathFill, "hwnd", $hPathStroke, "int", $iLineCap, "float", $nBaseInset, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[5] EndFunc ;==>_GDIPlus_CustomLineCapCreate Func _GDIPlus_CustomLineCapSetStrokeCaps($hCustomLineCap, $iStartCap, $iEndCap) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetCustomLineCapStrokeCaps", "hwnd", $hCustomLineCap, "int", $iStartCap, "int", $iEndCap) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_CustomLineCapSetStrokeCaps Func _GDIPlus_CustomLineCapGetStrokeCaps($hCustomLineCap) Local $aCaps[2], $aResult $aResult = DllCall($ghGDIPDll, "uint", "GdipGetCustomLineCapStrokeCaps", "hwnd", $hCustomLineCap, "int*", 0, "int*", 0) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return -1 $aCaps[0] = $aResult[2] $aCaps[1] = $aResult[3] Return $aCaps EndFunc ;==>_GDIPlus_CustomLineCapGetStrokeCap Func _GDIPlus_PenSetLineCap($hPen, $iStartCap, $iEndCap, $iDashCap) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPenLineCap197819", "hwnd", $hPen, "int", $iStartCap, "int", $iEndCap, "int", $iDashCap) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_PenSetLineCap1 point
-
_RefreshSystemTray()
Chris_1013 reacted to Valik for a topic
Here's a function to remove dead icons from the Notification Area (Tray). When an application dies, its icon isn't always removed. The simple solution is to mouse over the icon and it will vanish. Thats pretty much what this function does; it programatically mouses over the tray and removes any dead icons. I used SetCursorPos() from the Windows API because it is far faster than MouseMove(). Its so fast, in fact, that all you should see is a brief flicker of your cursor and the icons vanish. Requires: Beta build containing DllCall(). ; =================================================================== ; _RefreshSystemTray($nDealy = 1000) ; ; Removes any dead icons from the notification area. ; Parameters: ; $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's ; "Hide Inactive Icons" feature (In milliseconds). ; Returns: ; Sets @error on failure: ; 1 - Tray couldn't be found. ; 2 - DllCall error. ; =================================================================== Func _RefreshSystemTray($nDelay = 1000) ; Save Opt settings Local $oldMatchMode = Opt("WinTitleMatchMode", 4) Local $oldChildMode = Opt("WinSearchChildren", 1) Local $error = 0 Do; Pseudo loop Local $hWnd = WinGetHandle("classname=TrayNotifyWnd") If @error Then $error = 1 ExitLoop EndIf Local $hControl = ControlGetHandle($hWnd, "", "Button1") ; We're on XP and the Hide Inactive Icons button is there, so expand it If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) Sleep($nDelay) EndIf Local $posStart = MouseGetPos() Local $posWin = WinGetPos($hWnd) Local $y = $posWin[1] While $y < $posWin[3] + $posWin[1] Local $x = $posWin[0] While $x < $posWin[2] + $posWin[0] DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y) If @error Then $error = 2 ExitLoop 3; Jump out of While/While/Do EndIf $x = $x + 8 WEnd $y = $y + 8 WEnd DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1]) ; We're on XP so we need to hide the inactive icons again. If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) EndIf Until 1 ; Restore Opt settings Opt("WinTitleMatchMode", $oldMatchMode) Opt("WinSearchChildren", $oldChildMode) SetError($error) EndFunc; _RefreshSystemTray() Edit: Code updated to support Windows XP's "Hide Inactive Icons" feature. Edit 2: Removed $class variable and all references to it; $hWnd is now properly used ($class was a leftover from debugging the "Hide Inactive Icons" feature). There shouldn't be a functional change to the code, however. Edit 3: Added optional parameter to specify the delay to give to Windows XP's "Hide Inactive Icons" feature. There is an animation during the expansion of the notification area. The default pause is 1 second, however, passing a new time (in milliseconds) can alter the delay if 1 second isn't enough.1 point