How to stop flashing title bar?

Posted on 2000-03-22
Last Modified: 2008-02-01
I was using the KnowledgeBase article (Q176085) to put a program in the system tray when it is minimized. Everything works fine, but when you maximize the program's form by clicking or double-clicking on its tray icon, the form's title bar flashes on and off (enabled/disabled) a few times. I'm pretty sure this is by design in order to cause attention to the form, but it's kind of annoying.

Is there any way to stop the flashing title bar?
Question by:RoboRob

Expert Comment

ID: 2643785
I'm pretty sure this is by design in order to cause attention to the form?
Really by design? :-)

Author Comment

ID: 2643800
Not my design, Microsoft's!
LVL 28

Accepted Solution

Ark earned 50 total points
ID: 2644005
This is Microsoft's sample design :-)
Try this
Option Explicit

' SYSTRAY Sample by Matt Hart -
' The uCallbackMessage parameter is usually a user-defined
' message.  However, we can also use a message that VB
' automatically handles as an Event - the MouseMove message.
' The X parameter of this event contains the action.
' This method came from a Tip in VBPJ.
' Updated to show how to forcefully activate a window.
' Win98 doesn't automatically set the focus to the new
' window, but has an annoying tendancy to "blink" the
' task bar caption and window. The hProcess returned by
' GetWindowThreadProcessID (not the thread ID) can be
' used with AppActivate. Note that you can also use the
' Caption of the form you want to activate, but if you
' have more than one window with the same caption, you
' cannot be guaranteed of activating the correct one.

    cbSize As Long
    hwnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 64
End Type
Const NIM_ADD = 0
Const NIM_MODIFY = 1
Const NIM_DELETE = 2
Const NIF_ICON = 2
Const NIF_TIP = 4

Const WM_MOUSEMOVE = &H200
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer

' SetWindowPos Flags
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20        '  The frame changed: send WM_NCCALCSIZE
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering


' SetWindowPos() hwndInsertAfter values
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Function setNOTIFYICONDATA(hwnd As Long, ID As Long, Flags As Long, CallbackMessage As Long, Icon As Long, Tip As String) As NOTIFYICONDATA

    nidTemp.cbSize = Len(nidTemp)
    nidTemp.hwnd = hwnd
    nidTemp.uID = ID
    nidTemp.uFlags = Flags
    nidTemp.uCallbackMessage = CallbackMessage
    nidTemp.hIcon = Icon
    nidTemp.szTip = Tip & Chr$(0)

    setNOTIFYICONDATA = nidTemp
End Function

Private Sub Command1_Click()
    'Add an icon.  This procedure uses the icon specified in
    'the Icon property of Form1. This can be modified as desired.

    Dim i As Integer
    Dim s As String

    s = "ToolTipText Here!"
    nid = setNOTIFYICONDATA(Form1.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, WM_MOUSEMOVE, Form1.Icon, s)
    i = Shell_NotifyIconA(NIM_ADD, nid)
    WindowState = vbMinimized
    Visible = False
End Sub
Private Sub Command3_Click()
    'Delete an existing icon.

    Dim i As Integer

    nid = setNOTIFYICONDATA(Form1.hwnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, vbNull, Form1.Icon, "")

    i = Shell_NotifyIconA(NIM_DELETE, nid)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Not Visible Then
        Select Case x
            Case 7680
                'List1.AddItem "MouseMove!"
            Case 7695
                List1.AddItem "Left MouseDown"
            Case 7710
                List1.AddItem "Left MouseUp"
            Case 7725
                List1.AddItem "Left DoubleClick"
                Visible = True
                WindowState = vbNormal
                Dim hProcess As Long
                GetWindowThreadProcessId hwnd, hProcess
                AppActivate hProcess
            Case 7740
                List1.AddItem "Right MouseDown"
            Case 7755
                List1.AddItem "Right MouseUp"
            Case 7770
                List1.AddItem "Right DoubleClick"
        End Select
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
End Sub
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 2644021
try using FlashWindow with bInvert = false

here is the declaration for this function:

Public Declare Function FlashWindow Lib "user32" Alias "FlashWindow" (ByVal hwnd As Long, ByVal bInvert As Long) As Long

Author Comment

ID: 2648733
While korky's solution was simple and did get rid of the flashing title bar, it left the app without the focus (or at least appearing as if it didn't have the focus).

Ark's solution worked perfectly. To simplify things for anyone else accessing this question, here's the code needed to restore the app:

Dim lonResult As Long
Dim lonProcessId As Long

Me.WindowState = vbNormal
lonResult = SetForegroundWindow(Me.hWnd)
lonResult = GetWindowThreadProcessId _
    (Me.hWnd, lonProcessID)
AppActivate lonProcessID

Of course, you also have to declare the SetForegroundWindow and GetWindowThreadProcessId API functions:

Declare Function SetForegroundWindow _
    Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" _
    (ByVal hWnd As Long, lpdwProcessId As Long) As Long

That's it!

LVL 28

Expert Comment

ID: 2651244
Rob: Thank you for points. I posted all code just to show another way (not shown at MS sample) how to get notification from SysTray without subclassing

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 67
Run code from text file in vb 1 71
Modifying Conditional Format from VBA code 3 60
How to read File Date Created using VB6 8 51
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question