Application Activation using VC

K

kill.segfault

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?
 
B

Bruno van Dooren

could this be your problem? (see below)
i had the same problem once, and it was caused by this.

see
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setforegroundwindow.htm
for more info.

kind regards
Bruno.

With this change, an application cannot force a window to the foreground
while the user is working with another window. Instead, Foreground and
Background Windows will activate the window (see SetActiveWindow) and call
the function to notify the user. However, on Microsoft® Windows® 98 and
Windows Millennium Edition (Windows Me), if a nonforeground thread calls
SetForegroundWindow and passes the handle of a window that was not created
by the calling thread, the window is not flashed on the taskbar. To have
SetForegroundWindow behave the same as it did on Windows 95 and Microsoft
Windows NT® 4.0, change the foreground lock timeout value when the
application is installed. This can be done from the setup or installation
application with the following function call:

SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,
SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
This method allows SetForegroundWindow on Windows 98/Windows Me and Windows
2000/Windows XP to behave the same as Windows 95 and Windows NT 4.0,
respectively, for all applications.
 
K

kill.segfault

Bruno, Thanks for the response. I tried what you said. But, It didnt
work.
The window never gets active!
I've learnt from SPy++ that the class of window is "Transparent Windows
Client"!
I never heard about anything of this sort. Any ideas?
 
B

Bruno van Dooren

sorry, not for the moment. your situation is different from mine.
should i think of anything else i'll let you know.

kind regards,
Bruno.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top