It is currently Wed Sep 03, 2014 3:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Real SetForegroundWindow()
PostPosted: Wed Sep 03, 2003 9:05 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 10996
Location: France
Code updated For 5.20+

Here is a snippet I need for my work, to really put a window in the foreground, instead of flashing taskbar for Win98/2000 or XP. Warning, use it with care and only when needed, as it's not very smart to grab the user input without notice :)

Code:
; Code by Elvis Rox erox@etree.com

Procedure ReallySetForegroundWindow(Window)

  hWnd = WindowID(Window)

  ; If the window is in a minimized state, maximize now
 
  If GetWindowLong_(hWnd, #GWL_STYLE) & #WS_MINIMIZE
    ShowWindow_(hWnd, #SW_MAXIMIZE)
    UpdateWindow_(hWnd)
  EndIf
 
  ; Check To see If we are the foreground thread
 
  foregroundThreadID = GetWindowThreadProcessId_(GetForegroundWindow_(), 0)
  ourThreadID = GetCurrentThreadId_()
  ; If not, attach our thread's 'input' to the foreground thread's
 
  If (foregroundThreadID <> ourThreadID)
    AttachThreadInput_(foregroundThreadID, ourThreadID, #TRUE);
  EndIf
 
  ; Bring our window To the foreground
  SetForegroundWindow_(hWnd)
 
  ; If we attached our thread, detach it now
  If (foregroundThreadID <> ourThreadID)
    AttachThreadInput_(foregroundThreadID, ourThreadID, #FALSE)
  EndIf 
 
  ; Force our window To redraw
  InvalidateRect_(hWnd, #NULL, #TRUE)
EndProcedure


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Wed Sep 03, 2003 9:20 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7441
> Here is a snippet I need for my work, to really put a window in the
> foreground, instead of flashing taskbar for Win98/2000 or XP.

Hey, check out my tip from June 2002:

http://forums.purebasic.com/english/vie ... php?t=3751

:twisted:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 3:57 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 10996
Location: France
Arf :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 1:17 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7441
:lol:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 8:06 am 
Offline
Administrator
Administrator

Joined: Wed Apr 23, 2003 7:57 pm
Posts: 1309
Location: Belgium
Image

_________________
Berikco

http://www.cenn.be


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Mon Feb 24, 2014 3:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 145
Location: Linz - Austria
rock-solid :!:
Code:
#LSFW_UNLOCK = 2
#ASFW_ANY = -1

Procedure.i ForceWindowIntoForeground(window.i)
  Protected currentThread.i, activeWindow.i, activeProcess.i, activeThread.i, windowProcess.i, windowThread.i, oldTimeout.i, newTimeout.i
  currentThread = GetCurrentThreadId_();
  activeWindow = GetForegroundWindow_();
  activeThread = GetWindowThreadProcessId_(activeWindow, @activeProcess);
  windowThread = GetWindowThreadProcessId_(window, @windowProcess);
  If currentThread <> activeThread
    AttachThreadInput_(currentThread, activeThread, #True)
  EndIf
  If windowThread <> currentThread
    AttachThreadInput_(windowThread, currentThread, #True)
  EndIf
  oldTimeout = 0
  newTimeout = 0
  SystemParametersInfo_(#SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @oldTimeout, 0);
  SystemParametersInfo_(#SPI_SETFOREGROUNDLOCKTIMEOUT, 0, @newTimeout, 0);
  LockSetForegroundWindow_(#LSFW_UNLOCK);
  AllowSetForegroundWindow_(#ASFW_ANY);
  SetForegroundWindow_(window);
  If IsIconic_(window)
    ShowWindow_(window, #SW_RESTORE);
  EndIf
  SystemParametersInfo_(#SPI_SETFOREGROUNDLOCKTIMEOUT, 0, @oldTimeout, 0);
  If currentThread <> activeThread
    AttachThreadInput_(currentThread, activeThread, #False)
  EndIf
  If windowThread <> currentThread
    AttachThreadInput_(windowThread, currentThread, #False)
  EndIf
EndProcedure

cheers, chi


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Mon Feb 24, 2014 3:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 145
Location: Linz - Austria
@PB: There are certain circumstances where the process is locked (LockSetForegroundWindow) or the lock time-out has not expired (SPI_GETFOREGROUNDLOCKTIMEOUT)...
More info @ http://msdn.microsoft.com/en-us/library ... 85%29.aspx


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Mon Feb 24, 2014 3:55 pm 
Offline
Addict
Addict

Joined: Thu Nov 01, 2007 5:37 pm
Posts: 1798
Location: Germany
Offtopic:
Previous posting date wrote:
Thu Sep 04, 2003
Your posting date wrote:
Mon Feb 24, 2014
Wow, have some respect for the dead! :shock:


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Mon Feb 24, 2014 4:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 145
Location: Linz - Austria
Quote:
Code updated For 5.20+

Fred dug him up first ;)


Top
 Profile  
 
 Post subject: Re: Real SetForegroundWindow()
PostPosted: Mon Feb 24, 2014 4:25 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7441
:lol:

_________________
Note: I am not a member of the PureBasic team.
I am using 5.30 (x86) on Win 7 Ultimate (64-bit).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye