Application Activation using VC

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



hi,
I am working with a ICA32 citrix client from windows xp, where I
am trying to use some automation through citrix client so that I can
unmann a tedious file-copy through one of the published apps (Windows
Explorer). I've tried it through VB and found out that SendKeys wont
work with Citrix, so I switched to VC. With some googling this is where
I've reached.

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);
}

I am using an .ICA file which has a predefined credentials so that
login is automated, but before I log in to Citrix, there is a network
login-warning message that pops up and I need to hit an ENTER here
programmatically. So, I am trying to bring the small dialog to the
front and send it a VK_RETURN with some code like this:

Sleep(2000);
PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0x8001);
PostMessage(hWnd, WM_KEYUP, VK_RETURN, 0xc001);

however, this doesnt happen coz the dialog box never activates! I can
see that the application is set to the foreground but the window to
which ENTER has to be sent looks inactive!! It really doesnt make any
sense as the HWND obtained thru spy++ is exactly the one I am passing
to this function.

can anyone please throw some light on to why this could happen? Am I
doing something wrong?

.



Relevant Pages

  • Re: running an application in foreground?
    ... > I have an executable file lanuched from another application. ... DWORD foregroundThreadID; // foreground window thread ... DWORD ourThreadID; // our active thread ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Application Activation using VC
    ... an application cannot force a window to the foreground ... Background Windows will activate the window and call ... > I am working with a ICA32 citrix client from windows xp, ... > ourThreadID = GetCurrentThreadId; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Bizarre background window behavior in Word
    ... while one of the inactive open documents will randomly move to ... the inactive window now in the foreground ... the active window that is now hidden in the background. ... McGhie Information Engineering Pty Ltd ...
    (microsoft.public.mac.office.word)
  • Re: Windows 2003 server SetForegroundWindow|BringWindowToTop|SetWi
    ... And I see the exception with any Window form not only with mine, ... a process can only set the foreground window if it is already the foreground ... I tryed the same program on Window XP with the operator level and it is ...
    (microsoft.public.vc.mfc)
  • Re: BringWindowToFront/SetForegroundWindow problem
    ... full-screen window and pushing it to the bottom before trying to bring up the previous app. ... means you no longer have the foreground window status, and thus lose some ability to bring another ... the message loop has activated to handle the Registered Window Message. ...
    (microsoft.public.vc.mfc)