Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Form on top but ignores events?

Posted on 2002-05-09
4
Medium Priority
?
147 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
[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
  • 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 600 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

Independent Software Vendors: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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

719 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