Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to swap applications suppose I have create two process using

Process pro1 = run.exec("C:\\Windows\\System32\\notepad.exe");
Process pro2 = run.exec("C:\\Windows\\System32\\calc.exe");

Recent application will have focus, Simply I want to change focus of windows from calc.exe to the notepad.exe.


Thanks in Advance to solve my trouble.
Posted

Using DLL import -
C#
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


void ActivateProcess(int PID)
{
    Process proc = Process.GetProcessById(PID);
    IntPtr mainWindow = proc.MainWindowHandle;
    ShowWindow(mainWindow, 5);  // 5 == SW_SHOW
 }
 
Share this answer
 
Comments
Nei Sa 11-Mar-14 9:37am    
@Abhinav Thanks for your positive response..

I have tried to use ShowWindow() but It doesn't supports the HInstance type it can support only hwnd type...
C#
window = user32.FindWindow("notepad", null);
user32.SwitchToThisWindow(window,true);
 
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