summaryrefslogtreecommitdiff
path: root/ipl/gprocs/winsnap.icn
blob: b7ef5fe5105f3463e21a1522970ae42b051c102c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
############################################################################
#
#	File:     winsnap.icn
#
#	Subject:  Procedure to take snapshot of a portion of a window
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This procedure writes an image file for a specified portion of a
#  window.  The name for the file is requested from the user via a
#  dialog box.  If there already is a file by the specified name, the
#  user is given the option of overwriting it or selecting another
#  name.  The procedure fails if the user cancels.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links:  graphics
#
############################################################################

link graphics

procedure winsnap(win, x, y, w, h)
   local name, f

   if type(win) ~== "window" then {
      win :=: x :=: y :=: w :=: h
      win := \&window | runerr(140, &window)
      }

   repeat {
      if OpenDialog("Image file name") == "Okay" then {
         name := dialog_value
         if f := open(name) then {
            close(f)
            if Dialog("Overwrite existing file?", , , ,
               ["Okay", "Cancel"]) == "Cancel" then next
            }
         WriteImage(win, name, x, y, w, h) | {
            Notice("Cannot write image")
            fail
            }
         return
         }
      else fail
      }
      
   return

end