Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/05/2019 in all areas

  1. Outlook does not allow to import vCard/VCF-files programmatically. I might implement this format (RFC 6350) as I did with the iCalendar data format if someone is interested Please post here or click the "Like" button if you think this is a good idea
    3 points
  2. GuiFlatButton is a UDF to easily create regular buttons with different colors for background, foreground, border, hover, focus, etc.. This started as an effort to change the background color of a button and eventually grew into a full UDF. If you've looked around forums for changing button background colors, you have probably noticed that each proposed workaround has its own set of issues/side-effects. The answers usually circle back to 'use ownerdrawn buttons' and 'not worth it'. Well, now it is possible for anyone to easily create ownerdrawn buttons - totally worth it! Some issues with other workarounds such as drawing with GDI+ or using a colored label as a 'button': Not 'real' buttons so you lose built-in functionality that windows gives to buttons Messy / inefficient code in the main while loop to check for mouse position Slow to respond to click, paint, etc... Having to deal with GUIRegisterMsg messages Not straight-forward to implement GuiFlatButton is not a workaround; it is a technique to respond to Windows' built-in owner-drawn button events. With minimal effort, we can now create true simple colored buttons. The idea is to create an owner-drawn button using GUICtrlCreateButton then subclass the GUI and controls to handle the button-specific events to paint it however we want. This UDF magically does all of this for us! No need to worry about event handling or main while loop logic. How to use It couldn't be any easier! Simply create a new button using the familiar syntax. This creates an ownerdrawn button with default colors. $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) If you want to change the background and text colors: GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) Advanced Usage Set background/text/border all at once GuiFlatButton_SetColors(-1, 0x0000FF, 0xFFFFFF, 0x9999FF) Set ALL colors for ALL button states! (normal, focus, hover, selected) Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetColorsEx(-1, $aColorsEx) Set default colors to apply to any future buttons ;set colors GuiFlatButton_SetDefaultColors(0x0000FF, 0xFFFFFF, 0x9999FF) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Set ALL color defaults ;set colors Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Available Functions Simple Example #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 275, 120) GUISetBkColor(0x333333) Local $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1" & @CRLF & "Line 2", 78, 20, 120, 40, $BS_MULTILINE) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Menu/Toolbar Example #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;Example GUI with toolbar Func Example() Local $hGUI, $idLabel, $aButtons, $iTbSize $hGUI = GUICreate("GuiFlatButton Ex2", 300, 200) GUISetBkColor(0x444444) $idLabel = GUICtrlCreateLabel("Click a button", 10, 180, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) $aButtons = createToolbar() $iTbSize = UBound($aButtons) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[$iTbSize - 1] ConsoleWrite("1") GUICtrlSetData($idLabel, GuiFlatButton_Read($iMsg)) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Func createToolbar() Local $aButtons[6] Local $bkColor = 0x777777 Local $textColor = 0xFFFFFF Local $borderColor = 0x999999 Local $aBtnClrs[12] = [0x777777, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x888888, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x999999, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x666666, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT] For $i = 0 To UBound($aButtons) - 1 $aButtons[$i] = GuiFlatButton_Create("B" & $i, $i * 50, 0, 50, 17) GuiFlatButton_SetColorsEx($aButtons[$i], $aBtnClrs) Next Return $aButtons EndFunc ;==>createToolbar Icon Example You can even easily add icons to your buttons -- just create a new button and send it an icon! #include <GDIPlus.au3> #include "GuiFlatButton.au3" Example() ;buttons with Icon images Func Example() ;get images for demonstration _GDIPlus_Startup() ;initialize GDI+ Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 258, 24, 24) ;extract the 'Save' icon Local $hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon) ;Create Bitmap from Icon (for demonstration) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;Create HBitmap from Bitmap _GDIPlus_BitmapDispose($hBitmap) ;dispose the bitmap _GDIPlus_Shutdown() ;done with GDI+ Local $hGUI = GUICreate("GuiFlatButton Ex5", 255, 400) GUISetBkColor(0xEEEEEE) ;set default colors of future buttons Local $aColorsEx = _ [0xE2E5E8, 0X000000, 0x888888, _ ; normal : Background, Text, Border 0xE2E5E8, 0X000000, 0x333333, _ ; focus : Background, Text, Border 0xE8E8E8, 0X000000, 0x666666, _ ; hover : Background, Text, Border 0xDDDDDD, 0X000000, 0xAAAAAA] ; selected : Background, Text, Border GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;normal button with icon $label1 = GUICtrlCreateLabel( "$BS_TOOLBUTTON -->", 5, 10) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Local $mybutton1 = GuiFlatButton_Create("Save", 130, 5, 50, 48, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybutton1), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top Local $mybuttonT = GuiFlatButton_Create("Top", 5, 65, 120, 55, $BS_TOP) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonT), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-left Local $mybuttonTL = GuiFlatButton_Create("Top-Left", 5, 125, 120, 55, BITOR($BS_TOP, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-right Local $mybuttonTR = GuiFlatButton_Create("Top-Right", 5, 185, 120, 55, BITOR($BS_TOP, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align left Local $mybuttonL = GuiFlatButton_Create("Left", 5, 245, 120, 55, $BS_LEFT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom Local $mybuttonB = GuiFlatButton_Create("Bottom", 130, 65, 120, 55, $BS_BOTTOM) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonB), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-left Local $mybuttonBL = GuiFlatButton_Create("Bottom-Left", 130, 125, 120, 55, BITOR($BS_BOTTOM, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-right Local $mybuttonBR = GuiFlatButton_Create("Bottom-Right", 130, 185, 120, 55, BITOR($BS_BOTTOM, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align right Local $mybuttonR = GuiFlatButton_Create("Right", 130, 245, 120, 55, $BS_RIGHT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) GuiFlatButton_SetState($mybuttonR, $GUI_DISABLE ) ;disabled Local $mybuttonDisable = GuiFlatButton_Create("Disabled", 130, 310, 120, 55, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonDisable), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) GuiFlatButton_SetState($mybuttonDisable, $GUI_DISABLE ) ;clean up! _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DeleteObject( $hHBitmap ) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example I'm sure there are some use-cases I've forgotten, so feedback is welcome! Download the latest UDF and several more examples: GuiFlatButton_20220919.zip (1,121) Update 2022-09-19 Added update from 05/25 back in after it was accidentally removed Update 2022-09-01 Added $BS_MULTILINE button style Added ellipses when text is longer than the button Fixed compatibility with Opt("MustDeclareVars", 1) Update 2022-05-25 Fixed issue, buttons disappear when a GUI containing a child window with WS_EX_MDICHILD extended style is moved Update 2022-05-24 Fixed issue releasing subclassing when GUI is deleted but program is not closed Fixed occasional white background flicker Added function GuiFlatButton_GetPos Update 2021-01-02 Fixed bug, not drawing correctly after deleting GUI with GUIDelete() Fixed bug, changing default colors changed all buttons, even previously created buttons Made some internal functions more efficient Update 2019-04-14 Fixed bug, not showing pressed down state when clicking rapidly Added Icon/Bitmap support! Added function GuiFlatButton_SetPos to change the position and/or size of a button Update 2019-02-09 Added 2 new functions to set the button colors globally for all future buttons. GuiFlatButton_SetDefaultColors GuiFlatButton_SetDefaultColorsEx Credits to: Melba23 (UDF template) LarsJ (general subclassing code) 4ggr35510n (TrackMouseEvent example) binhnx (disable dragging with $WS_EX_CONTROLPARENT) GUIRegisterMsg in AutoIt Help (owner-draw button example) funkey (_WinAPI_DrawState example)
    1 point
  3. @Skeletor If your input date will always be in the format DD MMM YYYY, then you can use something like this: #include <Array.au3> #include <Date.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $strInputDate = "05 Feb 2019", _ $arrResult, _ $strDateTime, _ $strOutputDate $arrResult = StringRegExp($strInputDate, "^(\d{2})\s{1}([A-Z][a-z]{2})\s{1}(\d{4})$", $STR_REGEXPARRAYMATCH) $strDateTime = StringFormat("%04i/%02i/%02i", $arrResult[2], _GetMonthInDigits($arrResult[1]), $arrResult[0]) $strOutputDate = _DateTimeFormat($strDateTime, 2) If @error Then ConsoleWrite("Error while the date conversion! Error: " & @error & @CRLF) Exit Else MsgBox($MB_ICONINFORMATION, "", $strOutputDate) EndIf Func _GetMonthInDigits($strMonth) Local $arrMonths[12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] For $i = 0 To UBound($arrMonths) - 1 Step 1 If $arrMonths[$i] = $arrResult[1] Then Return ($i + 1) Next EndFunc Using _DateTimeFormat, and passing the date "splitted" in the format YYYY/MM/DD, you'll always have your output date in the format of the local regional settings of the PC
    1 point
  4. I surgest add base control as label, group, combo, input. For a sample: Func _Metro_CreateLabel($Text,$x,$y,$w,$h,$tyle=-1,$xstyle =-1,$Font_Color = $FontThemeColor, $Font = "Segoe UI", $Fontsize = "12") $hLabel = GUICtrlCreateLabel($Text,$x,$y,$w,$h,$tyle,$xstyle) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hLabel), "wstr", 0, "wstr", 0) GUICtrlSetFont($hLabel, $Fontsize, 500, 0, $Font) GUICtrlSetColor($hLabel, $Font_Color) Return $hLabel EndFunc Func _Metro_CreateGroup($Text,$x,$y,$w,$h,$tyle=-1,$xstyle =-1,$Font_Color = $FontThemeColor, $Font = "Segoe UI", $Fontsize = "12") $hgroup = GUICtrlCreateGroup($Text,$x,$y,$w,$h,$tyle,$xstyle) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hgroup), "wstr", 0, "wstr", 0) GUICtrlSetFont($hgroup, $Fontsize, 500, 0, $Font) GUICtrlSetColor($hgroup, $Font_Color) Return $hgroup EndFunc Func _Metro_CreateInput($Text,$x,$y,$w,$h,$tyle=-1,$xstyle =-1,$BG_Color = $GUIThemeColor,$Font_Color = $FontThemeColor, $Font = "Arial", $Fontsize = "9") $hInput = GUICtrlCreateInput($Text,$x,$y,$w,$h,$tyle,$xstyle) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hInput), "wstr", 0, "wstr", 0) GUICtrlSetFont($hInput, $Fontsize, 400, 0, $Font) GUICtrlSetColor($hInput, $Font_Color) GUICtrlSetBkColor($hInput,$GUIThemeColor) _cHvr_Register($hInput, "_iHoverOff", "_iHoverOn") Return $hInput EndFunc Func _Metro_CreateCombo($Text,$x,$y,$w,$h,$tyle=-1,$xstyle =-1,$BG_Color = $GUIThemeColor,$Font_Color = $FontThemeColor, $Font = "Arial", $Fontsize = "9") $hcombo = GUICtrlCreateCombo($Text,$x,$y,$w,$h,$tyle,$xstyle) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hcombo), "wstr", 0, "wstr", 0) GUICtrlSetFont($hcombo, $Fontsize, 400, 0, $Font) GUICtrlSetColor($hcombo, $Font_Color) GUICtrlSetBkColor($hcombo,$GUIThemeColor) Return $hcombo EndFunc
    1 point
  5. I found this code in my collections (might be "old"): ;by UEZ #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) $dll = DllOpen("user32.dll") $hGUI = GUICreate("Seriennummer", 232, 90) $input = GUICtrlCreateInput("", 42, 30, 140) $Label = GUICtrlCreateLabel("Format: XXXX-XXXX-XXXX-XXXX", 32, 8, 163, 17) GUICtrlSetLimit($input, 19) $Button = GUICtrlCreateButton("Weiter", 144, 56, 75, 25, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() $iLen_prev = 0 $iCurPos = 0 GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND') GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While Sleep(10) $aCaret_pos = WinGetCaretPos() If _IsPressed("25", $dll) Or _IsPressed("26", $dll) Then ;left or up Send("{RIGHT}") ElseIf _IsPressed("27", $dll) Or _IsPressed("28", $dll) Then ;right or down DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $aCaret_pos[0], 'int', $aCaret_pos[1]) EndIf $aPos = GUIGetCursorInfo($hGUI) If $aPos[2] And $aPos[4] = $input Then ControlFocus("", "", $input) Send("{Right 50}") EndIf WEnd Func _Exit() DllClose($dll) Exit EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $input Then GUICtrlSetData($input, StringUpper(GUICtrlRead($input))) ;upper letters $i = GUICtrlRead($input) $iLen = StringLen($i) + 1 If Mod($iLen, 5) = 0 And $iLen > $iLen_prev And $iLen < 20 Then GUICtrlSetData($input, $i & "-") If Mod($iLen, 5) = 0 And $iLen < $iLen_prev Then GUICtrlSetData($input, StringLeft($i, $iLen - 2)) $iLen_prev = $iLen If $iLen = 20 Then GUICtrlSetState($Button, $GUI_ENABLE) Else GUICtrlSetState($Button, $GUI_DISABLE) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Br, UEZ
    1 point
  6. Bert

    Runas System

    charming fellow. I wonder what bug bit his bum...
    1 point
  7. Here's another method that came to my mind using the Epoch functions from trancexx. #include <Date.au3> Global $Hour, $Mins, $Secs $start = _Epoch_encrypt(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) Sleep(3000) $end = _Epoch_encrypt(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) _TicksToTime(Int($end * 1000 - $start *1000), $Hour, $Mins, $Secs) $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) MsgBox(0, "Time between Start and End", $Time) Func _EPOCH_decrypt($iEpochTime) ; http://www.autoitscript.com/forum/index.php?showtopic=83667&hl=epoch ; by trancexx Local $iDayToAdd = Int($iEpochTime / 86400) Local $iTimeVal = Mod($iEpochTime, 86400) If $iTimeVal < 0 Then $iDayToAdd -= 1 $iTimeVal += 86400 EndIf Local $i_wFactor = Int((573371.75 + $iDayToAdd) / 36524.25) Local $i_xFactor = Int($i_wFactor / 4) Local $i_bFactor = 2442113 + $iDayToAdd + $i_wFactor - $i_xFactor Local $i_cFactor = Int(($i_bFactor - 122.1) / 365.25) Local $i_dFactor = Int(365.25 * $i_cFactor) Local $i_eFactor = Int(($i_bFactor - $i_dFactor) / 30.6001) Local $aDatePart[3] $aDatePart[2] = $i_bFactor - $i_dFactor - Int(30.6001 * $i_eFactor) $aDatePart[1] = $i_eFactor - 1 - 12 * ($i_eFactor - 2 > 11) $aDatePart[0] = $i_cFactor - 4716 + ($aDatePart[1] < 3) Local $aTimePart[3] $aTimePart[0] = Int($iTimeVal / 3600) $iTimeVal = Mod($iTimeVal, 3600) $aTimePart[1] = Int($iTimeVal / 60) $aTimePart[2] = Mod($iTimeVal, 60) Return SetError(0, 0, StringFormat("%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $aDatePart[0], $aDatePart[1], $aDatePart[2], $aTimePart[0], $aTimePart[1], $aTimePart[2])) EndFunc ;==>_Epoch_decrypt Func _Epoch_encrypt($date) Local $main_split = StringSplit($date, " ") If $main_split[0] - 2 Then Return SetError(1, 0, "") ; invalid time format EndIf Local $asDatePart = StringSplit($main_split[1], "/") Local $asTimePart = StringSplit($main_split[2], ":") If $asDatePart[0] - 3 Or $asTimePart[0] - 3 Then Return SetError(1, 0, "") ; invalid time format EndIf If $asDatePart[2] < 3 Then $asDatePart[2] += 12 $asDatePart[1] -= 1 EndIf Local $i_aFactor = Int($asDatePart[1] / 100) Local $i_bFactor = Int($i_aFactor / 4) Local $i_cFactor = 2 - $i_aFactor + $i_bFactor Local $i_eFactor = Int(1461 * ($asDatePart[1] + 4716) / 4) Local $i_fFactor = Int(153 * ($asDatePart[2] + 1) / 5) Local $aDaysDiff = $i_cFactor + $asDatePart[3] + $i_eFactor + $i_fFactor - 2442112 Local $iTimeDiff = $asTimePart[1] * 3600 + $asTimePart[2] * 60 + $asTimePart[3] Return SetError(0, 0, $aDaysDiff * 86400 + $iTimeDiff) EndFunc ;==>_Epoch_encrypt
    1 point
×
×
  • Create New...