Jump to content
Sign in to follow this  
Bert

WinSetOnTop Problem

Recommended Posts

Bert

I have a viewer with 2 IE windows embedded in it. One of my beta testers discovered a problem where if one of the IE panes is clicked while another window is on top of it, like notepad, the viewer will not pull to the front. It will work fine if I click on the GUI. All the panes will pull to the front. If I click on one of the IE panes, nothing. You will see around line 248 where I tried to fix it, but I just made the problem worse.

I'm thinking maybe the way the panes are docked to the GUI should be the correct way to fix it, (best guess) but I have no idea how to solve the problem. HELP!

Edit: THis code is updated to show my current problem.

#include<GUIConstants.au3>

Opt("TrayIconDebug", 1)
Opt("TrayMenuMode",1)
_IEErrorHandlerRegister()
$oIE = _IECreateEmbedded()
$oIE2 = _IECreateEmbedded()
$w = @DesktopWidth
$h = @DesktopHeight
$h1 = $h - 150
$w1 = $w - 40
$w2 = $w - 60
$h2 = $h - 25
Dim $ininame, $IniButtonNames, $iniweb, $inioptions_Enable, $inioptions_apps, $x, $oIE1, $oIE2, $title
_inisettings()
$title = $ininame[1][1]
$gui = GUICreate($title, $w1, $h1, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_CLIPCHILDREN))
$label1 = GUICtrlCreateLabel("", 10, 68, $w - 60, $h - 230)
GUICtrlSetBkColor(-1, 0xff0000)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$label2 = GUICtrlCreateLabel("", 10, 40, $w1 - 20, 23)
GUICtrlSetBkColor(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$oIE2 = _IECreate("about:blank", 0, 0)
$oIE2.AddressBar = 0
$oIE2.MenuBar = 0
$oIE2.StatusBar = 0
$oIE2.ToolBar = 0
$uID2 = Random(1000, 100000000)
$oIE2.document.title = $uID2
WinWait($uID2)
$hoIE2 = WinGetHandle($uID2)
$pid2 = WinGetProcess($hoIE2)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hoIE2, "int", -16, "long", $WS_POPUP)
DllCall("user32.dll", "int", "SetParent", "hwnd", $hoIE2, "hwnd", $gui)


$oIE1 = _IECreate("about:blank", 0, 0)
$oIE1.AddressBar = 0
$oIE1.MenuBar = 0
$oIE1.StatusBar = 0
$oIE1.ToolBar = 0
$uID1 = Random(1000, 100000000)
$oIE1.document.title = $uID1
WinWait($uID1)
$hoIE1 = WinGetHandle($uID1)
$mainwwindow = WinGetHandle($title)
$pid1 = WinGetProcess($hoIE1)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hoIE1, "int", -16, "long", $WS_CHILD)
DllCall("user32.dll", "int", "SetParent", "hwnd", $hoIE1, "hwnd", $gui)

repositionIEs()
$GUI_Button_CTS_web = GUICtrlCreateButton($IniButtonNames[1][1], 10, 5, 70, 30)
GUICtrlSetResizing($GUI_Button_CTS_web, 8)
$GUI_Button_Depot_web = GUICtrlCreateButton($IniButtonNames[2][1], 85, 5, 80, 30)
GUICtrlSetResizing($GUI_Button_Depot_web, 8)
$GUI_Button_SC_web = GUICtrlCreateButton($IniButtonNames[3][1], 170, 5, 80, 30)
GUICtrlSetResizing($GUI_Button_SC_web, 8)
$GUI_Button_problem_board = GUICtrlCreateButton($IniButtonNames[4][1], 255, 5, 100, 30)
GUICtrlSetResizing($GUI_Button_problem_board, 8)
$GUI_Button_Service_request = GUICtrlCreateButton($IniButtonNames[5][1], 360, 5, 90, 30)
GUICtrlSetResizing($GUI_Button_Service_request, 8)
$GUI_Button_Field_operations = GUICtrlCreateButton($IniButtonNames[7][1], 595 - 140, 5, 90, 30)
GUICtrlSetResizing($GUI_Button_Field_operations, 8)
$GUI_Button_Document_Repository = GUICtrlCreateButton($IniButtonNames[8][1], 690 - 140, 5, 120, 30)
GUICtrlSetResizing($GUI_Button_Document_Repository, 8)
$GUI_Button_open_KB = GUICtrlCreateButton($IniButtonNames[9][1], 815 - 140, 5, 130, 30)
GUICtrlSetResizing($GUI_Button_open_KB, 8)
$GUI_Button_Search_sub = GUICtrlCreateButton($IniButtonNames[10][1], 950 - 140, 5, 130, 30)
GUICtrlSetResizing($GUI_Button_Search_sub, 8)
If $inioptions_Enable[1][1] = 1 Then Run(@ScriptDir & "\" & $inioptions_apps[1][1])
;-----------------
$helpitem   = TrayCreateItem("Help")
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")


AdlibEnable('_marqueecontrol', 15 * 60000)
HotKeySet("{F6}", "HotKeyFunc")
HotKeySet("{F4}", "HotKeyFunc")
;~ HotKeySet("^{F1}", "HotKeyFunc")
GUISetState()
WinActivate($gui)
$oIE1.visible = 1
_IEQuit($oIE2)
$oIE3 = _IENavigate($oIE1, $iniweb[1][1])
Sleep(5000)
$oIE2 = _IECreate("about:blank", 0, 0)
$oIE2.AddressBar = 0
$oIE2.MenuBar = 0
$oIE2.StatusBar = 0
$oIE2.ToolBar = 0
$uID2 = Random(1000, 100000000)
$oIE2.document.title = $uID2
WinWait($uID2)
$hoIE2 = WinGetHandle($uID2)
$pid2 = WinGetProcess($hoIE2)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hoIE2, "int", -16, "long", $WS_CHILD)
DllCall("user32.dll", "int", "SetParent", "hwnd", $hoIE2, "hwnd", $gui)
repositionIEs()
$oIE2.visible = 1
_marqueecontrol()
WinActivate($oIE1)
$x = 0
While 1
    $msg = GUIGetMsg()
    $trr = WinGetTitle($hoIE1)
    $trm = TrayGetMsg ()
    Select
        Case $trr = $ininame[3][1]
            GUICtrlDelete($oIE2)
            WinActivate($oIE1)
            _IENavigate($oIE1, $iniweb[1][1])
            ;Sleep(500)
            $oIE2 = _IECreate("about:blank", 0, 0)
            $oIE2.AddressBar = 0
            $oIE2.MenuBar = 0
            $oIE2.StatusBar = 0
            $oIE2.ToolBar = 0
            $uID2 = Random(1000, 100000000)
            $oIE2.document.title = $uID2
            WinWait($uID2)
            $hoIE2 = WinGetHandle($uID2)
            $pid2 = WinGetProcess($hoIE2)
            DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hoIE2, "int", -16, "long", $WS_POPUP)
            DllCall("user32.dll", "int", "SetParent", "hwnd", $hoIE2, "hwnd", $gui)
            repositionIEs()
            WinActivate($oIE1)
        Case $msg = $GUI_EVENT_CLOSE
            $t1 = $ininame[3][1]
            $t2 = $ininame[4][1]
            WinActivate($hoIE1)
            $trr = WinGetTitle($hoIE1)
            If $trr = $t1 Then ExitLoop
            If $trr = $t2 Then ExitLoop
            WinActivate($hoIE1)
            Sleep(20)
            Send("!u")
            Sleep(10)
            Send('e')
            Do
                $trr = WinGetTitle($hoIE1)
                Sleep(100)
            Until $trr = $t2 Or $trr = $t1
            ProcessClose($hoIE1)
            ProcessClose($hoIE2)
            sleep(500)
            $oIE2 = 0
            $oIE1 = 0
            Exit
        Case sizeEvent($msg)
            repositionIEs()
        Case $msg = $GUI_EVENT_RESIZED
            _ResizeLimit($title, "", $w - 100, $h - 100, @DesktopWidth, @DesktopHeight)
        Case $msg = $GUI_Button_CTS_web
            _IECreate($iniweb[2][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_Depot_web
            _IECreate($iniweb[3][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_SC_web
            _IECreate($iniweb[4][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_problem_board
            _IECreate($iniweb[5][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_Service_request
            _IECreate($iniweb[6][1])
            WinActivate($oIE1)
            WinActivate($oIE1)
        Case $msg = $GUI_Button_Field_operations
            _IECreate($iniweb[8][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_Document_Repository
            _IECreate($iniweb[9][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_open_KB
            _IECreate($iniweb[10][1])
            WinActivate($oIE1)
        Case $msg = $GUI_Button_Search_sub
            _IECreate($iniweb[11][1])
            WinActivate($oIE1)
    EndSelect
    sleep(1)
    Select
        Case $trm = $helpitem
            ShellExecute(@ScriptDir & "/help.doc")
        Case $trm = $aboutitem
            MsgBox(0, "About", $title, 5)
        Case $trm = $exititem   
                        $t1 = $ininame[3][1]
            $t2 = $ininame[4][1]
            WinActivate($hoIE1)
            $trr = WinGetTitle($hoIE1)
            If $trr = $t1 Then ExitLoop
            If $trr = $t2 Then ExitLoop
            WinActivate($hoIE1)
            Sleep(20)
            Send("!u")
            Sleep(10)
            Send('e')
            Do
                $trr = WinGetTitle($hoIE1)
                Sleep(100)
            Until $trr = $t2 Or $trr = $t1
            ProcessClose($hoIE1)
            ProcessClose($hoIE2)
            sleep(500)
            $oIE2 = 0
            $oIE1 = 0
            Exit
    EndSelect       
WEnd
ProcessClose($pid1)
ProcessClose($pid2)
sleep(1000)
$oIE2 = 0
$oIE1 = 0
Exit
Func _ResizeLimit($title, $Text = "", $MinWidth = 150, $MinHeight = 150, $MaxWidth = @DesktopWidth, $MaxHeight = @DesktopHeight)
    If Not WinExists($title, $Text) Then Return SetError(1, 0, -1)
    Local $PosArr = WinGetPos($title, $Text), $xPos, $yPos, $wPos, $hPos
    If IsArray($PosArr) Then
        $xPos = $PosArr[0]
        $yPos = $PosArr[1]
        $wPos = $PosArr[2]
        $hPos = $PosArr[3]
        If ($wPos <> $MinWidth And $hPos <> $MinHeight) Or ($wPos <> $MaxWidth And $hPos <> $MaxHeight) Then
            If $wPos < $MinWidth And $hPos < $MinHeight Then WinMove($title, $Text, $xPos, $yPos, $MinWidth, $MinHeight)
            If $wPos < $MinWidth And $hPos >= $MinHeight Then WinMove($title, $Text, $xPos, $yPos, $MinWidth, $hPos)
            If $wPos >= $MinWidth And $hPos < $MinHeight Then WinMove($title, $Text, $xPos, $yPos, $wPos, $MinHeight)
            If $wPos > $MaxWidth And $hPos > $MaxHeight Then WinMove($title, $Text, $xPos, $yPos, $MaxWidth, $MaxHeight)
            If $wPos > $MaxWidth And $hPos <= $MaxHeight Then WinMove($title, $Text, $xPos, $yPos, $MaxWidth, $hPos)
            If $wPos <= $MaxWidth And $hPos > $MaxHeight Then WinMove($title, $Text, $xPos, $yPos, $wPos, $MaxHeight)
        EndIf
    EndIf
EndFunc   ;==>_ResizeLimit
Func repositionIEs()
    $pos1 = ControlGetPos($gui, "", "Static1")
    $pos2 = ControlGetPos($gui, "", "Static2")
    WinMove($hoIE1, "", $pos1[0], $pos1[1], $pos1[2], $pos1[3])
    WinMove($hoIE2, "", $pos2[0], $pos2[1], $pos2[2], $pos2[3])
EndFunc   ;==>repositionIEs
Func sizeEvent($event)
    If $event = $GUI_EVENT_MAXIMIZE Or _
            $event = $GUI_EVENT_MINIMIZE Or _
            $event = $GUI_EVENT_RESTORE Or _
            $event = $GUI_EVENT_RESIZED Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>sizeEvent
Func _marqueecontrol()
    Dim $aLinks[11]
    Local $htmlfile, $makehtml
    $htmlfile = @ScriptDir & "\bin\html.txm" 
    FileOpen($htmlfile, 8 + 2)
    FileWrite($htmlfile, "")
    FileClose($htmlfile)
    $makehtml = FileOpen($htmlfile, 8 + 1)
    $oIEb = _IECreate($iniweb[5][1], 0, 0)
    $colTables = _IETableGetCollection($oIEb, 1)
    $avTable = _IETableWriteToArray($colTables)
    $oLinks = _IELinkGetCollection($oIEb)
    $iNumLinks = @extended
    $sHTML = ""
    $sHTML &= '<body scroll=no topmargin=0 BGCOLOR=LTGREEN>' 
    $sHTML &= '<marquee behavior=scroll direction=left scrolldelay=2 scrollamount=2 onmouseover="this.stop()" onmouseout="this.start()") >' 
    $sHTML &= '<span style="background-color: #FFFFFF">******** Solution Center Problem Board Marquee ********</span>                        ' 
    For $i = 0 To $iNumLinks
        $sHTML &= '                      #' & $i + 1 & '  ' 
        $sHTML &= '<span style="background-color: #FFFF00"> <B>Last Update: </b>' 
        $sHTML &= '<a target="_blank" href= "' & $oLinks.item ($i + 3).href & '">' & $avTable[0][$i + 1] & "</a>         <b>Master#</b> " & $avTable[1][$i + 1]
        $sHTML &= "       <b>Description: </b> " & $avTable[2][$i + 1]
        $sHTML &= "       <b>Region:</b> " & $avTable[3][$i + 1]
        $sHTML &= "       <b>Resolve Date:</b> " & $avTable[4][$i + 1] & '</span>' 
        If $i = 9 Then ExitLoop
    Next
    $sHTML &= '                                </marquee></body>' 
    $writehtml = FileWrite($htmlfile, $sHTML)
    $fr = FileRead(@ScriptDir & "\bin\html.txm")
    $makemarquee = _IEDocWriteHTML($oIE2, $fr)
    FileClose($htmlfile)
    _IEQuit($oIEb)
    WinActivate($oIE1)
EndFunc   ;==>_marqueecontrol
Func _inisettings()
    $iniweb = IniReadSection(@ScriptDir & "\bin\cfgusd.cud", "1")
    $IniButtonNames = IniReadSection(@ScriptDir & "\bin\cfgusd.cud", "2")
    $ininame = IniReadSection(@ScriptDir & "\bin\cfgusd.cud", "3")
    $inioptions_apps = IniReadSection(@ScriptDir & "\bin\options.cud", "1")
    $inioptions_Enable = IniReadSection(@ScriptDir & "\bin\options.cud", "2")
    #cs
        iniweb
        1= Main USD
        2= CTS portal
        3= Depot
        4= SC - internal
        5= problem board
        6= Service request
        7= SR - archive
        8= Field Operations
        note - make button names changeable? offer choices?
    #ce
EndFunc   ;==>_inisettings
Func HotKeyFunc()
    Opt("WinTitleMatchMode", 2)
    If WinActive("Update Incident - Unicenter ServicePlus Service Desk") Then
        Switch @HotKeyPressed
            Case "{F4}" 
                If WinExists("USD Configuration Item Tool", "Help") = 0 Then Run(@ScriptDir & "/CIT.exe")
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
    If WinActive("Update Request - Unicenter ServicePlus Service Desk") Then
        Switch @HotKeyPressed
            Case "{F4}" 
                If WinExists("USD Configuration Item Tool", "Help") = 0 Then Run(@ScriptDir & "/CIT.exe")
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
    If WinActive("Create New Incident") Then
        Switch @HotKeyPressed
            Case "{F4}" 
                If WinExists("USD Configuration Item Tool", "Help") = 0 Then Run(@ScriptDir & "/CIT.exe")
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
    If WinActive("Create New Request") Then
        Switch @HotKeyPressed
            Case "{F4}" 
                If WinExists("USD Configuration Item Tool", "Help") = 0 Then Run(@ScriptDir & "/CIT.exe")
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
    If @HotKeyPressed = "{F6}"  Then
        If WinExists("QuickPaste 2.0", "Paste") = 0 Then
            Run(@ScriptDir & "/quickpaste2_0.exe")
        EndIf
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
EndFunc   ;==>HotKeyFunc
Edited by Volly

Share this post


Link to post
Share on other sites
Bert

I'm digging this one up for my fix caused my alt key to be stuck. Any ideas on this one? When I tried to tweak which IE window to make a child and the other popup, it caused the script to become unstable. I know I can just go with one embedded IE window, (ditch the marquee) and everything would be stable, but the marquee is something I like to keep. In the current form, the marquee has hyperlinks, and will stop scrolling when the mouse hovers over it. I'm not sure of a better way to make a marquee that does what this one does.

Thoughts?

Share this post


Link to post
Share on other sites
SmOke_N

I'm digging this one up for my fix caused my alt key to be stuck. Any ideas on this one? When I tried to tweak which IE window to make a child and the other popup, it caused the script to become unstable. I know I can just go with one embedded IE window, (ditch the marquee) and everything would be stable, but the marquee is something I like to keep. In the current form, the marquee has hyperlinks, and will stop scrolling when the mouse hovers over it. I'm not sure of a better way to make a marquee that does what this one does.

Thoughts?

Volly... I'm curious (I've never tried to be honest), but did you try GUISetStyle() before just invoking SetWindowLong DLL call?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Bert

The code in the first post is the latest I have in trying to solve the problem. I wish I included the ini in my post for troubleshooting purposes. The code I got to do the duel IE embedded isn't mine. I've been searching to find who did it. (I think it was Lod3n) If I remember right, he had a bitch of a time getting it to work, and he said something along the lines of it wasn't that stable. I guess I've been the tweaker of it since then.

SmoKe_N, I see what you are talking about. :) This may solve the problem. I won't be able to test until monday when I get back to the office. Thanks for the info.

Share this post


Link to post
Share on other sites
Bert

In reading about GUISetStyle, I see how it works with the GUI, but what about embedded IE windows. I tried what you suggested, and it failed somewhat awful. I started to have multiple IE windows opening. I may need to scrap the duel IE window thing and figure another method of handling the marquee. I think the duel IE window is the source of all my troubles, and trying a different approtch may solve it.

Edited by Volly

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.