Click here to Skip to main content
15,887,453 members
Home / Discussions / C#
   

C#

 
AnswerRe: Find Internet Server IP address Pin
Mirko198017-Jul-09 1:52
Mirko198017-Jul-09 1:52 
GeneralRe: Find Internet Server IP address Pin
harold aptroot17-Jul-09 2:47
harold aptroot17-Jul-09 2:47 
GeneralRe: Find Internet Server IP address Pin
Mirko198017-Jul-09 3:25
Mirko198017-Jul-09 3:25 
GeneralRe: Find Internet Server IP address Pin
harold aptroot17-Jul-09 3:33
harold aptroot17-Jul-09 3:33 
GeneralRe: Find Internet Server IP address Pin
Mirko198017-Jul-09 3:59
Mirko198017-Jul-09 3:59 
GeneralRe: Find Internet Server IP address Pin
harold aptroot17-Jul-09 4:22
harold aptroot17-Jul-09 4:22 
AnswerRe: Find Internet Server IP address Pin
harold aptroot17-Jul-09 2:49
harold aptroot17-Jul-09 2:49 
QuestionHow to bring a window to foreground on Vista? Pin
verence33317-Jul-09 0:38
verence33317-Jul-09 0:38 
Hi all.

I've spent 3 days searching for this and trying different alternatives, but nothing works.

I have an app which works perfectly on Windows XP:

1) Monitorizes some windows.
2) When one of them reaches a certain state, my app brings it to the foreground.
3) Then, does something with it (moves the mouse, clicks something...).
4) Finally, my app brings to the foreground the window that was visible before step 2, so the user can resume his work where he was before.

My problem is that, when I execute this app on Windows Vista, the step 4) seems not to work. I've been reading a lot these days, and I've found that the "SetForegroundWindow()" method I was using works differently on Vista, so I started using "AttachThreadInput()" following an example that I found somewhere:

private void activateWindow(IntPtr hWnd)
{
    if (IsIconic(hWnd))
        ShowWindowAsync(hWnd, SW_RESTORE);

    ShowWindowAsync(hWnd, SW_SHOW);

    SetForegroundWindow(hWnd);

    IntPtr foregroundWindow = GetForegroundWindow();
    IntPtr Dummy = IntPtr.Zero;

    uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, Dummy);
    uint thisThreadId = GetWindowThreadProcessId(hWnd, Dummy);

    if (AttachThreadInput(thisThreadId, foregroundThreadId, true))
    {
        BringWindowToTop(hWnd);
        SetForegroundWindow(hWnd);
        AttachThreadInput(thisThreadId, foregroundThreadId, false);
    }

    if (GetForegroundWindow() != hWnd)
    {
        IntPtr Timeout = IntPtr.Zero;
        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, SPIF_SENDCHANGE);
        BringWindowToTop(hWnd);
        SetForegroundWindow(hWnd);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, SPIF_SENDCHANGE);
    }
}


From my app, I do the following when a timer ticks and finds that one of the background windows must be activated:

IntPtr originalWHwnd = GetForegroundWindow();   //To keep the handle of the window in which the user is currently working.

/* Let's say that window with handle "hWnd" must be visible now: */
activateWindow(hWnd);  //It works in Vista and XP: brings the window to foreground.

/*
    Here I do the stuff with the window "hWnd":
     - move the mouse somewhere,
     - click somewhere else...
     */

/* Finally I want to bring back the original window: */
activateWindow(originalWHwnd);  //It does not work on Vista; it does on XP.


That code still works on Windows XP, but still doesn't work on Vista: step 4 will not bring to foreground the first window.

Please, could you enlighten me?

Thanks in advance.
AnswerRe: How to bring a window to foreground on Vista? Pin
musefan17-Jul-09 1:20
musefan17-Jul-09 1:20 
GeneralRe: How to bring a window to foreground on Vista? Pin
verence33317-Jul-09 1:45
verence33317-Jul-09 1:45 
AnswerRe: How to bring a window to foreground on Vista? Pin
Simon P Stevens17-Jul-09 1:24
Simon P Stevens17-Jul-09 1:24 
GeneralRe: How to bring a window to foreground on Vista? Pin
verence33317-Jul-09 1:58
verence33317-Jul-09 1:58 
AnswerRe: How to bring a window to foreground on Vista? Pin
Luc Pattyn17-Jul-09 1:33
sitebuilderLuc Pattyn17-Jul-09 1:33 
GeneralRe: How to bring a window to foreground on Vista? Pin
verence33317-Jul-09 2:01
verence33317-Jul-09 2:01 
AnswerRe: How to bring a window to foreground on Vista? Pin
verence33319-Jul-09 20:09
verence33319-Jul-09 20:09 
QuestionError Pin
john563217-Jul-09 0:32
john563217-Jul-09 0:32 
AnswerRe: Error Pin
0x3c017-Jul-09 0:35
0x3c017-Jul-09 0:35 
GeneralRe: Error Pin
john563217-Jul-09 0:55
john563217-Jul-09 0:55 
GeneralRe: Error Pin
0x3c017-Jul-09 1:05
0x3c017-Jul-09 1:05 
GeneralRe: Error Pin
john563217-Jul-09 1:35
john563217-Jul-09 1:35 
GeneralRe: Error Pin
0x3c017-Jul-09 1:44
0x3c017-Jul-09 1:44 
GeneralRe: Error Pin
john563217-Jul-09 2:33
john563217-Jul-09 2:33 
QuestionC# compression Pin
GauravKP17-Jul-09 0:05
professionalGauravKP17-Jul-09 0:05 
AnswerRe: C# compression Pin
Luc Pattyn17-Jul-09 0:20
sitebuilderLuc Pattyn17-Jul-09 0:20 
AnswerRe: C# compression Pin
Alan Balkany17-Jul-09 3:53
Alan Balkany17-Jul-09 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.