home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / SPLASH / SPLASH.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-22  |  7.4 KB  |  299 lines

  1. // splash.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "splash.h"
  6.  
  7. #include "mainfrm.h"
  8. #include "nulldoc.h"
  9. #include "nullview.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CSplashDemoApp
  18.  
  19. BEGIN_MESSAGE_MAP(CSplashDemoApp, CWinApp)
  20.     //{{AFX_MSG_MAP(CSplashDemoApp)
  21.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  22.     ON_COMMAND(ID_HELP_SPLASHME, OnHelpSplashme)
  23.     ON_UPDATE_COMMAND_UI(ID_HELP_SPLASHME, OnUpdateHelpSplashme)
  24.     //}}AFX_MSG_MAP
  25.     // Standard file based document commands
  26.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  27.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  28. END_MESSAGE_MAP()
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CSplashDemoApp construction
  32.  
  33. CSplashDemoApp::CSplashDemoApp()
  34. {
  35.     // TODO: add construction code here,
  36.     // Place all significant initialization in InitInstance
  37.     m_pwndSplash = NULL;
  38. }
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CSplashDemoApp object
  42.  
  43. CSplashDemoApp NEAR theApp;
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CSplashDemoApp initialization
  47.  
  48. BOOL CSplashDemoApp::InitInstance()
  49. {
  50. // Put up the splash window
  51. //if (RunEmbedded() || RunAutomated())            // Do the check here if OLE is used
  52. //{
  53.     ASSERT(NULL == m_pwndSplash);
  54.     m_pwndSplash = new CSplashWnd;
  55.     m_pwndSplash->Create();
  56.     m_pwndSplash->ShowWindow(SW_SHOW);
  57.     m_pwndSplash->UpdateWindow();
  58.     ASSERT(m_pwndSplash != NULL);
  59. //}
  60.     // Standard initialization
  61.     // If you are not using these features and wish to reduce the size
  62.     //  of your final executable, you should remove from the following
  63.     //  the specific initialization routines you do not need.
  64.  
  65.     SetDialogBkColor();        // Set dialog background color to gray
  66.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  67.  
  68.     // Register the application's document templates.  Document templates
  69.     //  serve as the connection between documents, frame windows and views.
  70.  
  71.     CMultiDocTemplate* pDocTemplate;
  72.     pDocTemplate = new CMultiDocTemplate(
  73.         IDR_NULLTYPE,
  74.         RUNTIME_CLASS(CNullDoc),
  75.         RUNTIME_CLASS(CMDIChildWnd),        // standard MDI child frame
  76.         RUNTIME_CLASS(CNullView));
  77.     AddDocTemplate(pDocTemplate);
  78.  
  79.     // create main MDI Frame window
  80.     CMainFrame* pMainFrame = new CMainFrame;
  81.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  82.         return FALSE;
  83.     m_pMainWnd = pMainFrame;
  84.  
  85.     // enable file manager drag/drop and DDE Execute open
  86.     EnableShellOpen();
  87.     RegisterShellFileTypes();
  88.  
  89.     // simple command line parsing
  90.     if (m_lpCmdLine[0] == '\0')
  91.     {
  92.         // create a new (empty) document
  93.         OnFileNew();
  94.     }
  95.     else
  96.     {
  97.         // open an existing document
  98.         OpenDocumentFile(m_lpCmdLine);
  99.     }
  100.  
  101.     m_pMainWnd->DragAcceptFiles();
  102.     // The main window has been initialized, so show and update it.
  103.     pMainFrame->ShowWindow(m_nCmdShow);
  104.     pMainFrame->UpdateWindow();
  105.  
  106.     m_dwSplashTime = ::GetCurrentTime();
  107.  
  108.     return TRUE;
  109. }
  110.  
  111. #define SPLASH_TIME 2500
  112.  
  113. BOOL CSplashDemoApp::OnIdle(LONG lCount)
  114. {
  115.     // call base class idle first
  116.     BOOL bResult = CWinApp::OnIdle(lCount);
  117.  
  118.     // then do our work
  119.     if (m_pwndSplash != NULL)
  120.     {
  121.         if (m_pwndSplash->m_hWnd != NULL)
  122.         {
  123.             if (::GetCurrentTime() - m_dwSplashTime >= SPLASH_TIME)
  124.             {
  125.                 // timeout expired, destroy the splash window
  126.                 m_pwndSplash->DestroyWindow();
  127.                 delete m_pwndSplash;
  128.                 m_pwndSplash = NULL;
  129.                 m_pMainWnd->UpdateWindow();
  130.                 // NOTE: don't set bResult to FALSE,
  131.                 //  CWinApp::OnIdle may have returned TRUE
  132.             }
  133.             else
  134.             {
  135.                 // check again later...
  136.                 bResult = TRUE;
  137.             }
  138.         }
  139.     }
  140.  
  141.     return bResult;
  142. }
  143.  
  144. BOOL CSplashDemoApp::PreTranslateMessage(MSG *pMsg)
  145. {
  146.     if (m_pwndSplash != NULL)
  147.     {
  148.         if (pMsg->message == WM_KEYDOWN ||
  149.             pMsg->message == WM_SYSKEYDOWN ||
  150.             pMsg->message == WM_LBUTTONDOWN ||
  151.             pMsg->message == WM_RBUTTONDOWN ||
  152.             pMsg->message == WM_MBUTTONDOWN ||
  153.             pMsg->message == WM_NCLBUTTONDOWN ||
  154.             pMsg->message == WM_NCRBUTTONDOWN ||
  155.             pMsg->message == WM_NCMBUTTONDOWN)
  156.         {
  157.             if (pMsg->hwnd == m_pwndSplash->m_hWnd) m_dwSplashTime -= SPLASH_TIME;
  158.             else
  159.             {
  160.                 m_pwndSplash->DestroyWindow();
  161.                 delete m_pwndSplash;
  162.                 m_pwndSplash = NULL;
  163.                 m_pMainWnd->UpdateWindow();
  164.             }
  165.         }
  166.     }
  167.      
  168.      return CWinApp::PreTranslateMessage(pMsg);
  169. }
  170.  
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CAboutDlg dialog used for App About
  173.  
  174. class CAboutDlg : public CDialog
  175. {
  176. public:
  177.     CAboutDlg();
  178.  
  179. // Dialog Data
  180.     //{{AFX_DATA(CAboutDlg)
  181.     enum { IDD = IDD_ABOUTBOX };
  182.     //}}AFX_DATA
  183.  
  184. // Implementation
  185. protected:
  186.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  187.     //{{AFX_MSG(CAboutDlg)
  188.         // No message handlers
  189.     //}}AFX_MSG
  190.     DECLARE_MESSAGE_MAP()
  191. };
  192.  
  193. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  194. {
  195.     //{{AFX_DATA_INIT(CAboutDlg)
  196.     //}}AFX_DATA_INIT
  197. }
  198.  
  199. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  200. {
  201.     CDialog::DoDataExchange(pDX);
  202.     //{{AFX_DATA_MAP(CAboutDlg)
  203.     //}}AFX_DATA_MAP
  204. }
  205.  
  206. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  207.     //{{AFX_MSG_MAP(CAboutDlg)
  208.         // No message handlers
  209.     //}}AFX_MSG_MAP
  210. END_MESSAGE_MAP()
  211.  
  212. // App command to run the dialog
  213. void CSplashDemoApp::OnAppAbout()
  214. {
  215.     CAboutDlg aboutDlg;
  216.     aboutDlg.DoModal();
  217. }
  218.  
  219. /////////////////////////////////////////////////////////////////////////////
  220. // CSplashWnd
  221.  
  222. CSplashWnd::CSplashWnd()
  223. {
  224. }
  225.  
  226. CSplashWnd::~CSplashWnd()
  227. {
  228.     m_bmSplash.DeleteObject();
  229. }
  230.  
  231. BOOL CSplashWnd::Create()
  232. {
  233.     m_bmSplash.LoadBitmap(IDB_SPLASHWND);
  234.     
  235.     BITMAP bm;
  236.     m_bmSplash.GetObject(sizeof(BITMAP), &bm);
  237.     
  238.     // Get the size of the splash window
  239.     m_wndWidth = bm.bmWidth;
  240.     m_wndHeight = bm.bmHeight;
  241.  
  242.     // Get the size of the screen
  243.     int screenWidth = GetSystemMetrics(SM_CXSCREEN);
  244.     int screenHeight = GetSystemMetrics(SM_CYSCREEN);
  245.     
  246.     // get top/left coord to center the splash window
  247.     int top = (screenHeight - m_wndHeight)/2;
  248.     int left = (screenWidth - m_wndWidth)/2;
  249.     
  250.     return CWnd::CreateEx(WS_EX_TOPMOST, "AfxWnd", "", WS_POPUP | WS_VISIBLE,
  251.         left, top, m_wndWidth, m_wndHeight, NULL, NULL);
  252. }
  253.  
  254. BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
  255.     //{{AFX_MSG_MAP(CSplashWnd)
  256.     ON_WM_PAINT()
  257.     //}}AFX_MSG_MAP
  258. END_MESSAGE_MAP()
  259.  
  260. /////////////////////////////////////////////////////////////////////////////
  261. // CSplashWnd message handlers
  262.  
  263. void CSplashWnd::OnPaint()
  264. {
  265.     CPaintDC dc(this); // device context for painting
  266.     
  267.     CDC memDC;
  268.     memDC.CreateCompatibleDC(&dc);
  269.  
  270.     CBitmap* pOld = memDC.SelectObject(&m_bmSplash);
  271.     
  272.     if (pOld == NULL)
  273.         return;     // destructors will clean up
  274.  
  275.     dc.BitBlt(0, 0, m_wndWidth, m_wndHeight, &memDC, 0, 0, SRCCOPY);
  276.     memDC.SelectObject(pOld);
  277.  
  278.     // Do not call CWnd::OnPaint() for painting messages
  279. }
  280.  
  281. /////////////////////////////////////////////////////////////////////////////
  282. // CSplashDemoApp commands
  283.  
  284. void CSplashDemoApp::OnHelpSplashme()
  285. {
  286.     ASSERT(NULL == m_pwndSplash);
  287.     m_pwndSplash = new CSplashWnd;
  288.     m_pwndSplash->Create();
  289.     m_pwndSplash->ShowWindow(SW_SHOW);
  290.     m_pwndSplash->UpdateWindow();
  291.     ASSERT(m_pwndSplash != NULL);
  292.     m_dwSplashTime = ::GetCurrentTime();
  293. }
  294.  
  295. void CSplashDemoApp::OnUpdateHelpSplashme(CCmdUI* pCmdUI)
  296. {
  297.     pCmdUI->Enable(NULL == m_pwndSplash);
  298. }
  299.