Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to bring window in foreground

how to bring window in foreground

how to bring window in foreground


" How to allow a background thread to bring a window in foreground"

If someone can help to come out of this problem.

I wanted to create an application whoes only one instance should run at a time from within a folder.
There are many ways to do this, but I followed this one.

- Create an event with some uniq name (with foler name) "Onlyone+Inst1" .
- Check if that event already created by another instance
- If first Instance then, Create a thread. The thread method (screen monitor) will wait for event to set.
- If another instance then, set the event and exit.
- If ScreenMonitor finds the event set, its job now is to bring the instance in the foreground, otherwise just waits for the event.
Now, it works fine but it does not bring the first instance in foreground all the time. Yes sometime it does and other itmes it blinks in the taskbar.

There is no surprise for this behaviour. I have tried all these method for this purpose and information can be find on msdn. none of them helped.

I can use alternate method, but I want to do this way as do not see any reason for not working.


RE: how to bring window in foreground


You don't say what language you are trying to do this in, but if you look at FAQ184-4262 that I wrote over in the Visual FoxPro General forum you'll see why this is happening and the only way around is via attaching to the foreground process. Regardless of the language, the FAQ should give you an idea of what API functions you need to use and possible fodder to find a similar example in your language of choice via Google search.

SweetPotato Software Website
My Blog

RE: how to bring window in foreground

Thanks for this only reply. My app is Win32 program written in  c and using win32 api.
I have tried AttachInputThread()method. But it does not work. Still it blinks in the taskbar.

From the main windows prgram I am running a backgroound thread which waits for event to set and then forces the main window to popup in foreground.

When same instance of the program starts, it finds that there is already one instance there and so it sets the event. This is immediately seen by background thread and tries to bring its "Hello" window on top.
if you want i can send you code also.

thanks for your reply. hope i am clear to express the problem.
- OP

RE: how to bring window in foreground

You might download the win32.zip from PowerBasic. it
may be a little old but you may find something in there
to help. examples are in 'C'.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close