Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move window to the front

Status
Not open for further replies.

AbelMorelos

Programmer
Jun 10, 2005
6
MX
Hello guys! I'm a Java programmer switching to C++(I'm starting to like this language but I´m very far of being good enought with C++)... and for now I need the assistance of some experts.

I have a Java application running under the "System" account, and I have to launch a GUI(display a chm file) when the user presses a "Help" button. When you press this button, I send a message(using JNI) to a NamedPipe to spawn the needed process, I'm doing this because I need this process to run under the current logged user account in Windows instead of the System account. But I have a problem, in some machines this GUI appears in the front of my application, and this is ok, but in other machines my Help window is behind my application(it seems to be happening always in Win2k and in some machines with XP). The question is: There is some way to force my Help window to be always in the front? I'm using a CreateProcess call to launch the Help window... I already tried many things with hShowWindow and STARTUPINFO parameters... and nothing.

This defect was assigned to me, because the code owner is on vacations, so, help plese!

(I already had posted this question in other forum, but I just found this was right place this, sorry if you noticed the duplicated post)

Regards!
Abel Morelos
 
FindWindow to get the hwnd of the window then call SetForeGroundWindow(HWND)
 
Well, your answer wasn't exactly what I needed... but it helped me to figure the final solution! Thanks a lot!

This is the code:
Code:
if(!CreateProcess(
			     NULL, //executable
                 chRequest,		//command line
                 NULL,					//default process security attributes
                 NULL,					//default thread  security attributes
                 FALSE,					//Do not inherit handles
                 CREATE_DEFAULT_ERROR_MODE, //default error mode
                 NULL,					//same environment
                 NULL,			//current directory
                 &sInfo,				//startup information
                 &pInfo
		)){
			//If the process couldn't be created
			lstrcpy( chReply,TEXT("ERROR"));
			*pchBytes = (lstrlen(chReply)+1)*sizeof(TCHAR);
::EnumWindows(&EnumWindowsProc,pInfo.dwThreadId);

...
/*I found the following code in [URL unfurl="true"]http://www.codeguru.com/forum/archive/index.php/t-229929.html,[/URL] I just added a line to make it work for my application*/
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{

	DWORD id = GetWindowThreadProcessId(hwnd, NULL);
	if (id == (DWORD)param){
			SetForegroundWindow(hwnd);
			return false;
        }
	return true;
}
 
Well, I get too excited the last time... I had to do more tests... It seems to work sometimes, but not all the time. What is missing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top