Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/03/2022 in all areas

  1. Not following your script completely. But here another way : #include <Array.au3> Local $hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then Exit Local $oShell = ObjCreate("Shell.Application") For $oWindow In $oShell.Windows() If $oWindow.HWND = $hExplorer Then ExitLoop Next With $oWindow.Document.SelectedItems() If Not .count Then Exit MsgBox(0, "Empty", "Please select a file or folder") ConsoleWrite("Items selected " & .count & @CRLF) Local $aFile[.count] For $i = 0 To .count - 1 $aFile[$i] = .item($i).Path Next EndWith _ArrayDisplay($aFile) For $i = 0 to UBound($aFile) - 1 ; do the delete here Next
    1 point
  2. Thanks @argumentum, fixed, and renamed the Globals (those with most "common" names, good advice.😙) New version in the first post.
    1 point
  3. @ashraful089Just put your Select into parentheses. Like this (pseudo): Case ($a >= xxx And $a <= xxx) And ($b >= xxx And $b <= xxx) .....
    1 point
  4. MagicianPT

    Volume Control

    Hello all. So sorry to dig up an old topic, just want to give a small contribution for those that need a fast way to set volume up/down and do not own a multimedia keyboard. So... on a modern keyboard we have the [Fn] key, witch is usually used to various multimedia functions... I think that the most important is the volume up and down. I've recently bought a keyboard with no [Fn] key, so I've searched the net for a small script that would help me find a way to have sound volume settings directly from my keyboard, so I've found this topic, witch is good, but not as simple as I'd like... so I've made my own script. If some of you are looking for this same feature, no need for further search... just look below HotKeySet("^{PGUP}", "vup") HotKeySet("^{PGDN}", "vdwn") While 1 Sleep (1000) WEnd Func vup() Sleep (5) Send ("{VOLUME_UP}") EndFunc Func vdwn() Sleep (5) Send ("{VOLUME_DOWN}") EndFunc This simple script will remain visible on your taskbar as long as you want [Ctrl] + [Page Up] => Volume up [Ctrl] + [Page Down] => Volume down EXIT => click on icon in task bar
    1 point
  5. Jon

    AutoIt v.3.3.16.0 Released

    AutoIt v3.3.16.0 has been released. Thanks to @jpm and the MVPs who were responsible for the majority of code in this version. Download it here. Complete list of changes: History
    1 point
  6. I tweaked the the _GuiHole function in the _WinAPI_CreateRoundRectRgn example in the help file to produce this result. #include <winapi.au3> #include <WinAPIGdi.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0x0000) WinSetTrans($hGUI,"",100) _GuiHole($hGUI, 50, 50, 80, 30, 8, 8) GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit Wend Func _GuiHole($hWin, $iX, $iY, $iSizeW, $iSizeH, $iWidthEllipse, $iHeightEllipse) Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn, $aPos = WinGetPos($hWin) $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $aPos[2], $aPos[3]) $hInner_rgn = _WinAPI_CreateRoundRectRgn($iX, $iY, $iX + $iSizeW, $iY + $iSizeH, $iWidthEllipse, $iHeightEllipse) $hCombined_rgn = _WinAPI_CreateRoundRectRgn(0, 0, 0, 0, 0 ,0) _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF) _WinAPI_DeleteObject($hOuter_rgn) _WinAPI_DeleteObject($hInner_rgn) _WinAPI_SetWindowRgn($hWin, $hCombined_rgn) EndFunc ;==>_GuiHole
    1 point
  7. Here we go: #include <GDIPlus.au3> Global $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.bmp;*.png;*.gif)") If @error Then Exit MsgBox(16, "Error", "You must select an image!", 20) _GDIPlus_Startup() Global Const $hImg = _GDIPlus_ImageLoadFromFile($sFile) Global Const $hBmp = _GDIPlus_BitmapCreateRoundedCornerFromBitmap($hImg) _GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\TestImg.png") _GDIPlus_ImageDispose($hImg) _GDIPlus_ImageDispose($hBmp) _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\TestImg.png") Func _GDIPlus_BitmapCreateRoundedCornerFromBitmap($hImage, $fRadiusCorner = -1, $bBorder = False, $iBorderColor = 0xE0FFFFFF, $iBorderSize = 1) ;coded by UEZ buid 2017-04-17 Local $aDim = _GDIPlus_ImageGetDimension($hImage) If @error Then Return SetError(1, 0, 0) Local Const $iW = $aDim[0], $iH = $aDim[1] Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4) _GDIPlus_GraphicsSetCompositingQuality($hGfx, 2) Local Const $hTexture = _GDIPlus_TextureCreate($hImage) Local Const $hPath = _GDIPlus_PathCreate() If $fRadiusCorner = -1 Then $fRadiusCorner = (($iW + $iH) / 2) * 0.1 EndIf _GDIPlus_PathAddArc($hPath, $iW - ($fRadiusCorner * 2), 0, $fRadiusCorner * 2, $fRadiusCorner * 2, 270, 90) _GDIPlus_PathAddArc($hPath, $iW - ($fRadiusCorner * 2), $iH - ($fRadiusCorner * 2), $fRadiusCorner * 2, $fRadiusCorner * 2, 0, 90) _GDIPlus_PathAddArc($hPath, 0, $iH - ($fRadiusCorner * 2), $fRadiusCorner * 2, $fRadiusCorner * 2, 90, 90) _GDIPlus_PathAddArc($hPath, 0, 0, $fRadiusCorner * 2, $fRadiusCorner * 2, 180, 90) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hTexture) If $bBorder Then Local Const $hPen = _GDIPlus_PenCreate($iBorderColor, $iBorderSize) _GDIPlus_PenSetLineJoin($hPen, 2) _GDIPlus_PenSetAlignment($hPen, 1) _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen) _GDIPlus_PenDispose($hPen) EndIf _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BrushDispose($hTexture) _GDIPlus_PathDispose($hPath) Return $hBitmap EndFunc ;==>_GDIPlus_BitmapCreateRoundedCornerFromBitmap
    1 point
  8. 1 point
  9. shaggy98, I use this function to write to RichEdit controls as it allows you to adjust the font size and attributes as well as the colour - here we leave the size and attributes as default and only adjust the colour: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> $hGui = GUICreate("RichEdit Test", 320, 350) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState() Sleep(1000) ; Write in black _GUICtrlRichEdit_WriteLine($hRichEdit, "I am in BLACK" & @CRLF, Default, Default, 0x000000) Sleep(2000) ; Write in red _GUICtrlRichEdit_WriteLine($hRichEdit, "I am in RED" & @CRLF, Default, Default, 0xFF0000) Sleep(2000) ; And back to black _GUICtrlRichEdit_WriteLine($hRichEdit, "I am back in BLACK" & @CRLF, Default, Default, 0x000000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1) ; Count the @CRLFs StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended ; Adjust the text char count to account for the @CRLFs Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines ; Add new text _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF) ; Select text between old and new end points _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1) ; Convert colour from RGB to BGR $iColor = Hex($iColor, 6) $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2) ; Set colour If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor) ; Set size If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement) ; Set weight If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib) ; Clear selection _GUICtrlRichEdit_Deselect($hWnd) EndFuncPlease ask if you have any further questions. M23
    1 point
  10. UEZ

    Draw rounded rectangle

    Try this instead: #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 ; Create GUI Local $hForm = GUICreate('Test', 400, 400) Local $idPic = GUICtrlCreatePic('', 0, 0, 60, 60) Local $hPic = GUICtrlGetHandle($idPic) Local $hGDIBmp = _GDIPlus_CreateBitmapRoundCornerRect() _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp)) GUISetState(@SW_SHOW) Do Until GUIGetMsg() = -3 _WinAPI_DeleteObject($hGDIBmp) _GDIPlus_Shutdown() Func _GDIPlus_CreateBitmapRoundCornerRect($iW = 60, $iH = 60, $iColorBg = 0xFFFFFFFF, $iColorBorder = 0xFF000000, $iRadius = 8, $bGDIBmp = 1) Local Const $iX = 0, $iY = 0, $iPenSize = 1 Local Const $iWidth = $iW - $iPenSize, $iHeight = $iH - $iPenSize Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) Local Const $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90) _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90) _GDIPlus_PathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90) _GDIPlus_PathCloseFigure($hPath) Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColorBg) _GDIPlus_GraphicsFillPath($hCtxt, $hPath, $hBrush) Local Const $hPen = _GDIPlus_PenCreate($iColorBorder, $iPenSize) _GDIPlus_GraphicsDrawPath($hCtxt, $hPath, $hPen) _GDIPlus_PathDispose($hPath) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hCtxt) If $bGDIBmp Then Local $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hGDIBmp EndIf Return $hBitmap EndFunc Br, UEZ
    1 point
  11. Well, then try this: ;coded by UEZ build 2014-09-27 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $iCountdown = 20 ;in seconds Global Const $iW = 800, $iH = 50, $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("Test", $iW, $iH, -1, -1, $WS_POPUP) Global Const $hPic = GUICtrlCreatePic("", 0, 0, $iW, $iH) Global Const $hRegion = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 1, $iH + 1, 12, 12) _WinAPI_SetWindowRgn($hGUI, $hRegion) Global $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(100, $iCountdown & " seconds left to start rocket", $iW, $iH, 6) _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg)) GUISetState() Global $iDiff, $iTimer = TimerInit() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _Exit() EndSwitch $iDiff = (TimerDiff($iTimer) / 1000) If $iDiff < $iCountdown + 1 Then $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(100 - $iDiff / $iCountdown * 100, Int($iCountdown - $iDiff) & " seconds left to take off", $iW, $iH, 6) _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg)) _WinAPI_DeleteObject($hGDIBmp_Bg) Else $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(0, "Taking off...", $iW, $iH, 6) _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg)) _WinAPI_DeleteObject($hGDIBmp_Bg) Sleep(2000) _Exit() EndIf Until False Func _Exit() _WinAPI_DeleteObject($hRegion) _WinAPI_DeleteObject($hGDIBmp_Bg) GUIDelete() _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit Func _GDIPlus_BitmapCreateRoundCornerRectProgressbar($fPerc, $sText, $iW, $iH, $iRadius_Corner = 6, _ $iColorOuter_Pb = 0xFFC4A000, $iColorInner_Pb = 0xFFFCE94F, $iColorOuter_Bg = 0xFFA0A0A0, $iColorInner_Bg = 0xFFD3D7CF, _ $iSizeBorder_Bg = 4, $iSizeBorder_Pb = 4, _ $sFont = "Arial Black", $fFontSize = 20, $iColor_FontBorder = 0xFF101010, $iColor_Font = 0xFFFFFFFF, $iSizeBorder_Ft = 2, $bGDIBitmap = True) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4) #Region background Local Const $hPath = _GDIPlus_PathCreate() Local $iWidth = $iW - $iSizeBorder_Bg - 1, $iHeight = $iH - $iSizeBorder_Bg - 1 _GDIPlus_PathAddArc($hPath, $iSizeBorder_Bg / 2, $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 180, 90) ;left upper corner _GDIPlus_PathAddArc($hPath, $iWidth - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 270, 90) ;right upper corner _GDIPlus_PathAddArc($hPath, $iWidth - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iHeight - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 0, 90) ;right bottom corner _GDIPlus_PathAddArc($hPath, $iSizeBorder_Bg / 2, $iHeight - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 90, 90) ;left bottm corner _GDIPlus_PathCloseFigure($hPath) Local $hPen = _GDIPlus_PenCreate($iColorOuter_Bg, $iSizeBorder_Bg), $hBrush = _GDIPlus_BrushCreateSolid($iColorInner_Bg) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush) #EndRegion background #Region progressbar Local $iX = 3 * $iSizeBorder_Pb, $iY = 3 * $iSizeBorder_Pb $iHeight = $iH - 2 * $iY $fPerc = $fPerc < 0 ? 0 : $fPerc > 100 ? 100 : $fPerc $iWidth = ($iW - 2 * $iX) * $fPerc / 100 _GDIPlus_PathReset($hPath) _GDIPlus_PenSetColor($hPen, $iColorOuter_Pb) _GDIPlus_PenSetWidth($hPen, $iSizeBorder_Pb) _GDIPlus_BrushSetSolidColor($hBrush, $iColorInner_Pb) _GDIPlus_PathAddRectangle($hPath, $iX, $iY, $iWidth, $iHeight) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush) #EndRegion progressbar #Region text render _GDIPlus_PathReset($hPath) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, 4) _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat) _GDIPlus_PenSetColor($hPen, $iColor_FontBorder) _GDIPlus_PenSetWidth($hPen, $iSizeBorder_Ft) _GDIPlus_BrushSetSolidColor($hBrush, $iColor_Font) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush) #EndRegion text render _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_PathDispose($hPath) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) If $bGDIBitmap Then Local Const $hGDIBmp_Bg = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hGDIBmp_Bg EndIf Return $hBitmap EndFunc ;==>_GDIPlus_BitmapCreateRoundCornerRectProgressbar Br, UEZ
    1 point
  12. UEZ

    WinAPI and Ellipse drawing

    Try something like this here: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> Global Const $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0x123456, $hGUI) _WinAPI_SetLayeredWindowAttributes($hGUI, 0x123456) GUISetState() DrawEllipse(300, 300, 300, 100, 0xFF) Sleep(2000) _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) DrawEllipse(500, 100, 100, 300, 0xFF) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func DrawEllipse($iPosX, $iPosY, $iWidth, $iHeight, $color, $iPenSize = 2) Local $hDC = _WinAPI_GetWindowDC($hGUI) ; DC of entire screen (desktop) Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iPenSize, $color) Local $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, 0x123456) Local $hObj1 = _WinAPI_SelectObject($hDC, $hBrush) Local $hObj2 = _WinAPI_SelectObject($hDC, $hPen) Local $tRECT = _WinAPI_CreateRect(0, 0, $iWidth, $iHeight) _WinAPI_OffsetRect($tRECT, $iPosX, $iPosY) _WinAPI_Ellipse($hDC, $tRECT) _WinAPI_SelectObject($hDC, $hObj1) _WinAPI_SelectObject($hDC, $hObj2) _WinAPI_DeleteObject($hPen) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hGUI, $hDC) EndFunc ;==>DrawEllipse Br, UEZ
    1 point
  13. rover

    _GUICtrlStatusBar_SetText

    statusbar text colour is a bit more problematic as it requires ownerdrawing and more code this example is a modified version of Rasim's demo with ownerdraw code added for statusbar part text and background colour Cheers to whom it may concern: please refrain from posting this code in the example scripts forum without author attribution. Edit Hi Rasim ;to whom it may concern: please refrain from posting this code in the example scripts forum with no attribution to the author. ;Author: rover ;Ownerdrawn StatusBar text font and colour demo ;set text colour and font for StatusBar parts ;modified version of demo by Rasim for setting StatusBar font ;http://www.autoitscript.com/forum/index.php?showtopic=88063 #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <FontConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hFont Global $aParts[3] = [125, 250] Global $aPartsText[2] = ["RED on Transparent", "BLUE on Transparent"] Global $hGUI = GUICreate("Statusbar custom font and colour demo", 400, 300) GUISetBkColor(0xE0FFFF) Global $hStatus = _GUICtrlStatusBar_Create($hGUI) _GUICtrlStatusBar_SetParts($hStatus, $aParts) ; add text and color to struct called in WM_DRAWITEM message handler Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000); Red on transparent background Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0); Blue on transparent background ;_GUICtrlStatusBar_SetText($hStatus, "", 0, $SBT_OWNERDRAW); text not set when ownerdrawn ;_GUICtrlStatusBar_SetText($hStatus, "", 1, $SBT_OWNERDRAW) _GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS") GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM") GUISetState() Sleep(3000) ;you can use the above _GUICtrlStatusBar_SetText() lines and set text and colour in the message handler ;or use _GUICtrlStatusBar_SetColor() to change text, text colour and part background colour more easily Local $iCnt = 0 Do $iCnt +=1 $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, "GOLD on BLACK", 0, 0xFFD700, 0) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, "BLUE on GOLD", 1, 0x0C0DC0, 0xFFD700) Sleep(500) $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0) Sleep(500) Until $iCnt = 5 Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") ;Author: Rasim $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;" & _ "uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) Local $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm"); retrieve statusbar handle Switch _WinAPI_GetClassName($hItm);an example of how message handler does not have to rely on having global variable for statusbar in advance ;Switch $hItm Case "msctls_statusbar32" ;Case $hStatus Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC") ; device context for statusbar for color and/or font Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID"); statusbar part number ; get 32-bit value in itmData when text has SBT_OWNERDRAW drawing type - pointer to struct with text and color Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData") Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam) ; create RECT structure from itmRect byte array for part metrics Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") ; metrics not same as non-ownerdrawn part for some reason, so 1 added for alignment DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)+1) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)+1) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) _WinAPI_SetBkMode($hDC, $TRANSPARENT); otherwise text background set to 0xFFFFFF _WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2)); set part text colour from struct If Not DllStructGetData($tParam, 4) Then; check if background should be transparent Local $iBkColor = DllStructGetData($tParam, 3), $hStatusDC, $hBrushBk $hStatusDC = _WinAPI_GetDC($hItm) $hBrushBk = _WinAPI_CreateSolidBrush($iBkColor) _WinAPI_FillRect($hStatusDC, DllStructGetPtr($tRect), $hBrushBk) _WinAPI_DeleteObject($hBrushBk) _WinAPI_ReleaseDC($hItm, $hStatusDC) EndIf ; draw text to DC (can also use gdi32 TextOutW and ExtTextOut API's) _WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRect, $DT_LEFT) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1) ;Author: rover - modified ownerdraw version of _GUICtrlStatusBar_SetText() from GuiStatusBar.au3 ;Includes RGB2BGR() - Author: Siao - http://www.autoitscript.com/forum/index.php?s=&showtopic=57161&view=findpost&p=433593 ;sets itmData element of statusbar DRAWITEMSTRUCT with pointer to struct with text and colour for part number If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd) Local $ret, $tStruct, $pStruct, $iBuffer ; In Microsoft Windows XP and earlier, the text for each part is limited to 127 characters. ; This limitation has been removed in Windows Vista. ; set sufficiently large buffer for use with Vista (can exceed XP limit of 128 chars) $tStruct = DllStructCreate("wchar Text[512];dword Color;dword BkColor;dword Trans") Switch $iBkColor Case -1 DllStructSetData($tStruct, "Trans", 1) Case Else $iBkColor = BitAND(BitShift(String(Binary($iBkColor)), 8), 0xFFFFFF) DllStructSetData($tStruct, "Trans", 0) DllStructSetData($tStruct, "BkColor", $iBkColor) EndSwitch $iColor = BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF); From RGB2BGR() Author: Siao DllStructSetData($tStruct, "Text", $sText) DllStructSetData($tStruct, "Color", $iColor) $pStruct = DllStructGetPtr($tStruct) If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID ;FOR INTERNAL STATUSBARS ONLY If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then $ret = _SendMessage($hWnd, $SB_SETTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr") Return $tStruct; returns struct to global variable EndIf Return 0 EndFunc ;==>_GUICtrlStatusBar_SetColor
    1 point
  14. rasim

    _GUICtrlStatusBar_SetText

    Example: #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> #include <WinAPI.au3> Global $hFont Dim $aParts[3] = [100, 250] Dim $aPartsText[2] = ["System info", "Current directory"] $hGUI = GUICreate("Statusbar custom font demo", 400, 300) $hStatus = _GUICtrlStatusBar_Create($hGUI, $aParts, $aPartsText) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 2 + 4, "Tahoma") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont
    1 point
  15. Zedna

    Reading Statusbar

    Replace _GUICtrlStatusBar_GetText() in "C:\Program Files\AutoIt3\Include\guistatusbar.au3" by this fix. This was fixed in 3.2.13.0 (7th June, 2008) (Beta) UDFs: - Fixed #321: _GUICtrlStatusBar_GetText buffer length for Unicode ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlStatusBar_GetText ; Description ...: Retrieves the text from the specified part ; Syntax.........: _GUICtrlStatusBar_GetText($hWnd, $iPart) ; Parameters ....: $hWnd - Handle to the control ; $iPart - Zero based part index ; Return values .: Success - Part text ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; Remarks .......: ; Related .......: _GUICtrlStatusBar_SetText ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _GUICtrlStatusBar_GetText($hWnd, $iPart) If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd) Local $iBuffer, $pBuffer, $tBuffer, $pMemory, $tMemMap Local $fUnicode = _GUICtrlStatusBar_GetUnicodeFormat($hWnd) $iBuffer = _GUICtrlStatusBar_GetTextLength($hWnd, $iPart) If $iBuffer = 0 Then Return "" If $fUnicode Then $iBuffer *= 2 $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]") Else $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]") EndIf $pBuffer = DllStructGetPtr($tBuffer) If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then If $fUnicode Then _SendMessage($hWnd, $SB_GETTEXTW, $iPart, $pBuffer, 0, "wparam", "ptr") Else _SendMessage($hWnd, $SB_GETTEXT, $iPart, $pBuffer, 0, "wparam", "ptr") EndIf Else $pMemory = _MemInit($hWnd, $iBuffer, $tMemMap) If $fUnicode Then _SendMessage($hWnd, $SB_GETTEXTW, $iPart, $pMemory, 0, "wparam", "ptr") Else _SendMessage($hWnd, $SB_GETTEXT, $iPart, $pMemory, 0, "wparam", "ptr") EndIf _MemRead($tMemMap, $pMemory, $pBuffer, $iBuffer) _MemFree($tMemMap) EndIf Return DllStructGetData($tBuffer, "Text") EndFunc ;==>_GUICtrlStatusBar_GetText
    1 point
×
×
  • Create New...