Hello,
I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.
+void ReallySetForegroundWindow( HWND ahWnd )
+{
+ DWORD foregroundThreadID; // foreground window thread
+ DWORD ourThreadID; // our active thread
+ static char foo[1024];
+ HWND h = GetForegroundWindow();
+
+ // If the window is in a minimized state, maximize now
+ if (GetWindowLong(ahWnd, GWL_STYLE) & WS_MINIMIZE)
+ {
+ ShowWindow(ahWnd, SW_MAXIMIZE);
+ UpdateWindow(ahWnd);
+ }
+
+ // 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(ahWnd);
+
+ // Set focus.
+ SetFocus( ahWnd );
+
+ // If we attached our thread, detach it now
+ if (foregroundThreadID != ourThreadID)
+ AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
+
+ // Force our window to redraw
+ InvalidateRect(ahWnd, NULL, TRUE);
+}/Fredrik