home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / scrnsave.pak / TSCRNSAV.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  4KB  |  180 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //
  4. //   Windows desktop screensaver classes.
  5. //----------------------------------------------------------------------------
  6. #include <owl\owlpch.h>
  7. #include <owl\dialog.h>
  8. #include "tscrnsav.h"
  9.  
  10. DEFINE_RESPONSE_TABLE1(TScrnSavWindow, TFrameWindow)
  11.   EV_WM_MOUSEMOVE,
  12.   EV_WM_LBUTTONDOWN,
  13.   EV_WM_RBUTTONDOWN,
  14.   EV_WM_MBUTTONDOWN,
  15.   EV_WM_ACTIVATE,
  16.   EV_WM_ACTIVATEAPP,
  17.   EV_WM_KEYDOWN,
  18.   EV_WM_SYSKEYDOWN,
  19.   EV_WM_SYSCOMMAND,
  20. END_RESPONSE_TABLE;
  21.  
  22. TScrnSavWindow::TScrnSavWindow(TWindow* parent, const char* title, TModule* module)
  23.   : TFrameWindow(parent, title, 0, FALSE, module)
  24. {
  25.   ShowCursor(FALSE);
  26.   Attr.Style = WS_POPUP;
  27. }
  28.  
  29. TScrnSavWindow::~TScrnSavWindow()
  30. {
  31.   ShowCursor(TRUE);
  32. }
  33.  
  34. void
  35. TScrnSavWindow::GetWindowClass(WNDCLASS& wndClass)
  36. {
  37.   TWindow::GetWindowClass(wndClass);
  38.   wndClass.hIcon = 0;
  39.   wndClass.style |= CS_SAVEBITS;
  40.   wndClass.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
  41. }
  42.  
  43. void
  44. TScrnSavWindow::SetupWindow()
  45. {
  46.   TFrameWindow::SetupWindow();
  47.   GetCursorPos(PrevPt);
  48.   TRect r;
  49.   ::GetWindowRect(GetDesktopWindow(), &r);
  50.   MoveWindow(r, TRUE);
  51. }
  52.  
  53. void
  54. TScrnSavWindow::EvMouseMove(UINT, TPoint& point)
  55. {
  56.   if (point != PrevPt)
  57.     PostMessage(WM_CLOSE);
  58. }
  59.  
  60. void
  61. TScrnSavWindow::EvLButtonDown(UINT, TPoint&)
  62. {
  63.   PostMessage(WM_CLOSE);
  64. }
  65.  
  66. void
  67. TScrnSavWindow::EvRButtonDown(UINT, TPoint&)
  68. {
  69.   PostMessage(WM_CLOSE);
  70. }
  71.  
  72. void
  73. TScrnSavWindow::EvMButtonDown(UINT, TPoint&)
  74. {
  75.   PostMessage(WM_CLOSE);
  76. }
  77.  
  78. void
  79. TScrnSavWindow::EvActivate(UINT active, BOOL, HWND)
  80. {
  81.   if (!active)
  82.     PostMessage(WM_CLOSE);
  83. }
  84.  
  85. #if defined(__WIN32__)
  86.   void TScrnSavWindow::EvActivateApp(BOOL active, HANDLE)
  87. #else
  88.   void TScrnSavWindow::EvActivateApp(BOOL active, HTASK)
  89. #endif
  90. {
  91.   if (!active)
  92.     PostMessage(WM_CLOSE);
  93. }
  94.  
  95. void
  96. TScrnSavWindow::EvKeyDown(UINT, UINT, UINT)
  97. {
  98.   PostMessage(WM_CLOSE);
  99. }
  100.  
  101. void
  102. TScrnSavWindow::EvSysKeyDown(UINT, UINT, UINT)
  103. {
  104.   PostMessage(WM_CLOSE);
  105. }
  106.  
  107. void
  108. TScrnSavWindow::EvSysCommand(UINT cmdType, TPoint&)
  109. {
  110.   if ((cmdType & 0xFFF0) != SC_SCREENSAVE)
  111.     DefaultProcessing();
  112. }
  113.  
  114. int
  115. TScrnSavApp::Run()
  116. {
  117.   if (strcmp(lpCmdLine, "/c") == 0 || strcmp(lpCmdLine, "-c") == 0) {
  118.     Configuring = TRUE;
  119.     InitConfigDialog();
  120.     
  121.     //
  122.     // Get the desktop control panel applet's window handle and make a
  123.     // TWindow out of it.
  124.     //
  125.     HWND deskAppletHWnd = ::FindWindow(WC_DIALOG, "Desktop");
  126.     TWindow* deskAppletWnd = 0;
  127.     if (deskAppletHWnd)
  128.       deskAppletWnd = new TWindow(deskAppletHWnd);
  129.  
  130.     //
  131.     // Set our config dialog to have the applet window as its parent if
  132.     // available
  133.     //
  134.     if (deskAppletWnd)
  135.       ConfigureDialog->SetParent(deskAppletWnd);
  136.     ConfigureDialog->Execute();
  137.     delete ConfigureDialog;
  138.  
  139.     //
  140.     // When our alias is destructed, it remove its thunk, & restores old proc
  141.     //
  142.     delete deskAppletWnd;
  143.     return Status;
  144.  
  145.   } else {
  146.     Configuring = FALSE;
  147.     return TApplication::Run();
  148.   }
  149. }
  150.  
  151. void
  152. TScrnSavApp::InitMainWindow()
  153. {
  154.   Configuring = FALSE;
  155.   InitScrnSavWindow();
  156.   if (ScrnSavWnd)
  157.     MainWindow = ScrnSavWnd;
  158.   LastTime = GetCurrentTime();
  159. }
  160.  
  161. void
  162. TScrnSavApp::InitScrnSavWindow()
  163. {
  164.   ScrnSavWnd = new TScrnSavWindow(0, 0, 0);
  165. }
  166.  
  167. BOOL
  168. TScrnSavApp::IdleAction(long)
  169. {
  170.   if (!Configuring) {
  171.     uint32 diffTime = GetCurrentTime() - LastTime;
  172.     if (Speed == 2 || Speed == 1 && diffTime > 10 || diffTime > 50) {
  173.       ScrnSavWnd->AnimateScreen();
  174.       LastTime = GetCurrentTime();
  175.     }
  176.     return TRUE;
  177.   }
  178.   return FALSE;
  179. }
  180.