home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4765 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.1 KB  |  71 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. From: chris@chrism.demon.co.uk (Chris Marriott)
  3. Path: sparky!uunet!pipex!demon!chrism.demon.co.uk!chris
  4. Subject: Re: Enabling the first and only window in MFC 
  5. Distribution: world
  6. References: <C0Fyw0.3pq@pcuf.fi>
  7. Organization: None
  8. Reply-To: chris@chrism.demon.co.uk
  9. X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
  10. Lines: 56
  11. Date: Fri, 8 Jan 1993 19:34:48 +0000
  12. Message-ID: <726521688snz@chrism.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <C0Fyw0.3pq@pcuf.fi> turre@pcuf.fi writes:
  16.  
  17. >I want user not to be able to run many instances of my application. So if
  18. >he tries to run another instance my program should bring the first
  19. >instance to top. I've been trying it with this following code:
  20. >BOOL CMyApp::InitInstance()
  21. >{
  22. >    If( m_hPrevInstance != NULL )
  23. >    {
  24. >        m_pMainWindow->BringWindowToTop();
  25. >        return FALSE;
  26. >    }
  27. >    else
  28. >    {
  29. >        m_pMainWindow = new CMyWindow;
  30. >        m_pMainWindow->ShowWindow( m_nCmdShow );
  31. >        m_pMainWindow->UpdateWindow();
  32. >        return TRUE;
  33. >    }
  34. >}
  35. >The first instance runs fine and no other instances are displayed or created
  36. >but the first windows is not brought to the top.
  37. >
  38.  
  39. No - your code is wrong! This code:
  40.  
  41. >    If( m_hPrevInstance != NULL )
  42. >    {
  43. >        m_pMainWindow->BringWindowToTop();
  44. >        return FALSE;
  45. >    }
  46.  
  47. brings *your* window to the top, not that of the previous instance.
  48. Sorry I don't know MFC or whatever it is you're using here, but what
  49. you want to do is:
  50.  
  51.     if (m_hPrevInstance!=NULL)
  52.     {
  53.         hWnd = FindWindow( "MyAppClassName", NULL );
  54.         BringWindowToTop( hWnd );
  55.         return FALSE;
  56.     }
  57.  
  58. That will do the trick.
  59.  
  60. Chris
  61. -- 
  62. --------------------------------------------------------------------------
  63. | Chris Marriott                           | chris@chrism.demon.co.uk    |
  64. | Warrington, UK                           | BIX: cmarriott              |
  65. | (Still awaiting inspiration              | CIX: cmarriott              |
  66. |  for a witty .sig .... )                 | CompuServe: 100113,1140     |
  67. --------------------------------------------------------------------------
  68.  
  69.