News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

How To Create a Flashing Title Bar on a Visual Basic Form

Started by ben2ong2, October 07, 2006, 04:57:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

PRODUCT :Microsoft Visual Basic for Windows
PROD/VER:4.00    | 4.00
OPER/SYS:WINDOWS | WINDOWS NT
KEYWORDS:kbui kbprg kbcode kbhowto

--------------------------------------------------------------------------
The information in this article applies to:

- Standard, Professional, and Enterprise Editions of Microsoft Visual
   Basic for Windows 16-bit and 32-bit, version 4.0
--------------------------------------------------------------------------

SUMMARY
=======

When calling a Windows API function call, you can create a flashing window
title bar on the present form or any other form for which you know the
handle.

MORE INFORMATION
================

Visual Basic for Windows has the ability to flash the title bar on any
form if you can get the handle to that form. The function FlashWindow
flashes the specified window once. Flashing a window means changing the
appearance of its caption bar, as if the window were changing from inactive
to active status, or vice versa. (An inactive caption bar changes to an
active caption bar; an active caption bar changes to an inactive caption
bar.)

Typically, a window is flashed to inform the user that the window requires
attention when that window does not currently have the input focus. The
function FlashWindow is defined as

   FlashWindow(hWnd, bInvert)

where:

   hWnd      - Identifies the window to be flashed. The window can be
               either open or iconic.

   bInvert   - Specifies whether the window is to be flashed or
               returned to its original state. The window is flashed
               from one state to the other if the bInvert parameter is
               nonzero. If the bInvert parameter is zero, the window
               is returned to its original state (either active or
               inactive).

FlashWindow returns a value that specifies the window's state before the
call to the FlashWindow function. It is nonzero if the window was active
before the call; otherwise, it is zero.

When using FlashWindow, it is a good design practice to set the flash rate
equal to that of the caret rate. The caret blink rate can be found by
using the GetCaretBlinkTime function. GetCaretBlinkTime returns the elapsed
time, in milliseconds, required to cause the caret to blink.

Step-by-Step Example
--------------------

The following section describes how to flash a form while that form does
not have the focus:

1. Start 16-bit or 32-bit Visual Basic 4.0, or, if it is already running,
   click New Project on the File menu.

2. Add a Timer control to the Form1 form.

3. Copy the following code to the Code window of the Form1 form:

   Private Sub Form_GotFocus()
      Timer1.Enabled = False
   End Sub

   Private Sub Form_Load()
      Timer1.Interval = GetCaretBlinkTime()
      You are not allowed to view links. Register or Login
   End Sub

   Private Sub Timer1_Timer()
      Success = FlashWindow(Form1.hwnd, 1)
   End Sub

4. On the Insert menu, click Form to insert a second form into the project.

5. Copy the following code to the Code window of the Form2 form:

   Private Sub Form_Click()
      Form1.Timer1.Enabled = True
   End Sub

6. On the Insert menu, click Module to insert a module into the project.

7. Copy the following code to the Code window of the Module1 module:

   'Depending on what operating system you are using determines the
   'correct function declares and variables. This is an example of
   'conditional compilation.

   #If Win32 Then
      Declare Function FlashWindow Lib "user32" ( _
                       ByVal hwnd As Long, _
                       ByVal bInvert As Long) As Long

      Declare Function GetCaretBlinkTime Lib "user32" () As Long

      Dim Success As Long

   #Else
      Declare Function FlashWindow Lib "User" ( _
                       ByVal hwnd As Integer, _
                       ByVal bInvert As Integer) As Integer

      Declare Function GetCaretBlinkTime Lib "User" () As Integer

      Dim Success As Integer

   #End If

8. On the Run menu, click Start or press the F5 key to start the program.
   Form1 will be in the foreground with Form2 in the background. Click
   anywhere in Form2; Form1's Caption Bar will flash until you click Form1.

Additional reference words: 4.00 vb4win vb4all
KBCategory: kbui kbprg kbcode kbhowto
KBSubcategory: APrgWindow APrgOther



=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.  MICROSOFT DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO NOT ALLOW THE EXCLUSION
OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1996.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login