borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (App Shutdown)Next Topic (Minesweeper Project: 1. MinePlacement 2. Best score) New Topic New Poll Post Reply
AndreaVB Forum : VB General : How to Cancel menu (in systray) when app is lost forcus
Poster Message
tuanhai
Level: Guest


icon How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

I have an Application and when the Main form is minimized then it go on systray. I popup a menu on when the App Icon Systray is clicked.
The problem is when the menu is on, I click the mouse to other place (Desktop or other App), the menu is still appear and that is not what I want.

I used to place the code on form like:

Private Sub Form_LostForcus()
  SendKeys "{ESC}", True
End Sub

But it can't help me in this sintuation.

Please help me out!

Thanks.

11-04-2002 at 02:51 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

Offhand, although I've never messed with it, you could try:
1) Subclassing the form, trapping for when the mouse is away from the menu.
2) Set a timer event to start when the menu pops up, set to automatically hide after x seconds.
3) Put a "Close Menu" option on the pop up as an option, put at the top or bottom, separated so that it's noticed.



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

11-04-2002 at 03:46 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
tuanhai
Level: Guest

icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

Can you give me the sample of the first solution (Using subclassing)?  

tuanhai@cmc.com.vn
Thanks In advance!

12-04-2002 at 01:15 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

I'd have to look (possibly re-create) if someone else has code for it, feel free to do so.

It may take a few days, took me a while to get it to work last time.

12-04-2002 at 01:32 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

Well, I looked, couldn't find the code.

Tried to recreate, it didn't work, or crashed, or brought the system to a virtual halt (would take mouse about ten seconds to move across the screen).

Unfortunetely I wasn't able to get a solution. Then I have WinXP, and even Microsoft's popup tray menus don't always close when you click off of them.




16-04-2002 at 05:27 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Merrion
Level: VB Guru

Registered: 15-04-2002
Posts: 37
icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

You can be notified when an application gains or loses the focus by subclassing that application's main form and trapping the WM_ACTIVATEAPP message.

I have written a subclassing wrapper dll (called EventVB.dll, downloadable from Merrion Computing Downloads that you could use to get this notification thus:


'\\ Form declarations
Option Explicit

Dim WithEvents vbLink As EventVB.ApiFunctions
Dim WithEvents vbWnd As EventVB.ApiWindow

Private Sub Form_Load()

Set vbLink = New EventVB.ApiFunctions

Set vbWnd = New EventVB.ApiWindow
vbWnd.hwnd = Me.hwnd
vbLink.SubclassedWindows.Add vbWnd

End Sub


This gives you a number of extra events for the form, one of which is ActiveApplicationChanged:


Private Sub vbWnd_ActiveApplicationChanged(ByVal ActivatingThisApp As Boolean, ByVal hThread As Long, Cancel As Boolean)

If Not ActivatingThisApp Then
   '\\ Your app lost focus, so cancel the menu here....
End If

End Sub


HTH,
  Duncan


____________________________
--8<------------------------------
Free components and source code - see http://www.merrioncomputing.com/Download/index.htm for details

16-04-2002 at 12:30 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
tuanhai
Level: Guest

icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

The code using EventVB still dosen't work since when I click outside of the form which is in systray and the menu is popup, the event ActiveApplicationChanged not be trapped. This event be trapped only when the form is on normal state (not on systray). (I test this dll long time ago.)

Otherwise, the EventVB.DLL is rather big (~900k) and I don't want to brink this dll follow the project. Just need some subclassing classes only. The EventVB.DLL should be saparated to be smaller catergory.

If you solved this problem already, please send me an example to tuanhai@cmc.com.vn

Thanks alot for your anwser!

Tuan Hai

17-04-2002 at 03:20 AM
| Quote Reply
tuanhai
Level: Guest

icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

Ha Ha...

I find out the solution. That just very simple.

' Declare API
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

'put this code before popup the menu
    SetForegroundWindow Me.hwnd
    PopupMenu mnuFile

Have nice day!

17-04-2002 at 04:30 AM
| Quote Reply
Merrion
Level: VB Guru

Registered: 15-04-2002
Posts: 37
icon Re: How to Cancel menu (in systray) when app is lost forcus  Archived to Disk

quote:
The EventVB.DLL should be saparated to be smaller catergory.


The source code is available for you to do so as your requirements dictate.  It is not economic for us to maintain several overlapping codesets for this, however.

HTH,
  Duncan

____________________________
--8<------------------------------
Free components and source code - see http://www.merrioncomputing.com/Download/index.htm for details
17-04-2002 at 09:26 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : How to Cancel menu (in systray) when app is lost forcus
Previous Topic (App Shutdown)Next Topic (Minesweeper Project: 1. MinePlacement 2. Best score) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder