setForegroundWindow - BringWindowToTop [???] - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: setForegroundWindow - BringWindowToTop [???] (/showthread.php?tid=46307)
setForegroundWindow - BringWindowToTop [???] by XM4ST3RX on 06-14-2005 at 11:50 PM
Hi,
I've tried to use "SetForegroundWindow" and "BringWindowToTop" to bring a convo window to the front... but it only brings it to the front of Messenger main window... i need a function to bring the convo window infront of EVERY window running.
Kind Regards,
XM4ST3RX
RE: setForegroundWindow - BringWindowToTop [???] by matty on 06-15-2005 at 01:40 AM
SetForegroundWindow will bring the window infront of everything else except those windows that are set to "Always On Top"
RE: setForegroundWindow - BringWindowToTop [???] by XM4ST3RX on 06-15-2005 at 01:41 AM
Hi,
Could you please paste the function, maybe im not doing it correctly.
Kind Regards,
XM4ST3RX
RE: setForegroundWindow - BringWindowToTop [???] by matty on 06-15-2005 at 02:15 AM
code: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
SetForegroundWindow FindWindow("IMWindowClass", vbNullString)
End Sub
RE: setForegroundWindow - BringWindowToTop [???] by XM4ST3RX on 06-15-2005 at 02:18 AM
Hi,
How would i find a window of lets say an msn messenger conversation though? This is what im trying to achieve.
[edit]
How would that make a specific window go above all? I have the HWND of the window i want to put onfront.
[/edit]
Kind Regards,
XM4ST3RX
RE: setForegroundWindow - BringWindowToTop [???] by matty on 06-15-2005 at 02:24 AM
code: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
' hWnd would be the variable that contains the actual window handle. Change it with whatever you are using to store the Window Handle in.
SetForegroundWindow hWnd
End Sub
RE: setForegroundWindow - BringWindowToTop [???] by XM4ST3RX on 06-15-2005 at 02:30 AM
Hi,
It only goes on top, if the window has only just opened... if i minimize it afterwards, it doesnt come to top, even though that code is there to program it to.
Kind Regards,
XM4ST3RX Hi,
Nevermind, ive got it working now, cheers .
Kind Regards,
XM4ST3RX
RE: setForegroundWindow - BringWindowToTop [???] by Stigmata on 06-15-2005 at 06:29 AM
code: AppActivate "Window Caption"
then just use api's like
findwindow, getwindowtext
RE: setForegroundWindow - BringWindowToTop [???] by TazDevil on 06-17-2005 at 11:07 AM
Actually if i understand correctly, what you trying to do is this...
You want to bring the window to front when another window has the foreground focus...
Regarding this matter Micro$oft, from version 98 of Windows and on decided to restrict the accessibility of this function, and now it should only work for windows that belong to the same thread...
This modification to the API was made due to the rise of adware, viruses, etc that would insert code to STEAL the foreground window...
Therefore in order to successfully acheive stilling the foreground you must use the followin function i found in the web... it is in c++ but some one can translate it for you if you can't
code: void ReallySetForegroundWindow( HWND hWnd )
{
DWORD foregroundThreadID; // foreground window thread
DWORD ourThreadID; // our active thread
// If the window is in a minimized state, maximize now
if (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)
{
ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);
}
// Check to see if we are the foreground thread
foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(),
NULL);
ourThreadID = GetCurrentThreadId();
// If not, attach our thread's 'input' to the foreground thread's
if (foregroundThreadID != ourThreadID)
AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
// Bring our window to the foreground
SetForegroundWindow(hWnd);
// If we attached our thread, detach it now
if (foregroundThreadID != ourThreadID)
AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
// Force our window to redraw
InvalidateRect(hWnd, NULL, TRUE);
}
What the code does is actually sends input to the thread that has the focus, and makes it think that the window belongs in that thread, thus successfully brings the window in front
|