Sign in to follow this  
Followers 0
GMib

Create Gui Without lose focus ?

12 posts in this topic

#1 ·  Posted (edited)

I want create gui when selection change in win explorer listview, but GUICreate break double click on explorer file. i think it's because explorer windows lose focus.

exemple :

#include <WindowsConstants.au3>

$rep_videos = "H:\Videos"
$nb_lettre_videos = StringLen($rep_videos)
Global $aff = 0
global $editsyn,$GuiActor,$size,$form1,$sel

While 1
    $wlist = WinList("[CLASS:CabinetWClass]")
    For $i = 1 To $wlist[0][0]
        If StringLeft(ControlGetText($wlist[$i][1], "", "[CLASS:Edit]"), $nb_lettre_videos) = $rep_videos Then
            $hwd = $wlist[$i][1]
            $size = WinGetPos($wlist[$i][1])
            vidzdetected($hwd)

        EndIf
    Next
    Sleep(100)
WEnd

Func vidzdetected($hwd)
    ;Opt("GUIOnEventMode", 1)
    While 1
        $edit = ControlGetText($hwd, "", "[CLASS:Edit]")
        $var1 = ControlListView($hwd, "", "SysListView321", "GetSelected", 0)
        $sel = ControlListView($hwd, "", "SysListView321", "GetText", $var1, 0)
        If Not ($sel == $aff) Then disp($sel)
        If Not WinExists($hwd) Or StringLeft($edit, $nb_lettre_videos) <> $rep_videos Then
            if WinExists("Vidz Film") then GUIDelete($form1)
            Return
        EndIf
        $size = WinGetPos($hwd)
        If WinActive($hwd) and not BitAnd(WinGetState($hwd),32) Then WinMove("Vidz Film", "", $size[0], $size[1] + $size[3])
        if WinActive($hwd) and BitAnd(WinGetState($hwd),32) Then WinMove("Vidz Film", "", $size[2]-730, $size[1] + $size[3]-240)
        Sleep(50)
    WEnd
EndFunc   ;==>creategui

func fexit()
    Exit
EndFunc

Func disp($sel)
    if WinExists("Vidz Film") then GUIDelete($form1)
    $form1 = GUICreate("Vidz Film", 715, 207, $size[0], $size[1] + $size[3], BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $hwd)
    GUISetState(@SW_SHOWNOACTIVATE, $form1)
    $aff = $sel
    ;WinActivate($hwd)
EndFunc   ;==>disp

someone has solution ?

thx

Edited by GMib

Share this post


Link to post
Share on other sites



Maybe if you create the window with the extended style $WS_EX_NOACTIVATE.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Another way is to pre-create the GUI and hide it. Then when you need it show it with

GUISetState(@SW_SHOWNOACTIVATE)

Share this post


Link to post
Share on other sites

Another way is to pre-create the GUI and hide it. Then when you need it show it with

GUISetState(@SW_SHOWNOACTIVATE)

yes, but lot of control must created in disp() func depend of file selected.

i searched for function for remove all control in gui, but not find.

Share this post


Link to post
Share on other sites

Here is an example you can use to delete all or some of the controls in a GUI. Pass the function the last control which you want deleted...default is the last created control

#include <GUIConstantsEx.au3>


Example()

Func Example()
    Local $widthCell, $msg, $iOldOpt
    
    GUICreate("My GUI")  ; will create a dialog box that when displayed is centered

    GUISetHelp("notepad")  ; will run notepad if F1 is typed
    $iOldOpt = Opt("GUICoordMode", 2)

    $widthCell = 70
    GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $widthCell) ; first cell 70 width
    GUICtrlCreateLabel("Line 2 Cell 1", -1, 0) ; next line
    GUICtrlCreateLabel("Line 3 Cell 2", 0, 0) ; next line and next cell
    GUICtrlCreateLabel("Line 3 Cell 3", 0, -1) ; next cell same line
    GUICtrlCreateLabel("Line 4 Cell 1", -3 * $widthCell, 0) ; next line Cell1

    GUISetState()      ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
sleep(2000)
deletecontrols()
sleep(3000)
EndFunc   ;==>Example

Func deletecontrols($last=-1)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle($last))
    For $i = 3 To $aLastID[0]
        GUICtrlDelete($i)
    Next
EndFunc

Share this post


Link to post
Share on other sites

Maybe save current app/window that is active to a variable, do GUICreate, then restore focus to the app/window that had focus before?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Here is an example you can use to delete all or some of the controls in a GUI. Pass the function the last control which you want deleted...default is the last created control

if last control is ie embed function don't work,i put label after embed and it's work

this fonction remove all controls of all gui ? if i have 3 gui it remove all controls on 3 gui ?

why 3 in For $i = 3 To $aLastID[0] ?

thx for your help

Share this post


Link to post
Share on other sites

if last control is ie embed function don't work,i put label after embed and it's work

this fonction remove all controls of all gui ? if i have 3 gui it remove all controls on 3 gui ?

why 3 in For $i = 3 To $aLastID[0] ?

thx for your help

You would have to do a guiswitch to get to the right gui. Either build it into the function or make sure to switch to the correct gui before running the function. If you have multiple gui's it may be important to specify the last control. I'm not sure I haven't used it in that situation. So 3 gui's you would have to use it 3 times.

It doesn't matter if you want to start $i at 1. I believe that 1 and 2 are the GUI itself and couldn't be deleted using guictrldelete. That is why it starts at 3.

I got this idea from the GUISetControlsVisible($hWnd) function that is available on the forum

Share this post


Link to post
Share on other sites

Even with last control the fonction remove all control on all gui :mellow:

Share this post


Link to post
Share on other sites

Okay, this version will only delete controls for a specific gui which must be specified

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>
Example1()
Example2()

sleep(2000)
deletecontrols($close, $gui2)
sleep(2000)
deletecontrols($n2,$gui1)
sleep(3000)

;example1 ---------------------------
Func Example1()
    Local $icon, $n1, $n2, $msg
    global $gui1=GUICreate(" My GUI Icons", 250, 250,0)
    Global $icon = GUICtrlCreateIcon("shell32.dll", 10, 20, 20)
    $n1 = GUICtrlCreateIcon(@WindowsDir & "\cursors\horse.ani", -1, 20, 40, 32, 32)
    Global $n2 = GUICtrlCreateIcon("shell32.dll", 7, 20, 75, 32, 32)
    GUISetState()

EndFunc   ;==>Example1



; example2 ---------------------------
Func Example2()
Global $gui2=GUICreate("My GUI list",350,250,350) ; will create a dialog box that when displayed is centered

   Global $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
    GUICtrlSetLimit(-1, 200)    ; to limit horizontal scrolling

   Global $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)


    GUISetState(@SW_SHOW)

    ; Run the GUI until the dialog is closed

EndFunc   ;==>Example2


Func deletecontrols($last=-1,$guiname="")
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle($last))
    For $i = 0 To $aLastID[0]
        if WinGetHandle($guiname)=_WinAPI_GetParent(GUICtrlGetHandle($i)) Then
        GUICtrlDelete($i)
        EndIf
    Next
EndFunc

Share this post


Link to post
Share on other sites

Okay, this version will only delete controls for a specific gui which must be specified

Yessss, thanks you very much, it's work very well :mellow:

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