Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

(Fixed) GUI shortly hides on en/disabling WS_EX_ACCEPTFILES


  • Please log in to reply
9 replies to this topic
fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
See this example script (On Win7 32Bit):
Gui, Add, Button, gButton, Test
Gui, Show, Autosize
return

Button:
if(state)
	Gui +E0x10
else
	Gui -E0x10
state := !state
return

On my machine this makes the taskbar icon disappear for a short moment, then it will reappear. In addition, the program will lose focus and will sometimes not regain it. Is this behavior fixable?
I'm trying to avoid setting this style too often, but I need to do so at one place while my GUI is visible.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Has anyone been able to reproduce this bug?

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Does it happen using WinSet as well?
Gui, Add, Button, gButton, Test

Gui, Show, AutoSize

Gui,+LastFound

hwnd:=WinExist()

return



Button:

if(state)

   WinSet,ExStyle, +0x10,ahk_id %hwnd%

else

   WinSet,ExStyle, -0x10,ahk_id %hwnd%

state := !state

return


fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
No, when using WinSet it seems to work fine.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
This behaviour appears to be by design:
[color=green]// Hiding then showing is the only way I've discovered to make it update.  If the window
// is not updated, a strange effect occurs where the window is still visible but can no
// longer be used at all (clicks pass right through it).  This show/hide method is less
// desirable due to possible side effects caused to any script that happens to be watching
// for its existence/non-existence, so it would be nice if some better way can be discovered
// to do this.
// SetWindowPos is also necessary, otherwise the frame thickness entirely around the window
// does not get updated (just parts of it):[/color]
SetWindowPos(mHwnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
ShowWindow(mHwnd, SW_HIDE);
ShowWindow(mHwnd, SW_SHOWNA); [color=green]// i.e. don't activate it if it wasn't before. Note that SW_SHOWNA avoids restoring the window if it is currently minimized or maximized (unlike SW_SHOWNOACTIVATE).
// None of the following methods alone is enough, at least not when the window is currently active:
// 1) InvalidateRect(mHwnd, NULL, TRUE);
// 2) SendMessage(mHwnd, WM_NCPAINT, 1, 0);  // 1 = Repaint entire frame.
// 3) RedrawWindow(mHwnd, NULL, NULL, RDW_INVALIDATE|RDW_FRAME|RDW_UPDATENOW);
// 4) SetWindowPos(mHwnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);[/color]


fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I haven't observed this behavior using the WinSet method, but I only did a quick test so far. Also it should maybe be tested if this problem persists in newer versions of Windows.
Apart from that, I noticed the window sometimes not getting reactivated properly. I don't have any NoActivate option set.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The code I posted is an extract from the Gui command, so it does no affect the WinSet command. It does not attempt to reactivate the window - the comments imply that it should remain active if it was already. It doesn't always remain active on my Windows 7 system. I guess it's up to whether the OS activates some other window when the active one is hidden.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I was talking about the "Click-through" behavior mentioned in that comment in relation to the WinSet command. This is why I suggest testing if this behavior is still present in Win7 when the GUI isn't hidden and shown again.
If this problem persists in Win7, could you add the activation of the window?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I have changed the Gui command in v1.1.00.01 so that it behaves the same as WinSet when setting or removing styles. The following is taken from my comments in the source code:

Update by Lexikos: I've been unable to produce the "strange effect" described above using WinSet on Win2k/XP/7, so changing this section to use the same method as WinSet. If there are any problems, at least WinSet and Gui will be consistent.



fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Sounds good.