home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / CTRLBARS / CTRLBARS.CP_ / CTRLBARS.CP
Encoding:
Text File  |  1993-02-08  |  3.1 KB  |  106 lines

  1. // ctrlbars.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include <afxpriv.h>    // for idle-update windows message
  15.  
  16. #include "ctrlbars.h"
  17. #include "mainfrm.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CCtrlbarsApp
  26.  
  27. BEGIN_MESSAGE_MAP(CCtrlbarsApp, CWinApp)
  28.     //{{AFX_MSG_MAP(CCtrlbarsApp)
  29.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  30.     //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CCtrlbarsApp construction
  35.  
  36. CCtrlbarsApp::CCtrlbarsApp()
  37. {
  38.     // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only CCtrlbarsApp object
  43.  
  44. CCtrlbarsApp NEAR theApp;
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CCtrlbarsApp initialization
  48.  
  49. BOOL CCtrlbarsApp::InitInstance()
  50. {
  51.     // Standard initialization
  52.     SetDialogBkColor();        // set dialog background color to gray
  53.  
  54.     // create a new SDI main frame window
  55.     CFrameWnd* pMainFrame = new CMainFrame;
  56.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  57.         return FALSE;
  58.     pMainFrame->ShowWindow(m_nCmdShow);
  59.     pMainFrame->UpdateWindow();
  60.     m_pMainWnd = pMainFrame;
  61.  
  62.     pMainFrame->SendMessage(WM_COMMAND, IDM_VIEWPALETTE, (LPARAM)0);
  63.     return TRUE;
  64. }
  65.  
  66.  
  67. // In this override of OnIdle we are doing UI for our app.
  68. // Since this needs to be as fast as possible to give the user
  69. // the best result we do our updates first when lCount is zero
  70. // then we call the library to do its work.
  71. BOOL CCtrlbarsApp::OnIdle(LONG lCount)
  72. {
  73.     if (lCount == 0)
  74.     {
  75.         ASSERT(m_pMainWnd != NULL);
  76.  
  77.         // look for any top-level windows owned by us
  78.         // we use 'HWND's to avoid generation of too many temporary CWnds
  79.         for (HWND hWnd = ::GetWindow(m_pMainWnd->m_hWnd, GW_HWNDFIRST);
  80.                 hWnd != NULL; hWnd = ::GetNextWindow(hWnd, GW_HWNDNEXT))
  81.         {
  82.             if (::GetParent(hWnd) == m_pMainWnd->m_hWnd)
  83.             {
  84.                 // if owned window is active, move the activation to the
  85.                 //   application window
  86.                 if (GetActiveWindow() == hWnd && (::GetCapture() == NULL))
  87.                     m_pMainWnd->SetActiveWindow();
  88.  
  89.                 // also update the buttons for the top-level window
  90.                 SendMessage(hWnd, WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0L);
  91.             }
  92.         }
  93.     }
  94.     return CWinApp::OnIdle(lCount);
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CCtrlbarsApp commands
  99.  
  100. void CCtrlbarsApp::OnAppAbout()
  101. {
  102.     CDialog(IDD_ABOUTBOX).DoModal();
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106.