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
Solved

Form on top but ignores events?

Posted on 2002-05-09
4
141 Views
Last Modified: 2010-05-02
This is a followup to my question "Pop up dialog in system tray"

Basically I have created an app that pops up a form occasionally when an event occurs. It's all well and good except I notice that when it does this it takes focus away from the current window (e.g. Microsoft Word) so when I'm typing Word will lose my keystrokes until I reselect the application.

Is there anyway to get the form to display above all applications but not take the focus away from the current application?

Cheers
0
Comment
Question by:deal051298
  • 2
4 Comments
 
LVL 3

Expert Comment

by:SirNick
ID: 6998304
Hi deal

Try using

AppActivate "Microsoft Word"

Hope this helps...
0
 

Author Comment

by:deal051298
ID: 6998308
Errr. The application that loses the focus to my popup could be *any* application. I want my form to popup above all apps but not actually take the focus. I want it to cause as little distubance to the user as possible while still making sure it is seen. Same functionality as popups that appear by MSN Messenger.
0
 
LVL 1

Accepted Solution

by:
Wildi earned 150 total points
ID: 6998442
Instead of showing your form with the .show method or by setting the .Visible property to true you could send an appropriate windows message to your form window where a little bit more flexibility is given. Try sending the message SW_SHOWNOACTIVE method.

Try this code in a form's code having one command button, which works here on a NT workstation (Win2K already supports window flashing so I am not sure if you need the manually window flashing there). However, for manually flashing the window your form window has to be minimized.

----------------------Begin Code Snippet
Option Explicit

Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function ShowWindowAsync Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Sub k32Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Private Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long

Public Enum eWinStyle
  SW_HIDE = 0
  SW_NORMAL = 1
  SW_SHOWNORMAL = 1
  SW_SHOWMINIMIZED = 2
  SW_SHOWMAXIMIZED = 3
  SW_MAXIMIZE = 3
  SW_SHOWNOACTIVATE = 4
  SW_SHOW = 5
  SW_MINIMIZE = 6
  SW_SHOWMINNOACTIVE = 7
  SW_SHOWNA = 8
  SW_RESTORE = 9
  SW_SHOWDEFAULT = 10
End Enum


Public Sub ShowWnd(ByVal hWnd As Long, Optional ByVal Modal As Integer = 0, Optional ByVal aCmd As eWinStyle = SW_SHOWDEFAULT)
  If Modal = 1 Then
    ShowWindow hWnd, aCmd
  Else
    ShowWindowAsync hWnd, aCmd
  End If
End Sub

Public Sub FlashWin(ByVal ahWnd As Long, Optional ByVal duration As Long = 250)
  FlashWindow ahWnd, 1
  k32Sleep duration
  FlashWindow ahWnd, 0
  k32Sleep duration
  'FlashWindow aHWnd, 0
End Sub


Private Sub Command1_Click()
  Dim i As Long
  On Error Resume Next
  Me.Visible = False
  For i = 1 To 100000
    DoEvents
  Next
  ShowWnd Me.hWnd, 0, SW_SHOWNOACTIVATE
  Me.WindowState = vbMinimized
  For i = 1 To 10
    FlashWin Me.hWnd, 500
    DoEvents
  Next
End Sub

----------------------End Code Snippet
0
 

Author Comment

by:deal051298
ID: 7632611
Found this open question Wildi so the points are use - can't remeber if it worked or not
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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