how to activate an application?

  • Thread starter Thread starter zhou
  • Start date Start date
This can be achieved by windows api's

Add the definitions inside your class

[DllImportAttribute( "User32.dll" )]
private static extern int FindWindow( String ClassName, String
WindowName );
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( int hWnd );


//to activate an application
int hWnd = FindWindow( null, "This is my Application Title" );
if( hWnd > 0 )
{
SetForegroundWindow( hWnd );
}

Shak.
 
This is approach will not work when at user desktop there is an explorer
window open with same title as your application title.

--------------------------------------------
Manish Agarwal <[email protected]>
http://personal.vsnl.com/mkag


Shakir Hussain said:
This can be achieved by windows api's

Add the definitions inside your class

[DllImportAttribute( "User32.dll" )]
private static extern int FindWindow( String ClassName, String
WindowName );
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( int hWnd );


//to activate an application
int hWnd = FindWindow( null, "This is my Application Title" );
if( hWnd > 0 )
{
SetForegroundWindow( hWnd );
}

Shak.


zhou said:
in Visual Basic ,I use
Appactivate(AcadApp.caption);
 
This approach will not work when at user desktop there is an explorer
window open with same title as your application title.

--------------------------------------------
Manish Agarwal <[email protected]>
http://personal.vsnl.com/mkag


Shakir Hussain said:
This can be achieved by windows api's

Add the definitions inside your class

[DllImportAttribute( "User32.dll" )]
private static extern int FindWindow( String ClassName, String
WindowName );
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( int hWnd );


//to activate an application
int hWnd = FindWindow( null, "This is my Application Title" );
if( hWnd > 0 )
{
SetForegroundWindow( hWnd );
}

Shak.


zhou said:
in Visual Basic ,I use
Appactivate(AcadApp.caption);
 
This approach will not work when at user desktop there is an explorer
window open with same title as your application title.

--------------------------------------------
Manish Agarwal <[email protected]>
http://personal.vsnl.com/mkag


Shakir Hussain said:
This can be achieved by windows api's

Add the definitions inside your class

[DllImportAttribute( "User32.dll" )]
private static extern int FindWindow( String ClassName, String
WindowName );
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( int hWnd );


//to activate an application
int hWnd = FindWindow( null, "This is my Application Title" );
if( hWnd > 0 )
{
SetForegroundWindow( hWnd );
}

Shak.


zhou said:
in Visual Basic ,I use
Appactivate(AcadApp.caption);
 
Manish,

Multiple instances of same application will have same titiles. To over come
this, we have to get process ids, to identify which one we want to activate.

for example

Process [] apps = Process.GetProcessesByName("TestAppName")

Now if we decide which one we want from this process list to be activated,
pass the handle to SetForegroundWindow() function to activate it.

example:

SetForegroundWindow(app[0].Handle.ToInt32 ()); //assuming that 1st process
id is the one we want to activate.

Shak.




Manish Agarwal said:
This is approach will not work when at user desktop there is an explorer
window open with same title as your application title.

--------------------------------------------
Manish Agarwal <[email protected]>
http://personal.vsnl.com/mkag


Shakir Hussain said:
This can be achieved by windows api's

Add the definitions inside your class

[DllImportAttribute( "User32.dll" )]
private static extern int FindWindow( String ClassName, String
WindowName );
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( int hWnd );


//to activate an application
int hWnd = FindWindow( null, "This is my Application Title" );
if( hWnd > 0 )
{
SetForegroundWindow( hWnd );
}

Shak.


zhou said:
in Visual Basic ,I use
Appactivate(AcadApp.caption);
 
Back
Top