home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / gotch175.zip / src / snapshot.cpp < prev    next >
Text File  |  2002-05-11  |  8KB  |  210 lines

  1. /***
  2.  This file belongs to the Gotcha! distribution.
  3.  Copyright (C) 1998-2002 Thorsten Thielen <thth@gmx.net>
  4.  
  5.  This program is free software; you can redistribute it and/or modify
  6.  it under the terms of the GNU General Public License as published by
  7.  the Free Software Foundation; either version 2 of the License, or
  8.  (at your option) any later version.
  9.  
  10.  This program is distributed in the hope that it will be useful,
  11.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  GNU General Public License for more details.
  14.  
  15.  You should have received a copy of the GNU General Public License
  16.  along with this program; if not, write to the Free Software
  17.  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  ***/
  19.  
  20. // ** CreateSnapshotWindow ************************************************ /*FOLD00*/
  21.  
  22. HWND CreateSnapshotWindow (VOID)
  23. {
  24.     ULONG fl = FCF_SIZEBORDER | FCF_NOBYTEALIGN;
  25.     HWND  hwndClient;
  26.  
  27.     // create frame window
  28.     // create the window
  29.     HWND hwndSnapshot =
  30.         WinCreateStdWindow (HWND_DESKTOP, 0L, &fl,
  31.                             "thth.wc.gotcha.snapshot", PSZ (NULL), 0L, 0, 1, &hwndClient);
  32.     OldFrameWP = WinSubclassWindow (hwndSnapshot, FrameProcedure);
  33. //    DisplayError ("DEBUG", "0x%08lx", WinGetLastError (GETHAB));
  34.  
  35.     // create window
  36.     /*    hwndSnapshot =
  37.      WinCreateWindow (HWND_DESKTOP, "thth.wc.gotcha.snapshot", "",
  38.      WS_VISIBLE,
  39.      0,0,0,0, HWND_DESKTOP, HWND_TOP, 1L, NULL, 0L); */
  40.     // create the button
  41.     HWND hwndButton =
  42.         WinCreateWindow (hwndClient, WC_BUTTON, RSTR( IDS_SNAPLABEL ),
  43.                          WS_VISIBLE | BS_PUSHBUTTON | BS_NOBORDER |
  44.                          BS_NOPOINTERFOCUS,
  45.                          0,0, 1,1,  hwndClient, HWND_TOP,
  46.                          WID_PB_SNAPSHOT, NULL, NULL);
  47.     wpOldButton = WinSubclassWindow (hwndButton, wpNewButton);
  48.  
  49.     // get the popup menu
  50.     g_hwndMenuSSW = WinLoadMenu(HWND_DESKTOP, GETMODULE, IDM_SSWPOPUP);
  51.  
  52.     WinSetWindowPos (hwndSnapshot, NULLHANDLE, 50,50, 48,32,
  53.                      SWP_MOVE | SWP_SIZE | SWP_SHOW);
  54. //    DisplayError ("DEBUG", "0x%08lx", WinGetLastError (GETHAB));
  55.  
  56.     return hwndSnapshot;
  57. }
  58.  
  59. // ** wpNewButton ********************************************************* /*fold00*/
  60.  
  61. MRESULT EXPENTRY wpNewButton (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  62. {
  63.     switch (msg)
  64.     {
  65.     case WM_BEGINDRAG:
  66.         WinSendMsg (WinQueryWindow (hwnd, QW_OWNER), WM_BEGINDRAG, 0,0);
  67.         break;
  68.  
  69.     case WM_CONTEXTMENU:
  70.         WinSendMsg (WinQueryWindow (hwnd, QW_OWNER), WM_CONTEXTMENU, 0,0);
  71.         break;
  72.     }
  73.  
  74.     return wpOldButton (hwnd, msg, mp1, mp2);
  75. }
  76.  
  77. // ** wpSnapshot ********************************************************** /*FOLD00*/
  78.  
  79. MRESULT EXPENTRY wpSnapshot (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  80. {
  81.     static ULONG    ulTimer;
  82.     static BOOL     fInCapture = FALSE;
  83.  
  84.     switch (msg)
  85.     {
  86.     case WM_CREATE:
  87.         ulTimer = WinStartTimer (hab, hwnd, 2, 1990);
  88.         return MRESULT (FALSE);
  89.  
  90.     case WM_DESTROY:
  91.         WinStopTimer (hab, hwnd, ulTimer);
  92.         return MRESULT (FALSE);
  93.  
  94.     case WM_TIMER:
  95.         if (pset->SSWAlwaysOnTop ())
  96.             WinSetWindowPos (hwndSnapshot, HWND_TOP, 0,0,0,0, SWP_ZORDER);
  97.         return MRESULT (FALSE);
  98.  
  99.     case WM_MOUSEMOVE:
  100.         // we don't want to reset the mouse pointer so capture this msg
  101.         return MRESULT (FALSE);
  102.  
  103.     case WM_COMMAND:
  104.         switch (SHORT1FROMMP (mp1))
  105.         {
  106.         case WID_PB_SNAPSHOT:
  107.             if (fInCapture)
  108.                 WinSendMsg (hwndFrame, UM_ABORT, 0,0);
  109.             else
  110.             {
  111.                 USHORT us;
  112.                 switch (pset->QuerySSWCaptureType ())
  113.                 {
  114.                 case CAP_WINDOWINT: us = WID_PB_WINDOWINTERIOR; break;
  115.                 case CAP_WINDOW: us = WID_PB_WINDOW; break;
  116.                 case CAP_SCREENREGION: us = WID_PB_SCREENREGION; break;
  117.                 default: us = WID_PB_SCREEN; break;
  118.                 }
  119.                 WinSendMsg (WinWindowFromID (hwndFrame, FID_CLIENT),
  120.                             WM_COMMAND, MPFROMSHORT (us), 0L);
  121.             }
  122.             break;
  123.  
  124.         case WID_SSWSCREEN:
  125.             pset->SetSSWCaptureType (CAP_SCREEN); break;
  126.         case WID_SSWSCREENREGION:
  127.             pset->SetSSWCaptureType (CAP_SCREENREGION); break;
  128.         case WID_SSWWINDOW:
  129.             pset->SetSSWCaptureType (CAP_WINDOW); break;
  130.         case WID_SSWWINDOWINT:
  131.             pset->SetSSWCaptureType (CAP_WINDOWINT); break;
  132.  
  133.         case WID_CB_SSWHIDE:
  134.             pset->SSWHide(!pset->SSWHide()); break;
  135.         case WID_CB_SSWALWAYSONTOP:
  136.             pset->SSWAlwaysOnTop(!pset->SSWAlwaysOnTop()); break;
  137.         // the name is a little bit misleading ...
  138.         case WID_CB_SSWENABLE:
  139.             pset->SnapshotWindow(FALSE);
  140.             WinShowWindow (hwndSnapshot, FALSE);
  141.             break;
  142.         }
  143.         return MRESULT (FALSE);
  144.  
  145.     case UM_STARTCAPTURE:
  146.         fInCapture = TRUE;
  147.         return MRESULT (FALSE);
  148.  
  149.     case UM_STOPCAPTURE:
  150.         fInCapture = FALSE;
  151.         WinSetWindowText (WinWindowFromID (hwnd, WID_PB_SNAPSHOT), RSTR( IDS_SNAPLABEL ) );
  152.         return MRESULT (FALSE);
  153.  
  154.     case UM_WINDOWHIDDEN:
  155.         WinSendMsg (WinWindowFromID (hwndFrame, FID_CLIENT), UM_SSWHIDDEN,
  156.                     0,0);
  157.         return MRESULT (FALSE);
  158.  
  159.     case WM_SIZE:
  160.         WinSetWindowPos (WinWindowFromID (hwnd, WID_PB_SNAPSHOT), 0L, 0,0,
  161.                          SHORT1FROMMP (mp2), SHORT2FROMMP (mp2),
  162.                          SWP_SIZE);
  163.         break;
  164.  
  165.     case WM_BEGINDRAG:
  166.         Drag (hwndSnapshot);
  167.         return MRESULT (FALSE);
  168.  
  169.     case UM_COUNTDOWN:
  170.         {
  171.             CHAR    ach[11];
  172.             sprintf (ach, "%lu", ULONG (mp1));
  173.             WinSetWindowText (WinWindowFromID (hwnd, WID_PB_SNAPSHOT), ach);
  174.         }
  175.         return MRESULT (FALSE);
  176.  
  177.     case WM_CONTEXTMENU:
  178.         WinCheckMenuItem(g_hwndMenuSSW, WID_CB_SSWHIDE,
  179.                          pset->QueryFlag(SEI_SSWHIDE));
  180.         WinCheckMenuItem(g_hwndMenuSSW, WID_CB_SSWALWAYSONTOP,
  181.                          pset->QueryFlag(SEI_SSWALWAYSONTOP));
  182.  
  183.         WinCheckMenuItem(g_hwndMenuSSW, WID_SSWWINDOWINT, FALSE); 
  184.         WinCheckMenuItem(g_hwndMenuSSW, WID_SSWSCREENREGION, FALSE); 
  185.         WinCheckMenuItem(g_hwndMenuSSW, WID_SSWWINDOW, FALSE); 
  186.         WinCheckMenuItem(g_hwndMenuSSW, WID_SSWSCREEN, FALSE); 
  187.  
  188.         switch (pset->QuerySSWCaptureType ())
  189.         {
  190.         case CAP_WINDOWINT:
  191.             WinCheckMenuItem(g_hwndMenuSSW, WID_SSWWINDOWINT, TRUE); break;
  192.         case CAP_SCREENREGION:
  193.             WinCheckMenuItem(g_hwndMenuSSW, WID_SSWSCREENREGION, TRUE); break;
  194.         case CAP_WINDOW:
  195.             WinCheckMenuItem(g_hwndMenuSSW, WID_SSWWINDOW, TRUE); break;
  196.         default:
  197.             WinCheckMenuItem(g_hwndMenuSSW, WID_SSWSCREEN, TRUE); break;
  198.         }
  199.  
  200.         WinPopupMenu(hwnd, hwnd, g_hwndMenuSSW, 10,10, WID_CB_SSWHIDE,
  201.                      PU_HCONSTRAIN | PU_VCONSTRAIN | PU_POSITIONONITEM |
  202.                      PU_KEYBOARD | PU_MOUSEBUTTON1);
  203.         return MRESULT (FALSE);
  204.     }
  205.  
  206.     return WinDefWindowProc (hwnd, msg, mp1, mp2);
  207. }
  208.  
  209. // ************************************************************************
  210.