vavallone Posted June 18, 2021 Posted June 18, 2021 (edited) Hey All, I have a nice little form that allows my end users to click on various menus and radio buttons to do things like map printers, download update, etc. One thing I am trying to do is have a menu item (or radio button) that says Email Support. When they click on it, I want Outlook to come up with some fields filled out. I have the code that will do that (listed below). However, I am not sure how to link the menu to that code and have it run. I am really only familiar with using basic $MenuItem and Case command. Any thoughts on how I can "link" the menu - Email Support to this code? Btw, I am not sure who created this code, but thank you! Honestly, what I really could use is a way to just click the menu - Email Support and Outlook opens. This code brings up a window, which is ok too. But I do need to learn how to run other scripts from within AutoIT. Thanks for any help. expandcollapse popupGlobal $MAILTO = 'YourEmailAddress@SomWhere.Com' Dim $MyMsgBox = _MsgBox(2, 'Email Us', 'Click the Link Below or Click "OK" to email us!') If $MyMsgBox = 6 Then _INetMail($MAILTO, 'Regarding: ', '') Else Exit EndIf Func _MsgBox($mb_Icon, $mb_Title, $mb_Text, $mb_Time = '') Local $StrnLenText = MsgLongestString($mb_Text) Local $NumberOfLines = (UBound(StringSplit($mb_Text, @CRLF)) - 1) * 5 Local $Button1Txt = "Ok" Local $Button2Txt = "Cancel" Local $MsgValue = 0 Local $Timer = '' $iMsgBox = GUICreate($mb_Title, $StrnLenText + 190, 100 + $NumberOfLines, -1, -1, 0x00400000, 0x00000008) $Label = GUICtrlCreateLabel($mb_Text, 60, 10) GUICtrlCreateIcon(@SystemDir & "\User32.dll", $mb_Icon, 10, 10, 35, 35) $OK = GUICtrlCreateButton($Button1Txt, 30 + ($StrnLenText / 2), 45 + $NumberOfLines, 60 + StringLen($Button1Txt), 25) $CANCEL = GUICtrlCreateButton($Button2Txt, 100 + ($StrnLenText / 2), 45 + $NumberOfLines, 60 + StringLen($Button2Txt), 25) $ControlPos = ControlGetPos($iMsgBox, $mb_Text, $OK) $EMAIL = _GuiCtrlCreateHyperlink("Email Us: Click to Email", $ControlPos[0], $ControlPos[1] - 15, 150, 25, 0x0000FF, 'E-Mail ' & _ "SomeAddress@SomeWhere.com" & " (Comments/Questions)") GUISetState() If $mb_Time <> '' Then $Timer = TimerInit() While 1 $imsg = GUIGetMsg() Select Case $imsg = $OK $MsgValue = 6 ExitLoop Case $imsg = $CANCEL $MsgValue = 7 ExitLoop Case $imsg = $EMAIL _INetMail($MAILTO, 'Regarding: ', '') Case $mb_Time <> '' If TimerDiff($Timer) / 1000 >= $mb_Time Then ExitLoop EndSelect WEnd GUIDelete($iMsgBox) Return $MsgValue EndFunc Func MsgLongestString($sText) Local $sSplit = StringSplit($sText, @CRLF) Local $Times = '' If Not @error Then ArraySortByLen($sSplit) If StringLen($sSplit[1]) <= 100 Then $Times = 2.25 If StringLen($sSplit[1]) >= 101 And StringLen($sSplit[1]) <= 150 Then $Times = 2.5 If StringLen($sSplit[1]) >= 151 And StringLen($sSplit[1]) <= 201 Then $Times = 3 If StringLen($sSplit[1]) >= 202 Then $Times = 3.25 Return Round(StringLen($sSplit[1])*$Times) Else If StringLen($sText) <= 100 Then $Times = 2.25 If StringLen($sText) >= 101 And StringLen($sText) <= 150 Then $Times = 2.5 If StringLen($sText) >= 151 And StringLen($sText) <= 201 Then $Times = 3 If StringLen($sText) >= 202 Then $Times = 3.25 Return Round(StringLen($sText)*$Times) EndIf EndFunc Func ArraySortByLen(ByRef $nArray, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i For $x = $i To UBound($nArray) - 1 If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x Next Local $HLD = $nArray[$i] $nArray[$i] = $nArray[$SE] $nArray[$SE] = $HLD Next EndFunc Func _GuiCtrlCreateHyperlink($S_TEXT, $I_LEFT, $I_TOP, _ $I_WIDTH = -1, $I_HEIGHT = -1, $I_COLOR = 0x0000FF, $S_TOOLTIP = '', $I_STYLE = -1, $I_EXSTYLE = -1) Local $I_CTRLID $I_CTRLID = GUICtrlCreateLabel($S_TEXT, $I_LEFT, $I_TOP, $I_WIDTH, $I_HEIGHT, $I_STYLE, $I_EXSTYLE) If $I_CTRLID <> 0 Then GUICtrlSetFont($I_CTRLID, -1, -1, 1) GUICtrlSetColor($I_CTRLID, $I_COLOR) GUICtrlSetCursor($I_CTRLID, 0) If $S_TOOLTIP <> '' Then GUICtrlSetTip($I_CTRLID, $S_TOOLTIP) EndIf EndIf Return $I_CTRLID EndFunc Edited June 18, 2021 by Melba23 Added code tags
Moderators Melba23 Posted June 18, 2021 Moderators Posted June 18, 2021 vavallone, When you post code in future please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
oli_the_true_one Posted June 18, 2021 Posted June 18, 2021 When you receive the GUIGetMsg() of your button, simply open a "mailto" URL like this: $sTo = "johnwick@domain.com" $sCC = "johnmcclane@domain.com" $sSubject = "The%20mail%20subject" $sBody = "The%20mail%20body" ShellExecute("mailto:" & $sTo & "?cc=" & $sCC & "&subject=" & $sSubject & "&body=" & $sBody) It will open the default email client and create a new mail pre-filled with the data inside the URL. Be aware that all the CRLF, space, etc are percent-encoded so you will have to adapt your data. There are some website that can generate the link for you, like this one: https://mailtolinkgenerator.com/
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