home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / dlgcbr.zip / DLGCBAR.CPP < prev    next >
C/C++ Source or Header  |  1994-07-05  |  4KB  |  128 lines

  1. /*****************************************************************************
  2.   DLGCBAR.CPP
  3.  
  4.   Purpose:   
  5.       Implementation of CTheApp.
  6.  
  7.   Functions:
  8.       CTheApp::CTheApp()          -- constructor
  9.       CTheApp::~CTheApp()         -- destructor
  10.       CTheApp::FirstInstance()    -- locate first instance of app
  11.       CTheApp::InitInstance()     -- initialize app-instance
  12.       CTheApp::OnHelpAbout()        -- display About box
  13.  
  14.   Development Team:           
  15.       Mary Kirtland
  16.  
  17.   Written by Microsoft Product Support Services, Premier ISV Support
  18.   Copyright (c) 1994 Microsoft Corporation. All rights reserved.
  19. \****************************************************************************/
  20.                               
  21. #include "stdafx.h"
  22. #include "resource.h"
  23. #include "dlgcbar.h" 
  24. #include "aboutdlg.h"
  25. #include "wndlist.h"
  26.  
  27. #ifdef _DEBUG
  28.     #undef THIS_FILE
  29.     static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.         
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CTheApp 
  34.  
  35. CTheApp NEAR theApp;  
  36.  
  37. BEGIN_MESSAGE_MAP(CTheApp, CWinApp)
  38.     //{{AFX_MSG_MAP(CTheApp)
  39.     ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
  40.     //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CTheApp Constructors/Destructors
  45.  
  46. CTheApp::CTheApp()
  47. {
  48. }
  49.  
  50. CTheApp::~CTheApp()
  51. {
  52. }   
  53.   
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CTheApp::FirstInstance
  56. //        FirstInstance checks for an existing instance of the application. 
  57. //        If one is found, it is activated.
  58. //
  59. //      This function uses a technique similar to that described in KB 
  60. //      article Q109175    to locate the previous instance of the application.  
  61. //      However, instead of searching for a matching class name, it searches 
  62. //      for a matching caption.  This allows us to use the normal dialog
  63. //      class for our main window.  It assumes that the AFX_IDS_APP_TITLE 
  64. //      string resource matches the caption specified in the dialog template.
  65.  
  66. BOOL CTheApp::FirstInstance()
  67. {                                       
  68.     CString strCaption;
  69.     strCaption.LoadString(AFX_IDS_APP_TITLE);
  70.  
  71.     CWnd* pwndFirst = CWnd::FindWindow((LPCSTR)(DWORD)WC_DIALOG, 
  72.                                        strCaption);
  73.     if (pwndFirst)
  74.     {
  75.         // another instance is already running - activate it
  76.         CWnd* pwndPopup = pwndFirst->GetLastActivePopup();                                   
  77.         pwndFirst->BringWindowToTop();
  78.         if (pwndFirst->IsIconic())
  79.             pwndFirst->ShowWindow(SW_SHOWNORMAL);
  80.         if (pwndFirst != pwndPopup)
  81.             pwndPopup->BringWindowToTop(); 
  82.         return FALSE;            
  83.     }
  84.     else
  85.     {   
  86.         // this is the first instance  
  87.         return TRUE;
  88.     }
  89. }    
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CTheApp::InitInstance
  93. //        InitInstance performs per-instance initialization of the DLGCBAR 
  94. //        application.  If an instance of the application is already running,
  95. //        it activates that instance.  Otherwise, it creates the modeless 
  96. //        dialog which serves as the application's interface.
  97.  
  98. BOOL CTheApp::InitInstance()
  99. {
  100.     if (!FirstInstance())
  101.         return FALSE;
  102.     
  103.     // Create main window
  104.     TRY
  105.     {           
  106.         CWndListDlg* pMainWnd = new CWndListDlg;
  107.         m_pMainWnd = pMainWnd;
  108.         return pMainWnd->Create();
  109.     }
  110.     CATCH_ALL(e)
  111.     {
  112.         TRACE0("Failed to create main dialog\n");
  113.         return FALSE;
  114.     }
  115.     END_CATCH_ALL    
  116.     
  117. }
  118.        
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CTheApp::OnHelpAbout
  121. //        OnHelpAbout displays the application's about box.
  122.  
  123. void CTheApp::OnHelpAbout() 
  124. {
  125.     CAboutDlg dlg(m_pMainWnd);
  126.     dlg.DoModal();
  127. }
  128.