?
Solved

Set active window when clicking system tray icon

Posted on 2003-03-20
4
Medium Priority
?
179 Views
Last Modified: 2013-12-26
This is very likely to be a simple problem, but from my perspective it's just one of those very irritating imperfections in my program that I can't solve without help.

I have a program that uses a system tray icon and a double click method on the icon to toggle the form's visibility. My problem is when the window becomes inactive and then is hidden, making it visible again annoyingly makes the window appear at the back. I would very much like the window to be set as the topmost active window everytime it is made visible again.
0
Comment
Question by:alwaysunderestimated
[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 7

Expert Comment

by:fluglash
ID: 8173356
use API SetForegroundWindow(hWnd as long) as Long
0
 
LVL 4

Accepted Solution

by:
jmfairchild earned 150 total points
ID: 8174166
If you didn't want to use an API call, couldn't you just use the SetFocus method on the window?:

Form1.Visible = True
Form1.SetFocus

Also, is there a window that is set to "Always be on top"? (so that it receives focus no matter what other windows/forms are made visible/activated)?

- Jim
0
 

Author Comment

by:alwaysunderestimated
ID: 8174656
Thanks Guys,

Both of the comments were very helpful but since I did actually use jmfairchild's suggestion I've accepted his answer. Although for some strange reason I did try using Me.SetFocus before and it didn't seem to make any difference, but now I am using it directly after the Me.Visible = True and it's working exactly as I wanted.

Thanks again
0
 

Author Comment

by:alwaysunderestimated
ID: 8174674
I'm not sure if there is a circumstance when Me.SetFocus doesn't work, but I did try using it before and if I recall correctly I had some kind of improper use error - but based on your suggestion I have my program working as I wanted - so thank you.
0

Featured Post

Industry Leaders: 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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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