Hasan_Khan
asked on
Prevent window caption blinking on activation
I have an icon in system tray.
Double click on that icon fires an event in which I'm using me.show to make the window appear.
But when it appears, its not activated like the caption is grayed out and it blinks 3 times unless I click on it.
AppActivate solves the problem but I can't use it since I have multiple instances of my program running at the same time and they all have same caption while appactivate works on caption title so I want an alternate.
Note: setactivewindow, setforegroundwindow, setdesktopwindow, me.setfocus e.t.c nothing works.
Double click on that icon fires an event in which I'm using me.show to make the window appear.
But when it appears, its not activated like the caption is grayed out and it blinks 3 times unless I click on it.
AppActivate solves the problem but I can't use it since I have multiple instances of my program running at the same time and they all have same caption while appactivate works on caption title so I want an alternate.
Note: setactivewindow, setforegroundwindow, setdesktopwindow, me.setfocus e.t.c nothing works.
ASKER
It doesn't blink anymore but still it ain't activated.
ASKER
I've found a perfect solution to the problem.
I temporarily add few white spaces at the end of the caption.
Do the AppActivate on it and then change it back.
Nothing else works for me.
I temporarily add few white spaces at the end of the caption.
Do the AppActivate on it and then change it back.
Nothing else works for me.
Hasan:
''bas
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
''form
SetForegroundWindow me.hWnd
may work...
-m
''bas
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
''form
SetForegroundWindow me.hWnd
may work...
-m
Hasan:
Ack, you've already tried that... nm... Perhaps use SetForegroundWindow in combination with the remove blinking code? I'm out of ideas.. :)
-m
Ack, you've already tried that... nm... Perhaps use SetForegroundWindow in combination with the remove blinking code? I'm out of ideas.. :)
-m
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ambientnet I've tried all the combinations with all the APIs but the problem got solved only by the way I mentioned above.
This might work (if not, plz let me know):
''bas code:
Public Declare Function SetFocusAPI Lib "user32.dll" Alias "SetFocus" (ByVal hWnd As Long) As Long
''form code:
Dim retval As Long ' return value
' Give your form's hWnd focus
retval = SetFocusAPI(me.hWnd)
If you have flashing problems, try this, too:
''bas code
Private Type FLASHWINFO
cbSize As Long
Hwnd As Long
dwFlags As Long
uCount As Long
dwTimeout As Long
End Type
Private Const FLASHW_STOP = 0
Private Declare Function FlashWindowEx Lib "user32" _
(FWInfo As FLASHWINFO) As Boolean
''form code:
Dim bRet As Boolean
Dim udtFWInfo As FLASHWINFO
Dim Hwnd as Long, Dim uCount As Long
hWnd = me.hWnd
uCount = 1
With udtFWInfo
.cbSize = 20
.Hwnd = hWnd
.dwFlags = FLASHW_TRAY
.uCount = uCount 'flash window x times
.dwTimeout = 0
End With
bRet = FlashWindowEx(udtFWInfo)
~ http://www.freevbcode.com/ShowCode.Asp?ID=1447
hope this helps...
-m