|
-
Jul 9th, 2002, 12:47 AM
#1
Thread Starter
Addicted Member
showing main window of prev running application
if a prev existance of application is running and i again run another instance of tht application then i want to popup that prev. application's main window in front as happens in Messengers .. and terminate newly created instance what to do for tht ..
some thing like this in VB
if app.previnstance then
' popup main window/form of previos running application
termination of newly instance of application ..
endif
ne idea on it ??
-
Jul 10th, 2002, 08:01 PM
#2
You'd use a named mutex object for this - look it up in MSDN
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 10th, 2002, 08:40 PM
#3
Fanatic Member
Code:
HANDLE hMutex;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
hMutex = CreateMutex( NULL, FALSE, _T("ApplicationName") );
if ( hMutex && (GetLastError() == ERROR_ALREADY_EXISTS )) {
//Find Correct Window&Send to front;
}
//.....blah blah blah
return 0;
}
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Jul 11th, 2002, 12:22 AM
#4
PowerPoster
how abt this? AS i does not use Mutex before, pls coreect me, if my method is not a proper way 
PHP Code:
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Check for previous instance
hWnd = FindWindow(TEXT("ClassName"), TEXT("WindowsTitle"));
if (hWnd != NULL)
{
// Show the previous window
SetForegroundWindow(hWnd);
// Unload the current instance
return false;
}
// Register application define class into windows system
// Perform application initialization:
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
-
Jul 13th, 2002, 08:52 PM
#5
Chris: This method works too, as long as the app has a non-dialog main window.
SetForegroundWindow is API and is used to bring the existing app to top.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|