home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- From: chris@chrism.demon.co.uk (Chris Marriott)
- Path: sparky!uunet!pipex!demon!chrism.demon.co.uk!chris
- Subject: Re: Enabling the first and only window in MFC
- Distribution: world
- References: <C0Fyw0.3pq@pcuf.fi>
- Organization: None
- Reply-To: chris@chrism.demon.co.uk
- X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
- Lines: 56
- Date: Fri, 8 Jan 1993 19:34:48 +0000
- Message-ID: <726521688snz@chrism.demon.co.uk>
- Sender: usenet@demon.co.uk
-
- In article <C0Fyw0.3pq@pcuf.fi> turre@pcuf.fi writes:
-
- >I want user not to be able to run many instances of my application. So if
- >he tries to run another instance my program should bring the first
- >instance to top. I've been trying it with this following code:
- >
- >BOOL CMyApp::InitInstance()
- >{
- > If( m_hPrevInstance != NULL )
- > {
- > m_pMainWindow->BringWindowToTop();
- > return FALSE;
- > }
- > else
- > {
- > m_pMainWindow = new CMyWindow;
- > m_pMainWindow->ShowWindow( m_nCmdShow );
- > m_pMainWindow->UpdateWindow();
- > return TRUE;
- > }
- >}
- >
- >The first instance runs fine and no other instances are displayed or created
- >but the first windows is not brought to the top.
- >
-
- No - your code is wrong! This code:
-
- > If( m_hPrevInstance != NULL )
- > {
- > m_pMainWindow->BringWindowToTop();
- > return FALSE;
- > }
-
- brings *your* window to the top, not that of the previous instance.
- Sorry I don't know MFC or whatever it is you're using here, but what
- you want to do is:
-
- if (m_hPrevInstance!=NULL)
- {
- hWnd = FindWindow( "MyAppClassName", NULL );
- BringWindowToTop( hWnd );
- return FALSE;
- }
-
- That will do the trick.
-
- Chris
- --
- --------------------------------------------------------------------------
- | Chris Marriott | chris@chrism.demon.co.uk |
- | Warrington, UK | BIX: cmarriott |
- | (Still awaiting inspiration | CIX: cmarriott |
- | for a witty .sig .... ) | CompuServe: 100113,1140 |
- --------------------------------------------------------------------------
-
-