FreeProcess: process window can be foreground

BlitzMax Forums/BlitzMax Module Tweaks/FreeProcess: process window can be foreground

JoshK(Posted 2012) [#1]
You may have experienced problems with a launch process not being able to grab the window focus. This fix will fix it so all processes your application launches can self-activate their main window.

You only need to edit the freeprocess.c file.

1. Add this code somewhere near the top of the file:
#ifdef _WIN32
extern BOOL WINAPI AllowSetForegroundWindow(DWORD dwProcessId);
#endif


2. Find this line of code:
	int pflags=CREATE_NEW_PROCESS_GROUP;

And change it to this:
	int pflags=CREATE_NEW_PROCESS_GROUP | CREATE_SUSPENDED;


3. Find this line of code:
CloseHandle( pi->hThread );

And replace it with this:
//------------------------------------------
	AllowSetForegroundWindow(-1);
	ResumeThread(pi->hThread);	
//------------------------------------------
	
	CloseHandle( pi->hThread );


That's it! Here's the whole code:



xlsior(Posted 2012) [#2]
Should probably be submitted to a change to the official build?