Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to bring window in foreground

Status
Not open for further replies.

cutpaste

Programmer
Mar 5, 2006
4
US
Hi,

" 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.

Implementation:
- 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.

SetForegroundWindow()
SystemParametersInfo()
AllowSetForegroundWindow(ASFW_ANY)
SwitchToThisWindow()
BringWindowToTop()
----
I can use alternate method, but I want to do this way as do not see any reason for not working.

regards,
-op
 
cutpaste,

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.

boyd.gif

SweetPotato Software Website
My Blog
 
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
 
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'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top