What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » setForegroundWindow - BringWindowToTop [???]

setForegroundWindow - BringWindowToTop [???]
Author: Message:
XM4ST3RX
Full Member
***

Avatar
DJ Scoop!

Posts: 172
Reputation: 12
37 / Male / –
Joined: May 2003
O.P. setForegroundWindow - BringWindowToTop [???]
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
06-14-2005 11:50 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: setForegroundWindow - BringWindowToTop [???]
SetForegroundWindow will bring the window infront of everything else except those windows that are set to "Always On Top"
06-15-2005 01:40 AM
Profile E-Mail PM Find Quote Report
XM4ST3RX
Full Member
***

Avatar
DJ Scoop!

Posts: 172
Reputation: 12
37 / Male / –
Joined: May 2003
O.P. RE: setForegroundWindow - BringWindowToTop [???]
Hi,

Could you please paste the function, maybe im not doing it correctly.


Kind Regards,
XM4ST3RX
06-15-2005 01:41 AM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: setForegroundWindow - BringWindowToTop [???]
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

This post was edited on 06-15-2005 at 02:19 AM by matty.
06-15-2005 02:15 AM
Profile E-Mail PM Find Quote Report
XM4ST3RX
Full Member
***

Avatar
DJ Scoop!

Posts: 172
Reputation: 12
37 / Male / –
Joined: May 2003
O.P. RE: setForegroundWindow - BringWindowToTop [???]
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

This post was edited on 06-15-2005 at 02:20 AM by XM4ST3RX.
06-15-2005 02:18 AM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: setForegroundWindow - BringWindowToTop [???]
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

This post was edited on 06-15-2005 at 02:24 AM by matty.
06-15-2005 02:24 AM
Profile E-Mail PM Find Quote Report
XM4ST3RX
Full Member
***

Avatar
DJ Scoop!

Posts: 172
Reputation: 12
37 / Male / –
Joined: May 2003
O.P. RE: setForegroundWindow - BringWindowToTop [???]
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 (Y).



Kind Regards,
XM4ST3RX
06-15-2005 02:30 AM
Profile E-Mail PM Web Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
RE: setForegroundWindow - BringWindowToTop [???]
code:
AppActivate "Window Caption"


then just use api's like

findwindow, getwindowtext :)

This post was edited on 06-15-2005 at 06:30 AM by Stigmata.
06-15-2005 06:29 AM
Profile PM Web Find Quote Report
TazDevil
Full Member
***

Avatar
sleep(0);

Posts: 359
Reputation: 11
40 / Male / Flag
Joined: May 2004
RE: setForegroundWindow - BringWindowToTop [???]
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 :D

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

This post was edited on 06-17-2005 at 11:11 AM by TazDevil.
Window Manager is discontinued, for WLM try the new,
Enhancer for contact list docking, auto-hide, hide taskbar button, remove button flashing and remember keyboard layout in conversation windows
06-17-2005 11:07 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On