Microsoft KB Archive/254339

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 13:52, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Article ID: 254339

Article Last Modified on 7/13/2004



APPLIES TO

  • Microsoft Visual Basic 5.0 Professional Edition, when used with:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows 2000 Standard Edition
  • Microsoft Visual Basic 6.0 Professional Edition, when used with:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows 2000 Standard Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition, when used with:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows 2000 Standard Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition, when used with:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows 2000 Standard Edition



This article was previously published under Q254339

SUMMARY

Under Microsoft Windows 98, Microsoft Windows Me, and Microsoft Windows 2000, a change was made regarding how Windows allows the foreground window to be set. An application is no longer permitted to bring a window to the foreground unless:

  • The application is already the foreground window.


  • The application activated the current foreground window.


  • The application received the last input event.


  • There is currently no active foreground window.


  • The foreground application is being debugged.


  • The foreground lock timeout has expired.



Windows 2000 introduces the following constraint:

  • No menus are active.

This article demonstrates how to implement the new method of alerting a user to an application using the FlashWindowEx API function from Visual Basic. For further information on this topic, see the "References" section below.

MORE INFORMATION

The following code sample demonstrates how to implement this functionality using Visual Basic versions 5.0 or 6.0. Note that this implementation is intended for Windows 98, Windows Me, and Windows 2000 only. This sample fails on any other operating system.

Step by Step Example

  1. Start a new Visual Basic Standard EXE project. Form1 is created by default.
  2. Add a CommandButton control to Form1.
  3. Add the following code to the General Declarations section of Form1:

    Option Explicit
    
    Private Declare Function FlashWindowEx Lib "user32" _
       (FWInfo As FLASHWINFO) As Boolean
    
    Private Declare Sub Sleep Lib "kernel32" _
       (ByVal dwMilliseconds As Long)
    
    Private Type FLASHWINFO
      cbSize As Long     ' size of structure
      hWnd As Long       ' hWnd of window to use
      dwFlags As Long    ' Flags, see below
      uCount As Long     ' Number of times to flash window
      dwTimeout As Long  ' Flash rate of window in milliseconds. 0 is default.
    End Type
    
    Const FLASHW_STOP = 0
    Const FLASHW_CAPTION = 1
    Const FLASHW_TRAY = 2
    Const FLASHW_ALL = FLASHW_CAPTION Or FLASHW_TRAY
    Const FLASHW_TIMER = 4
    Const FLASHW_TIMERNOFG = 12
    
    Private Sub Command1_Click()
       Dim RetVal As Integer
       Dim FWInfo As FLASHWINFO
       
       ' Fill the structure:
       With FWInfo
          .cbSize = 20
          .hWnd = Me.hWnd
          .dwFlags = FLASHW_ALL
          .uCount = 5
          .dwTimeout = 0
       End With
       
       ' Allow time to cover the window:
       Sleep (2000)
       ' call the function:
       RetVal = FlashWindowEx(FWInfo)
    End Sub
                        
  4. Start the application and press the CommandButton. A two-second delay occurs before the window flashes in the taskbar. This allows time for you to cover up the window and observe the change in behavior.


REFERENCES

Platform SDK Documentation: "Foreground and Background Windows"

Keywords: kbapi kbhowto KB254339