home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4322 < prev    next >
Encoding:
Text File  |  1992-12-18  |  2.2 KB  |  68 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: Bringing Application Windows to the top 
  5. Distribution: world
  6. References: <1992Dec17.122321.20939@cs.nott.ac.uk>
  7. Organization: None
  8. Reply-To: chris@chrism.demon.co.uk
  9. X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
  10. Lines: 53
  11. Date: Thu, 17 Dec 1992 18:40:56 +0000
  12. Message-ID: <724617656snz@chrism.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <1992Dec17.122321.20939@cs.nott.ac.uk> mak@vulcan.xtel.co.uk writes:
  16.  
  17. >
  18. >Hi,
  19. >I`ve got fairly simple question:
  20. >
  21. >        Given a HWND, how can I bring an Application window to the top?
  22. >
  23. >I want only one instance of my application to run, and like in the
  24. >File Manager I'd like the current instance of my program to come
  25. >to the front when the user selects my program-item from the 
  26. >Program Manager.
  27. >To do this I check for a previous instance on startup, and if there
  28. >is one I use EnumWindows to step through the windows looking for
  29. >the one belonging to the previous instance. This works fine, I
  30. >can set the title of that window. But now I want to bring that 
  31. >application to the top. I tried SetWindowPos(hwnd, HWND_TOPMOST,
  32. >0, 0, 0, 0, WPS_NOSIZE | WPS_NOMOVE), but nothing happens.
  33. >
  34. >Any suggestions greatly appreciated.
  35. >
  36. >-- Martijn
  37. >
  38.  
  39. Using "EnumWindows" isn't necessary.  All you need to do is say:
  40.  
  41.     if (hPrevInstance!=NULL) {
  42.  
  43.         // Find the window handle of the previous instance.
  44.  
  45.         hWnd = FindWindow( "MyClassName", NULL );
  46.         
  47.         // If the window is iconic, restore it.
  48.  
  49.         if (IsIconic(hWnd)) OpenIcon(hWnd);
  50.  
  51.         // Bring the window to the front.
  52.  
  53.         BringWindowToTop( hWnd );
  54.         return 0;
  55.     }
  56.  
  57. This should do the trick.
  58.  
  59. Chris
  60. -- 
  61. --------------------------------------------------------------------------
  62. | Chris Marriott                           | chris@chrism.demon.co.uk    |
  63. | Warrington, UK                           | BIX: cmarriott              |
  64. | (Still awaiting inspiration              | CIX: cmarriott              |
  65. |  for a witty .sig .... )                 | CompuServe: 100113,1140     |
  66. --------------------------------------------------------------------------
  67.  
  68.