Sign in to follow this  
Followers 0
StMaSi

Forcing Windows OnTop...

3 posts in this topic

#1 ·  Posted

Trying to create a form that displays on top of all other windows. That part I have. However, within this form, there is an IE control that displays an animated GIF. That part I have. The problem is once I add the IE control to the form, the form no longer stays on top. Here's what I'm working with...

#include <AutoItConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <IE.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $oIE
Global $WINDOWS_ONTOP = 1
$Form1 = GUICreate("Test", 521, 376, -1, -1, $WS_EX_TOPMOST, $WM_SYSCOMMAND)
_Main()
GUISetState(@SW_SHOW)
OnTop()
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Main()
    Local $pheight = 129, $pwidth = 129, $oIE, $GUIActiveX, $gif
    $gif = @ScriptDir & "\anim.gif"
    If @error Then Exit
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)
    $oIE = ObjCreate("Shell.Explorer.2")
    $GUIActiveX = GUICtrlCreateObj($oIE, 275, 125, $pwidth, $pheight)
    $oIE.navigate ("about:blank")
    While _IEPropertyGet($oIE, "busy")
        Sleep(100)
    WEnd
    $oIE.document.body.background = $gif
    $oIE.document.body.scroll = "no"
    $oIE.document.body.style.border = "0"
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
    OnTop2()
EndFunc
Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc
Func On_WM_SYSCOMMAND($Form1, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
    Return $GUI_RUNDEFMSG
EndFunc
Func OnTop()
    Global $Disp = WinGetHandle($Form1)
    WinSetOnTop($Disp,"",$WINDOWS_ONTOP)
EndFunc
Func OnTop2()
    Global $Disp2 = WinGetHandle($oIE)
    WinSetOnTop($Disp2,"",$WINDOWS_ONTOP)
EndFunc

Any suggestions?

Thanx.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

2 hours ago, StMaSi said:

Any suggestions?

A lot. In fact, too much.
Do you know the 'spot the difference' game ? I suggest that you compare your code with the one below, then spot the differences, then run into the helpfile to understand why some things work and other ones don't  :)

#include <AutoItConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <IE.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
Global $oIE
Global $WINDOWS_ONTOP = 1
$Form1 = GUICreate("Test", 521, 376, -1, -1, -1, $WS_EX_TOPMOST)
_Main()
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _Main()
    Local $pheight = 129, $pwidth = 129, $oIE, $GUIActiveX, $gif
    $gif = @ScriptDir & "\anim.gif"
    If @error Then Exit
    _GetGifPixWidth_Height($gif, $pwidth, $pheight)
    $oIE = ObjCreate("Shell.Explorer.2")
    $GUIActiveX = GUICtrlCreateObj($oIE, 275, 125, $pwidth, $pheight)
    $oIE.navigate ("about:blank")
    While _IEPropertyGet($oIE, "busy")
        Sleep(100)
    WEnd
    $oIE.document.body.background = $gif
    $oIE.document.body.scroll = "no"
    $oIE.document.body.style.border = "0"
EndFunc
Func _GetGifPixWidth_Height($s_gif, ByRef $pwidth, ByRef $pheight)
    If FileGetSize($s_gif) > 9 Then
        Local $sizes = FileRead($s_gif, 10)
        ConsoleWrite("Gif version: " & StringMid($sizes, 1, 6) & @LF)
        $pwidth = Asc(StringMid($sizes, 8, 1)) * 256 + Asc(StringMid($sizes, 7, 1))
        $pheight = Asc(StringMid($sizes, 10, 1)) * 256 + Asc(StringMid($sizes, 9, 1))
        ConsoleWrite($pwidth & " x " & $pheight & @LF)
    EndIf
EndFunc
Func On_WM_SYSCOMMAND($Form1, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
    Return $GUI_RUNDEFMSG
EndFunc

 

Edited by mikell

Share this post


Link to post
Share on other sites

#3 ·  Posted

Yes, I see it now. Jeez. I've re-worked this so many times, can't believe I missed those extra bits at the end of the _Main function. Thank you!!!

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  
Followers 0