Page 1 of 2
How to re-activate my app ?
Posted: Sat Aug 02, 2003 7:39 pm
by eddy
Some infos :
- My app XCC has a unique instance
- When I click on a file (e.g file.xcc), my app is activated and receives file.XCC
The problem :
ShowWindow_(*myapp,#SW_SHOW) works once
The second time, my app is visible but not activated.
I've tried SetForeGround, SetActiveWindow, SetWindowPos...
I've forgot something in my code ?

Posted: Sat Aug 02, 2003 8:21 pm
by Karbon
UseWindow() maybe?
Posted: Sun Aug 03, 2003 1:39 am
by aszid
i would try to do usewindow() followed by activatewindow()
Re: How to re-activate my app ?
Posted: Wed Aug 06, 2003 8:53 am
by PB
> ShowWindow_(*myapp,#SW_SHOW) works once
> The second time, my app is visible but not activated.
This procedure brings any window to the front and gives it the focus:
Code: Select all
Procedure ForceFore(handle)
thread1=GetWindowThreadProcessID_(GetForegroundWindow_(),0)
thread2=GetWindowThreadProcessID_(handle,0)
If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#TRUE) : EndIf
SetForegroundWindow_(handle) : Sleep_(125) ; Delay to stop fast CPU issues.
If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#FALSE) : EndIf
EndProcedure
Posted: Mon Jun 14, 2004 1:43 pm
by DriakTravo
Thats awsome. THanks

Posted: Mon Jun 14, 2004 4:48 pm
by GreenGiant
Hi, I'm just curious. I've simply been using
Code: Select all
SetForegroundWindow_(WindowID(#Window))
to bring my window to the front. Is there some reason I shouldnt be doing this?
Posted: Mon Jun 14, 2004 11:46 pm
by PB
> to bring my window to the front
That works fine for your window, or any windows that your app launched,
but it won't work for other windows not associated with your app. My tip
brings ANY window to the front by temporarily attaching to their input
thread first, which is required to accomplish the feat.
Posted: Tue Jun 15, 2004 3:25 pm
by GreenGiant
Ahh ok. Thanks.

I was just a bit worried that maybe mine didnt work in some situations or something.
Posted: Wed Jun 16, 2004 6:34 am
by Danilo
GreenGiant wrote:Ahh ok. Thanks.

I was just a bit worried that maybe mine didnt work in some situations or something.
SetForegroundWindow_() alone works only if your process is
active.
If another program is active, your app doesnt come to foreground -
the window icon in the taskbar just begins blinking.
For more info see MSDN/PSDK.
Posted: Fri Jun 15, 2007 7:53 pm
by blueznl
Can anybody confirm this still works under the latest Windows XP? I can't seem to get this working

Posted: Fri Jun 15, 2007 8:12 pm
by rsts
If you mean forcefore, I use PB's forcefore in one of my apps and it has always worked under XP (and Vista).
cheers
Posted: Fri Jun 15, 2007 8:39 pm
by blueznl
Yes. That's weird then. Why doesn't it work for my app then? Hmmm...
Posted: Fri Jun 15, 2007 8:49 pm
by rsts
Whoops - I just checked my code and I use a different routine now and I'm not sure why.
cheers
Posted: Fri Jun 15, 2007 10:39 pm
by blueznl
Well, post it so we all can learn!
Anyway, I fooled around a little, and came to the following modification, which appears to work better:
Code: Select all
If window_h < 0
UseWindow(windownr)
window_h = WindowID(windownr)
EndIf
;
t1 = GetWindowThreadProcessId_(GetTopWindow_(0),0)
t2 = GetWindowThreadProcessId_(window_h,0)
If t1 <> t2
AttachThreadInput_(t1,t2,#True)
EndIf
Delay(128)
SetFocus_(window_h)
SetWindowPos_(window_h,#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
If t1 <> t2
AttachThreadInput_(t1,t2,#False)
EndIf
SetWindowPos_(window_h,#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
It looks like XP is trying to do smart things, such as grabbing back the top window after I disconnected the threads. Also SetForegroundWindow_() appears to be less efficient than SetWindowPos_()... beats me.
Added: oh darn, doesn't work 100%, who can help me further?
Posted: Fri Jun 15, 2007 11:05 pm
by rsts
Ok - several months back in an semi-major code update, forcefore stopped working the way I needed it to.
Here's the routine I ended up using as a replacement, after quite a bit of trial and error. It may be somewhat unique to my circumstance that this works where forcefore didn't. I'm not trying to fault forcefore at all. It worked fine for me before I made the changes.
Code: Select all
ShowWindow_(WindowID(#window_0),#SW_SHOWNORMAL| #SW_RESTORE)
SetWindowPos_(Handle, #HWND_TOPMOST, 0,0,0,0, #SWP_SHOWWINDOW |#SWP_NOMOVE | #SWP_NOSIZE)
Sleep_(250)
SetWindowPos_(Handle,-2,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
cheers