|This tip was submitted by Loganathan
Only one instance of any application running at a time is good to make it
simple and sleek. In this discussion we are going to see how to make your application run
When user double clicks on your application icon, first try to see if it is already
running. If it is already running bring it to top and return. There are some sleek SDK
functions you can make use of to implement this. The following are the steps to create
1. Create a non-visual user object 'n_cst_win32sdk' with following local functions and
FUNCTION boolean ShowWindow( ulong winhandle,&
int wincommand ) Library "user32"
FUNCTION boolean BringWindowToTop( ulong HWND )&
FUNCTION long FindWindowA( ulong Winhandle, &
string wintitle ) Library "user32"
Of_FindWindowByTitle( string as_wintitle )
Return FindWindowA( 0, as_wintitle )
Of_ShowWindow( unsignedlong al_winhandle )
Return ShowWindow( al_winhandle, 5 )
Of_BringToTop( unsignedlong al_winhandle )
Return BringWindowToTop( al_winhandle )
2. Create a small test window 'w_test' with one close button to close the window. Give
window the title "First Window".
3. In the application Open event code the following:
If Not IsValid( lnv_sdk ) Then
lnv_sdk = Create n_cst_win32sdk
ll_winhandle = &
lnv_sdk.of_FindWindowByTitle( "First Window" )
If ll_winhandle > 0 Then
lnv_sdk.of_BringToTop( ll_winhandle )
lnv_sdk.of_ShowWindow( ll_winhandle )
Open( w_sdktest )
If the window is found, it means it is already running, so bring the window to top and
return. The Source code to this user object can be found on the software page.