Click here to Skip to main content
15,889,631 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to launch winword from my java application.Word application is getting launched successfully. But word application window is going in background on Vista (losing focus).But same code works well on XP.
In Xp word application window gets focus.

I tried below to bring Word Application in Front ..but not getting correct results

WINWAKEUP_API int WakeUp(TCHAR WndTitle[])
{

TCHAR String[255]= {0};
_tcscpy(String,WndTitle);
EnumWindows(XEnumProc,(LPARAM)String);
return 0;
}

BOOL CALLBACK XEnumProc(HWND hWnd, LPARAM lParam)
{
HWND hTest = NULL;
TCHAR title[280];
if (!hWnd)
return TRUE; // Not a window
if (!::IsWindowVisible(hWnd))
return TRUE; // Not visible
GetWindowText(hTest, "Test1", 6);
GetWindowText(hWnd, title, sizeof(title));
if(_tcsstr(title, (TCHAR *)lParam)) {
SwitchToThisWindow(hWnd,TRUE);
//SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
SetWindowPos(HWND_TOPMOST,hTest,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
HWND hActiveWnd = ::SetActiveWindow(hTest);
::SetForegroundWindow(hTest);
SetFocus(hActiveWnd);
return FALSE;
}
return TRUE;
}

Can anybody pls help in fixing this issue ?


Thanks,
Sanjay
Posted

1 solution

You could also try BringWindowToTop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900