How to re-activate my app ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

How to re-activate my app ?

Post 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 ? :?
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

UseWindow() maybe?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

i would try to do usewindow() followed by activatewindow()
--Aszid--

Making crazy people sane, starting tomorrow.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to re-activate my app ?

Post 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
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Thats awsome. THanks :D
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

Ahh ok. Thanks. :) I was just a bit worried that maybe mine didnt work in some situations or something.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post 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.
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Can anybody confirm this still works under the latest Windows XP? I can't seem to get this working :-(
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Yes. That's weird then. Why doesn't it work for my app then? Hmmm...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Whoops - I just checked my code and I use a different routine now and I'm not sure why.

cheers
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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?
Last edited by blueznl on Sat Jun 16, 2007 11:13 am, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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
Post Reply