hero88 Posted November 25, 2011 Share Posted November 25, 2011 Hi I have a question with regards to using _InetMail, i want to use it to create a mail, that part is ok, and then I want to get to the window which gets created by it. If I use MsgBox(0,'E-Mail has been opened','The E-Mail has been opened and process identifier for the E-Mail client is ' & _INetMail($address, $subject, $body)), it gives me a number which varies whenever I run the program. Can I use this number in some way or convert it to something i can use with WinWaitActive? Link to comment Share on other sites More sharing options...
guinness Posted November 25, 2011 Share Posted November 25, 2011 One way (not how I would do it personally) is to look at the function _GetHwndFromPID() >>http://www.autoitscript.com/wiki/FAQ#How_can_I_get_a_window_handle_when_all_I_have_is_a_PID.3F to get the Window Handle from the PID, which is the random number you mentioned in your original post. 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 Link to comment Share on other sites More sharing options...
hero88 Posted November 25, 2011 Author Share Posted November 25, 2011 Thanks for the suggestions, i tried it and it didn't work, it just get stuck in a loop because the number i get from _InetMail is 1352 and in Winlist the number of the window that gets created is 0x00101680 I have attached my sample script expandcollapse popup#include <array.au3> $Address = 'me@work.dk' $Subject = 'Test' $body = 'Hello' $attachment = '' $ref=_INetMail($address, $subject, $body,$attachment) Sleep(2000) MsgBox(0,"ref",$ref,0) $hWnd1 = _GetHwndFromPID($ref) ;Function for getting HWND from PID Func _GetHwndFromPID($PID) $hWnd = 0 $winlist = WinList() _ArrayDisplay($winlist) Do For $i = 1 To $winlist[0][0] If $winlist[$i][0] <> "" Then $iPID2 = WinGetProcess($winlist[$i][1]) If $iPID2 = $PID Then $hWnd = $winlist[$i][1] ExitLoop EndIf EndIf Next Until $hWnd <> 0 Return $hWnd EndFunc;==>_GetHwndFromPID ; #FUNCTION# ==================================================================================================================== ; Name...........: _INetExplorerCapable ; Description ...: Convert a string to IE capable line ; Parameters ....: $s_IEString - String to convert to a capable IExplorer line ; Return values .: On Success - Returns the converted string ; On Failure - Blank String and @error = 1 ; Author ........: Wes Wolfe-Wolvereness <Weswolf at aol dot com> ; =============================================================================================================================== Func _INetExplorerCapable($s_IEString) If StringLen($s_IEString) <= 0 Then Return SetError(1, 0, '') Local $s_IEReturn Local $n_IEChar For $i_IECount = 1 To StringLen($s_IEString) $n_IEChar = '0x' & Hex(Asc(StringMid($s_IEString, $i_IECount, 1)), 2) If $n_IEChar < 0x21 Or $n_IEChar = 0x25 Or $n_IEChar = 0x2f Or $n_IEChar > 0x7f Then $s_IEReturn = $s_IEReturn & '%' & StringRight($n_IEChar, 2) Else $s_IEReturn = $s_IEReturn & Chr($n_IEChar) EndIf Next Return $s_IEReturn EndFunc ;==>_INetExplorerCapable ; #FUNCTION# ==================================================================================================================== ; Name...........: _INetMail ; Description ...: Open default mail client with given Address/Subject/Body ; Parameters ....: $s_MailTo - Address for E-Mail ; $s_Subject - Subject <Weswolf at aol dot com>of E-Mail ; $s_MailBody - Body of E-Mail ; Return values .: On Success - Process ID of e-mail client ; On Failure - Returns 0 and sets @error to non-zero. ; Author ........: Wes Wolfe-Wolvereness <Weswolf at aol dot com> ; =============================================================================================================================== Func _INetMail($s_MailTo, $s_MailSubject, $s_MailBody,$s_Attachment = "") Local $prev = Opt("ExpandEnvStrings", 1) Local $var = RegRead('HKCRmailtoshellopencommand', "") If $s_Attachment = '' then Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody))) Else Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody & '&attach=' & $s_Attachment))) EndIf Local $nError = @error, $nExtended = @extended Opt("ExpandEnvStrings", $prev) Return SetError($nError, $nExtended, $ret) EndFunc ;==>_INetMail Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2011 Share Posted December 1, 2011 (edited) Thanks for the suggestions, i tried it and it didn't work, it just get stuck in a loop because the number i get from _InetMail is 1352 and in Winlist the number of the window that gets created is 0x00101680 The PID is 1352 and 0x00101680 is the handle (HWND) of the window associated with that PID. Both the PID and HWND will change each time you run it. Use the HWND to identify the window. It can be used directly in the native functions in place of the window title parameter. For example: $sTitle = WinGetTitle($hWnd1) MsgBox(64, "Title", "The title is: " & $sTitle) Edited December 1, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
hero88 Posted December 1, 2011 Author Share Posted December 1, 2011 Okay, as far as I can tell from this is that there are no way I can find the window that _inetmail has created if there are other windows of the same kind open. I have found a way to give me the handle if there are no other emails open, but not if there is another email window open. I cannot use a search for the window because I cannot always be certain what text the window contains. Brief rundown of what I am trying to do, I have made a script which sends pdf files as email, the script gets the email address from the pdf file and sends it. In this case I know what text there are in the window and I can search for that. I have a problem when I just generate the email and allow them to change the text and attach files to it. I was hoping there were some sort of connection between the PID and the handle of the window so I could get the PID and use that to find the handle of window. $List = WinList("[CLASS:ATH_Note]") For $i = 1 to $List[0][0] $WindowsText = WinGetText($List[$i][1]) If stringinstr($WindowsText,$setupdata[3]) <> 0 Then ;~ msgbox(0,"Windows text",$WindowsText,0) $handle=($list[$i][1]) Else ;~ msgbox(0,"Window",_WinAPI_GetWindowtext($List[$i][1]),0) EndIf Next Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2011 Share Posted December 1, 2011 I think it might have been missed that one PID can have many windows open. The same PID may spawn a main GUI, a child GUI, and a pop up dialog. That function should have returned an array instead of returning the first match. Something like this (not tested): ; Function for getting HWNDs from PID ; Returns an array because one PID can have multiple windows open Func _GetHwndFromPID($PID) Local $aWinList = WinList() For $i = $winlist[0][0] To 1 Step -1 If WinGetProcess($aWinList[$i][1]) <> $PID Then _ArrayDelete($aWinList, $i) Next $aWinList[0][0] = UBound($aWinList) - 1 Return $aWinList EndFunc ;==>_GetHwndFromPID In addition, the parent process may have spawned one or more child processes, each with their own PIDs. So you see it isn't that simple. Something that may help would be checking the window class and other things that might be unique to the specific window. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
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