Hi folks,
I got a requirement in my project where in when my application is activated another window should get activated and upon it my application should be present. Both should be in restored state not maximised.
To accomplish this, in the activated event of my MainForm I first activated the other window and then activated my window.
I've implemented the following piece of code in the activated event of my MainForm:
private void MainForm_Activated(object sender, EventArgs e) {
Process[] proc = Process.GetProcessesByName("IEXPLORE");
foreach(Process p in proc){
if(p.MainWindowTitle.Equals("Hi - Microsoft Internet Explorer")){
IntPtr hwnd = p.MainWindowHandle;
SetForegroundWindow(hwnd);
ShowWindow((int)hwnd,1);
this.Activated -= new EventHandler(MainForm_Activated);
SetForegroundWindow(this.Handle);
ShowWindow((int)this.Handle,1);
this.Activated += new EventHandler(MainForm_Activated);
return;
}
}
}
But this code is not working properly all the times.
When both the windows are minimised it works fine but when both are in restored state when my mainform is activated the other window comes to front but my MainForm never comes to front. Also, i am unable to minimize my application from taskbar as the activated event is getting fired andboth the windows are being restored. But, i am able to minimize from the minimize button on the form.
Can anybody propose me a solution with reasons(comments)
Thanks in advance,
Pavan..