|
-
Mar 28th, 2007, 11:24 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Click on NotifyIcon, bring my program to front
Hello,
I have a Notify Icon on the main form of my application. It periodically checks for Alerts (as we call them) and notifies the user if they have new Alerts (very similar to Outlook telling you that you have a new e-mail). When the user clicks on the Notify Icon, it brings the Alerts module to the front if an instance of it is open, and opens a new instance if there is not one.
But, I would also like for my program to come to the front as if the user clicked on it in the taskbar.
Does this require some sort of API call?
I have tried these:
Me.WindowState = FormWindowState.Normal
Me.Focus()
Me.BringToFront()
but none have worked.
Any ideas?
Thanks
Last edited by 18experience; Mar 29th, 2007 at 08:16 AM.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 28th, 2007, 11:44 AM
#2
Re: Click on NotifyIcon, bring my program to front
You may want to concider using the BringWindowToTop API function
VB.NET MVP 2008 - Present
-
Mar 28th, 2007, 12:03 PM
#3
Thread Starter
Fanatic Member
Re: Click on NotifyIcon, bring my program to front
Thanks for the idea, I bet this is the right track.
I put this at the top of my class:
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
and then I call this:
BringWindowToTop(Me.Handle)
but nothing is happening. I have used APIs very little. Am I missing something important here?
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 28th, 2007, 12:28 PM
#4
Re: Click on NotifyIcon, bring my program to front
This works for me
Code:
Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
Me.Visible = True
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.NotifyIcon1.Visible = False
End Sub
-
Mar 28th, 2007, 12:36 PM
#5
Thread Starter
Fanatic Member
Re: Click on NotifyIcon, bring my program to front
Excuse me, its a balloon click. So, I'm not looking to do the standard Maximize Form/Make Notify Icon Invisible thing. The program is in the taskbar, and the notify icon is always visible. A balloon pops up if the user gets a new alert, and when they click it I want my application to pop up front. This is what happens when I run this (see attached pic):
Me.WindowState = FormWindowState.Normal
BringWindowToTop(Me.Handle)
This happens when I position Windows Explorer over the form to where I can still see this top and then click the balloon. Notice how it appears selected, but it is still behind Windows Explorer. Is this because I am running it in the debugger?
Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 28th, 2007, 01:27 PM
#6
Thread Starter
Fanatic Member
Re: Click on NotifyIcon, bring my program to front
I guess this should really be moved to the API forum now. Moderators? Anyone? I would appreciate it.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 28th, 2007, 08:35 PM
#7
Re: Click on NotifyIcon, bring my program to front
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 28th, 2007, 09:40 PM
#8
Re: Click on NotifyIcon, bring my program to front
This not an API question. Just call the form's Activate method. If you tried those methods and they didn't work then you should have read their MSDN help topics to see if you were using them incorrectly. If you'd done that for the Focus method then you'd have seen this:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
If we as developers cannot read help documentation then there is no hope for our users.
-
Mar 29th, 2007, 08:16 AM
#9
Thread Starter
Fanatic Member
Re: Click on NotifyIcon, bring my program to front
RobDog888, thanks for the move.
jmcilhinney - sorry, I know how much you talk about the MSDN help topics. And I agree with what you say about reading help documentation. Thanks for the help, that worked perfectly, by the way.
Thanks again, everyone.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|