Jump to content
horrscht6

Problem with window activation of a existing process window

Recommended Posts

horrscht6

Hello together,

I am searching for hours in the web and this forum too but no articles helps really.

Issue:

  1. In the background Thunderbird is running and receives mails and fax (as PDF mails).
  2. If a specific mail will be received and the rules detect this mail an external program will be executed.
  3. The external program is the AutoIt script. Execution will be okay but the result is not okay:
  4. If the button $btnShowMailProg is pressed: The Thunderbird should appear to show the important mail.
    ==> This is the problem.
    I have tried several times and different code examples but Thunderbird will not be shown in the front.

Who can help me or show a code example which shows an already in background running program active again in the foreground?

Thanks in advance for your help.

Matthias

Sorry, the GUI is for a german office usage and therefore the text messages are in german. But this doesn't matter for the asked issue. ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

$Form1_1 = GUICreate("BENACHRICHTIGUNG: Wichiges FAX eingegangen", 422, 220, -1, -1,$WS_EX_TOPMOST)
$Label1 = GUICtrlCreateLabel("Diese Benachrichtigung wird angezeigt, weil die Filter-Regeln", 24, 18, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$Label2 = GUICtrlCreateLabel("im Email-Programm den Eingang eines wichtigen FAX oder", 24, 38, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$Label3 = GUICtrlCreateLabel("einer wichtigen EMAIL festgestellt haben.", 24, 58, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$btnShowMailProg = GUICtrlCreateButton("Email-Programm in den Vordergrund bringen", 24, 92, 355, 33, 0)
GUICtrlSetFont(-1, 10, 700 , 0, "Arial")
$btnClose = GUICtrlCreateButton("Dieses Fenster schließen", 24, 135, 203, 41, 0)
GUISetState(@SW_SHOW)
$hWnd = WinGetHandle("[ACTIVE]")
WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnClose
            Exit
        case $btnShowMailProg
            if ProcessExists("thunderbird.exe") Then
                $hWnd2 = ProcessExists("thunderbird.exe")
                WinSetOnTop($hWnd, "", $WINDOWS_NOONTOP )
                GUISetState(@SW_HIDE)
                $return0 = WinActivate($hWnd2)
                $return1 = WinSetState($hWnd2, "", @SW_MAXIMIZE)
                $return2 = WinSetState($hWnd2, "", @SW_SHOW)
                MsgBox (0, "DEBUG-Info", "$hWnd2=" & $hWnd2 & @CRLF & "$return0=" & $return0 & @CRLF & "$return1=" & $return1 & @CRLF & "$return2=" & $return2 )
                If  Not WinActive($hWnd2) Then
                    MsgBox (0, "DEBUG-Info", "Thunderbird manuell öffnen!" )
                    Run("thunderbird.exe")
                    WinActivate($hWnd2)
                    WinSetState($hWnd2, "", @SW_MAXIMIZE)
                    WinSetState($hWnd2, "", @SW_SHOW)
                EndIf
                MsgBox (0,"INFO","Programm wird beendet.")
            Else
                MsgBox (0, "DEBUG-Info", "Thunderbird manuell öffnen!" )
            EndIf
            Exit
    EndSwitch
WEnd
Exit

 

Share this post


Link to post
Share on other sites
horrscht6

@Admins: Sorry, I have chosen the wrong area for my issue. Can it be copied to "AutoIt Help and Support" ?

Share this post


Link to post
Share on other sites
horrscht6

Problem is solved now. If it's interesting for someone... here is my code solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

$Form1_1 = GUICreate("BENACHRICHTIGUNG: Wichiges FAX eingegangen", 422, 220, -1, -1,$WS_EX_TOPMOST)
$Label1 = GUICtrlCreateLabel("Diese Benachrichtigung wird angezeigt, weil die Filter-Regeln", 24, 18, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$Label2 = GUICtrlCreateLabel("im Email-Programm den Eingang eines wichtigen FAX oder", 24, 38, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$Label3 = GUICtrlCreateLabel("einer wichtigen EMAIL festgestellt haben.", 24, 58, 390, 17)
GUICtrlSetFont(-1, 10, 400 , 0, "Arial")
$btnShowMailProg = GUICtrlCreateButton("Email-Programm in den Vordergrund bringen", 24, 92, 355, 33, 0)
GUICtrlSetFont(-1, 10, 700 , 0, "Arial")
$btnClose = GUICtrlCreateButton("Dieses Fenster schließen", 24, 135, 203, 41, 0)
GUISetState(@SW_SHOW)
$hWnd = WinGetHandle("[ACTIVE]")
WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnClose
            Exit
        case $btnShowMailProg
            if ProcessExists("thunderbird.exe") Then
                $aWinList = WinList("[REGEXPTITLE:(?i)(.*Mozilla Thunderbird.*)]")
                if $aWinList[0][0]>=1 Then
                    $WinTitle = $aWinList[1][0]
                    $returnA = WinActivate($WinTitle)
                EndIf
            EndIf
            Exit
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • argumentum
      By argumentum
      So, Thunderbird does not have a minimize to tray option. Here is a handler to do just that.
      More info. at https://www.autoitscript.com/forum/topic/187431-thundrebird-to-tray/
    • argumentum
      By argumentum
      gmail does not allow to things that a regular email client do, so, thunderbird is a good option.
      But ThunderBird does not have a minimize to tray option. There are plugins but I read around forums and they have problems depending on the version, so, I wrote a non-plugin solution to my wanting.
      Sources and compiled executable files are at https://www.autoitscript.com/forum/files/file/438-thundrebirdtotray/
      The tray icons are:
      Pruple = ThunderBird is not running. A double click will run it.
      Blue = ThunderBird is visible. A double click will hide it
      Green = ThunderBird is hidden. A double click will unhide it.
      Right click will show a menu to:
      Minimize to tray.
      Show/hide ( just as a double click on the tray icon would )
      Compose a new email.
      Browse some folders that may be of interest.
      In new version 0.2017.3.11
      added: command line options /RunAs "UserName" [/minimized] [/hidden].

        the user/password is saved encrypted to the ini file to each user's configuration.
      added: -purgecaches as its needed from time to time to clear the javascript cache.
      fixed: "dyslexia induced" misnamed files.
      added: browse startup folders
       
      PS: I run this from "C:\Program Files (x86)\Mozilla Thunderbird" but I guess you can run it from anywhere. The features implemented are those to fit my needs. If you'd like to add a feature, I could go the extra mile line of code and add it. You may even make me aware of things that can be done, and be of use, that I did not know at the time of coding this.
    • Akshay07
      By Akshay07
      Hi all,

      I am trying to achieve the following:

      When an email is received with a specific subject field, I want to trigger an autoit script.
      I am not sure how to do the first part (monitor emails and check for the email subject filed, or even better, email content).
      I have no specific requisites about the email client, it could be outlook, thunderbird, or other. It would be okay as well to read the email header only from an online gmail account.

      I know it is possible with a gmail account (there are severals widgets that can do that) but I was wondering if this can be done using autoit ? My programming knowledge is very poor, and I doubt I can go through the use of Google APIs for this.
×