SetForegroundWindow() Works Inconsistently

ms windows

    Sponsored Links

    Next

  • 1. Got it - was: InternetOpen & InternetCloseHandle
    Jerry Coffin wrote: > In article <eDeHi.131290$ XXXX@XXXXX.COM >, > XXXX@XXXXX.COM says... >> I am working on a prog that requires Inet >> access. I have created a function call that will >> contain the basic open/close operations. >> >> I have created the handle hInternet and the >> 'Open' and 'Close' calls. >> >> Both produce linker errors for undefined call. >> >> This implies the wrong (or missing) *.h file in >> the includes. > > If the code compiles, the headers are almost certainly being included > correctly. If it fails to link, that indicates that the necessary > library is not being specified to the linker. You need to specify > wininet.lib to the linker. > Dev-C++ does not call the library 'wininet.lib'. Instead it is called libwininet.a. Hence a search didn't work. When I searched for '*wininet* I got teh DLL and the Dev-C++ library file. Thanks for the guidance.
  • 2. internetOpen & InternetCloseHandle
    I am working on a prog that requires Inet access. I have created a function call that will contain the basic open/close operations. I have created the handle hInternet and the 'Open' and 'Close' calls. Both produce linker errors for undefined call. This implies the wrong (or missing) *.h file in the includes. #include <wininet.h> is present and I take it this is the correct include for the job; if not please advise. Also, MSDN says that the proxy string should be NULL not an empty string. In the case of string is there any difference? Surely a NULL string is one that has \x00 in the first byte. Please advise if I am mistaken TIA D.
  • 3. Writing data to a serial port and buffering?
    When WriteFile returns true, does that mean the data is successfully send to the device, or is it possible only stored in the internal buffer? I'm using non-overlapped i/o without write timeouts (both the multiplier and the constant set to zero). And what if I do use a timeout?
  • 4. DDE Callback not working
    Hi. I've written a DDE programme that does everything like it should. It initialises. connects and gets data, all ok but for some reason the DDECallback function doesn't do anything. I've checked i've passed the right address and everything is ok on that front but for some reason it's ignoring traffic. Has anyone had any success with DDE Callback? Thanks
  • 5. confused include
    Hello, I'm a novice programmer. I inserted the below code into a simple compilable app that previously had no errors or warnings. I get this same error no matter what I do. What confuses me is the fact that when I put the cursor on the item causing the error and press F12 it immediately goes to the delcaration in the include file. So why am I getting this error ? compiling... Text2b.cpp C:\PROGRAMMING\VC_6_PROJECTS\TEXT2\Text2b\Text2b.cpp(180) : error C2065: 'g_hfFont' : undeclared identifier ///* insert exp code long lfHeight; hdc = GetDC(NULL); lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(NULL, hdc); hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman"); if(hf) { DeleteObject(g_hfFont); g_hfFont = hf; } else { MessageBox(hWnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION); } //End exp code //*/

SetForegroundWindow() Works Inconsistently

Postby mintdiesel » Tue, 19 May 2009 02:14:06 GMT

I am using SetForegroundWindow() to set the foreground window.  Most
of the time it works fine.  Sometimes, however, instead of putting the
window in the foreground and activating it, only the taskbar rectangle
for the window is depressed as it is when the window is successfully
brought to the foreground and activated but the window isn't brought
to the foreground and activated (the rectangle isn't flashed as
described by other people who have similar problems).

Some more information:

1. I'm currently using BringWindowToTop() and SetWindowPos() in
addition to SetForegroundWindow():

BringWindowToTop(hwnd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
SWP_SHOWWINDOW);
SetForegroundWindow(hwnd);

2. I've tried using the solutions suggested in these threads, but I
got the same behavior with all of them:

 http://www.**--****.com/ #9cbb53153bea48cb

 http://www.**--****.com/ #74fa3ac0508b6660

 http://www.**--****.com/ #dd2756d8ea1a552b

3. I've tried using SwitchToThisWindow() and still got the same
behavior.

4. When the problem happens, keyboard focus is set to the window I
want to activate (i.e. if I press Alt+F, I get the "File" menu of the
window I want to activate - it appears/floats on top of the currently
activated foreground window).

5. My application is the foreground window when it runs the code to
bring the other window to the foreground and activate it (so it should
have permission to do so according to MSDN and so
AllowSetForegroundWindow() is not necessary).

6. I am using Windows XP


That given, does anybody know of a way to consistently bring a window
to the foreground and activate it?

Re: SetForegroundWindow() Works Inconsistently

Postby domi » Wed, 20 May 2009 11:43:44 GMT



You should define "sometimes" and which exact code you use ( 
SPI_SETFOREGROUNDLOCKTIMEOUT + AttachThreadInput ?), so we can try to 
reproduce it...

Re: SetForegroundWindow() Works Inconsistently

Postby mintdiesel » Mon, 25 May 2009 03:34:33 GMT





The problem happens sporadically.  I just keep trying to bring a
window to the foreground - It works most of the time and then for some
reason it fails (i.e. the problem happens).  I've tried to find out
what causes the problem to happen, but have not been able to.

To reproduce it, you could have a program that while being in the
foreground, brings other programs' windows to the foreground; that's
what I'm doing.  As for specific code, the same problem happened with
the code below but also with the code suggested as a solution in the
threads I listed.  But if the goal is just to reproduce the problem,
then the code below
should be sufficient.

BringWindowToTop(hwnd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
SWP_SHOWWINDOW);
SetForegroundWindow(hwnd);

By the way, almost the exact same code is used in:
 http://www.**--****.com/ 
- download TaskSwitchXP_2.0.11-src.zip.  But although I tried, I could
not get the problem to reproduce using TaskSwitchXP (and incidentally,
I don't know what the difference between my application and
TaskSwitchXP is).

Re: SetForegroundWindow() Works Inconsistently

Postby trulytruly » Mon, 25 May 2009 16:32:15 GMT






I think you'd have to either post a link to the source so someone else
can check it out, or you get more into detail about the actual
implementation (with snippets).

Regards,
Reto

Re: SetForegroundWindow() Works Inconsistently

Postby Jerome » Mon, 25 May 2009 19:13:14 GMT


 XXXX@XXXXX.COM ...


You must call AttachThreadInput() to the foreground window





Similar Threads:

1.SetForegroundWindow(hwnd) don't work on my dell with mobile 2003 se

Hello!

I tried to get my running application in foreground when it was startet a
second time with the following code. But my running App window don't went in
foreground. have anyone a idea what i can do?

My Code:

Declare Function GetLastError Lib "coredll" () As Long

Declare Function CreateMutex Lib "coredll" Alias "CreateMutexW" _
(lpMutexAttributes As Long, ByVal bInitialOwner As Long, ByVal lpName As _
String) As Long

Declare Function FindWindow Lib "coredll" Alias "FindWindowW" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function SetForegroundWindow Lib "coredll" (ByVal hwnd As Long) As
Long

Private Sub Form_Load()

   Dim foo
   Dim hwnd

   CreateMutex CLng(0), 1, App.Title

   If GetLastError() = ERROR_ALREADY_EXISTS Then
      MsgBox "ENER:CE lft schon! 2. Start wird beendet"

      hwnd = FindWindow("frmMain", "ENER:CE") ' "frmMain" = frmMain.name,
"Caption" = frmMain.caption
      foo = SetForegroundWindow(hwnd)
      foo = SetForegroundWindow(hwnd)
      App.End

   Else
      ....


2.scripts work inconsistently

I am brand new to scripting. The snippet below seems to run on the
majority of boxes I place it on, but fails following the "opendlg" 
with "err# 424, object required", on some, even though they have the
exact same versions of wsh, vbscript, wmi, and adsi. Any help would be
appreciated.

On Error Resume Next

dim WshShell, email

const olMailItem = 0, CreateFile = true, NoCreateFile = false,
ForReading = 1, ForWriting = 2, ForAppending = 3, Append2File = 8,
TristateFalse = 0

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oApp     = CreateObject("Outlook.Application")
Set email    = oApp.CreateItem(olMailItem)

strInFileOpen = OpenDlg(UCASE(wscript.Scriptname) &" - Open
File","Checkfree Rxx file","toscwc.*.r??")

3.Location change of my documents works inconsistently

Hi, i have several user accounts in win xp.
I tried to change locations to another drive. In two of the accounts, this 
works for all folders under Documents and settings. The have moved to the 
other drive.
But for two other accounts, only the MyDocuments folder itself has moved, 
and the rest is still occupying space with application data, local settings, 
etc.
What can i do to make all the files under a single user account move to 
another location and not just the files in my documents?

4.SetForegroundWindow/SendInput timing problems

Claus Tondering wrote:
> I'm using SetForegroundWindow followed by SendInput to send keystrokes
> to another program.
> 
> The problem is that apparently it takes some time for Windows (Vista
> in my case) to process the SetForegroundWindow request: Some of
> keystrokes sent by SendInput are lost. But if I call Sleep(50) between
> SetForegroundWindow and SendInput, everything works fine!
> 
> I've tried checking GetForegroundWindow immediately after
> SetForegroundWindow, but this does not help. GetForgroundWindow has
> the new value immediately.
> 
> In my opinion, calling Sleep(50) is very ugly. How do I know that 50
> ms is always enough? Is there any way I can be sure that my SendInput
> reaches the correct destination?
> 
> --
> Claus

The time delay can't be avoided. This can happen if its memory is in the 
pagefile and the system needs to move it to the physical memory. Or the 
window needs to reinitialize some things each time it become active.

The Sleep is one of the solution, however, we don't know how long the 
window takes in order to be ready to receive inputs. A better solution 
is to use WaitForInputIdle function. Call it after setting the window to 
the foreground.

Consider calling IsHungAppWindow before setting the window to the 
foreground.

5.Windows Server 2003 SetForegroundWindow

I'm using Windows Server 2003 as a server and Windows XP as a client. 
On both of them I'm creating an event to SetForegroundWindow on another 
machine. It works from Server 2003 to XP but doesn't work from XP to Server 
2003. I tried a combination of many functions. Is there a way to 
SetForegroundWindow on Server 2003 or it is not allowed by design? Thanks.

6. Get handle for last active window for SetForeGroundWindow

7. Problems with SetForegroundWindow(), especially in Vista.

8. SetForegroundWindow



Return to ms windows

 

Who is online

Users browsing this forum: No registered users and 64 guest