?
Solved

How to stop flashing title bar?

Posted on 2000-03-22
6
Medium Priority
?
480 Views
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?
0
Comment
Question by:RoboRob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

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

Author Comment

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

Accepted Solution

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

' SYSTRAY Sample by Matt Hart - vbhelp@matthart.com
' http://matthart.com
'
' 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. http://www.windx.com
'
' 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.

Private Type NOTIFYICONDATA
    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_MESSAGE = 1
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

Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER

' 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
    Dim nidTemp 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
    Dim nid As NOTIFYICONDATA

    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
    Dim nid As NOTIFYICONDATA

    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)
    Command3_Click
End Sub
Cheers
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:korky
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
0
 

Author Comment

by:RoboRob
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)
Me.Show
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!

Rob
0
 
LVL 28

Expert Comment

by:Ark
ID: 2651244
Hi
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 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