Solved

Form on top but ignores events?

Posted on 2002-05-09
4
132 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
Comment Utility
Hi deal

Try using

AppActivate "Microsoft Word"

Hope this helps...
0
 

Author Comment

by:deal051298
Comment Utility
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
Comment Utility
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
Comment Utility
Found this open question Wildi so the points are use - can't remeber if it worked or not
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now