Sign in to follow this  
Followers 0
SmiLe

Disabling GUI when a dialog is open

9 posts in this topic

Hi all!

I want to disable all controls on my GUI when a dialog like FileOpenDialog or FileSelectFolder is open. I think there's something I am doing wrong...

When I use GUISetState(@SW_DISABLE, $MyGUI) and GUISetState(@SW_ENABLE, $MyGUI), the GUI loses control. If I use WinActivate($MyGUI) after GUISetState(@SW_ENABLE, $MyGUI), the redrawing of controls is visible.

Here is an example:

#include <GUIConstants.au3>

$MyGUI = GUICreate("My GUI")
$Button1 = GUICtrlCreateButton("Test 1", 10, 30, 70)
$Button2 = GUICtrlCreateButton("Test 2", 100, 30, 70)
$Button3 = GUICtrlCreateButton("Test 3", 190, 30, 70)

GUISetState ()

While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
        
    Case $msg = $Button1
     ; In this case, $MyGUI is always enabled.
      FileOpenDialog("No matter what you do...", "", "(*.*)")
        
    Case $msg = $Button2
     ; In this case, the problem is that $MyGUI loses focus
     ; when you close the FileOpen Dialog.
      GUISetState(@SW_DISABLE, $MyGUI)
      FileOpenDialog("Press Cancel...", "", "(*.*)")
      GUISetState(@SW_ENABLE, $MyGUI)
        
    Case $msg = $Button3
     ; Now when you close the FileOpen Dialog, the redrawing of controls
     ; on $MyGUI is visible. Is there a way to avoid this?
      GUISetState(@SW_DISABLE, $MyGUI)
      FileOpenDialog("Press Cancel...", "", "(*.*)")
      GUISetState(@SW_ENABLE, $MyGUI)
      WinActivate($MyGUI)
  EndSelect
WEnd

The same problem occurs if I run the script with SciTe or if I compile it. Any idea?

Thanks!

Share this post


Link to post
Share on other sites



This might help...

#include <GUIConstants.au3>

$MyGUI = GUICreate("My GUI")
$Button1 = GUICtrlCreateButton("Test 1", 10, 30, 70)
$Button2 = GUICtrlCreateButton("Test 2", 100, 30, 70)
$Button3 = GUICtrlCreateButton("Test 3", 190, 30, 70)

GUISetState ()

While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
        
    Case $msg = $Button1
     ; In this case, $MyGUI is always enabled.
      FileOpenDialog("Try Button 2 or 3...", "", "(*.*)")
        
    Case $msg = $Button2
     ; In this case, the problem is that $MyGUI loses focus
     ; when you close the FileOpen Dialog.
      GUICtrlSetState($Button1, $GUI_DISABLE)
      GUICtrlSetState($Button2, $GUI_DISABLE)
      GUICtrlSetState($Button3, $GUI_DISABLE)
      FileOpenDialog("Disabeled all controls on GUI...", "", "(*.*)")
      GUICtrlSetState($Button1, $GUI_ENABLE)
      GUICtrlSetState($Button2, $GUI_ENABLE)
      GUICtrlSetState($Button3, $GUI_ENABLE)
        
    Case $msg = $Button3
     ; Now when you close the FileOpen Dialog, the redrawing of controls
     ; on $MyGUI is visible. Is there a way to avoid this?
      GUISetState(@SW_HIDE, $MyGUI)
      FileOpenDialog("Hide the GUI totally...", "", "(*.*)")
      GUISetState(@SW_SHOW, $MyGUI)
      WinActivate($MyGUI)
  EndSelect
WEnd

Cheers

Share this post


Link to post
Share on other sites

There must be a way to do this right, but we may not have access to the correct method in AutoIt. Check out Notepad's file dialog: If you try to click on the main window, it fails and the dialog flashes, and when the dialog is closed, the main window is properly focused and doesn't have that weird redrawing delay.

Share this post


Link to post
Share on other sites

There must be a way to do this right, but we may not have access to the correct method in AutoIt. Check out Notepad's file dialog: If you try to click on the main window, it fails and the dialog flashes, and when the dialog is closed, the main window is properly focused and doesn't have that weird redrawing delay.

Yes, the user should not be able to use the main GUI until the dialog is closed. Perhaps there is no way to do the same thing in AutoIt without the "redrawing effect", except for MsgBox():

#include <GUIConstants.au3>

$MyGUI = GUICreate("My GUI")
$Button = GUICtrlCreateButton("MsgBox", 10, 30, 70)

GUISetState ()

While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      ExitLoop

    Case $msg = $Button
      MsgBox(262144+8192, "Top-most + task modal", "You can't use the main GUI!")
  EndSelect
Wend

Share this post


Link to post
Share on other sites

There must be a way to do this right, but we may not have access to the correct method in AutoIt. Check out Notepad's file dialog: If you try to click on the main window, it fails and the dialog flashes, and when the dialog is closed, the main window is properly focused and doesn't have that weird redrawing delay.

How about something like this:

#include <GUIConstants.au3>

Global $hGUI, $iButton

$hGUI    = GUICreate("File Dialog", 400, 300)
$iButton = GUICtrlCreateButton("Press Me", 4, 4, 75, 25)
GUISetState()

while 1
  Switch GUIGetMsg()
    case $iButton
      GUISetState(@SW_DISABLE, $hGUI)
      FileOpenDialog("Press Cancel...", "", "(*.*)")
      GUISetState(@SW_ENABLE , $hGUI)
      DllCall("User32.dll", "hwnd", "SetFocus", "hwnd", $hGUI)
    case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
wend

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

How about something like this:

GUISetState(@SW_ENABLE , $hGUI)
      DllCall("User32.dll", "hwnd", "SetFocus", "hwnd", $hGUI)
This solves the redrawing problem, thank you!

Share this post


Link to post
Share on other sites

This solves the redrawing problem, thank you!

Maybe so, but try this: Open some other windows (if you're reading this now you should at least have a browser window open), then run the program and go through the dialog. The main window pops behind any other windows for about half a second. If anything, it's worse than just having the controls disappear.

Share this post


Link to post
Share on other sites

Maybe so, but try this: Open some other windows (if you're reading this now you should at least have a browser window open), then run the program and go through the dialog. The main window pops behind any other windows for about half a second. If anything, it's worse than just having the controls disappear.

Works just fine on my machine. If I select a file or press Cancel, the main window appears and stays on top.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Works just fine on my machine. If I select a file or press Cancel, the main window appears and stays on top.

That's weird... it works fine for me too, when I'm on my regular XP desktop. When I made that post, and saw the half-second pop-behind, I was on my Vista machine. Under XP there is just a brief flicker, no pop-behind at all. Strange thing is, I remember seeing this exact same pop-behind on XP before, under similar conditions. The plot thickens. :shocked:

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