home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bmpkit / bmpkit.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  10.7 KB  |  315 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4020
  5.    ClientLeft      =   1125
  6.    ClientTop       =   2010
  7.    ClientWidth     =   7365
  8.    Height          =   4425
  9.    Left            =   1065
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2.792
  13.    ScaleMode       =   5  'Inch
  14.    ScaleWidth      =   5.115
  15.    Top             =   1665
  16.    Width           =   7485
  17.    Begin CommandButton Command4 
  18.       Caption         =   "Show Original "
  19.       Height          =   375
  20.       Left            =   5640
  21.       TabIndex        =   12
  22.       Top             =   3480
  23.       Width           =   1335
  24.    End
  25.    Begin CommandButton Command5 
  26.       Caption         =   "Hide Original"
  27.       Height          =   375
  28.       Left            =   5640
  29.       TabIndex        =   13
  30.       Top             =   3000
  31.       Width           =   1335
  32.    End
  33.    Begin CommandButton Command3 
  34.       Caption         =   "Print"
  35.       Height          =   375
  36.       Left            =   6480
  37.       TabIndex        =   2
  38.       Top             =   2520
  39.       Width           =   735
  40.    End
  41.    Begin CommandButton Command2 
  42.       Caption         =   "Display"
  43.       Height          =   375
  44.       Left            =   5640
  45.       TabIndex        =   1
  46.       Top             =   2520
  47.       Width           =   735
  48.    End
  49.    Begin HScrollBar HScroll1 
  50.       Height          =   255
  51.       Left            =   5160
  52.       TabIndex        =   6
  53.       Top             =   960
  54.       Width           =   1215
  55.    End
  56.    Begin OptionButton Option2 
  57.       Caption         =   "Size"
  58.       Height          =   255
  59.       Left            =   5160
  60.       TabIndex        =   9
  61.       Top             =   600
  62.       Width           =   855
  63.    End
  64.    Begin PictureBox Picture2 
  65.       AutoRedraw      =   -1  'True
  66.       Height          =   1335
  67.       Left            =   840
  68.       ScaleHeight     =   0.906
  69.       ScaleMode       =   5  'Inch
  70.       ScaleWidth      =   0.906
  71.       TabIndex        =   4
  72.       Top             =   600
  73.       Width           =   1335
  74.    End
  75.    Begin OptionButton Option1 
  76.       Caption         =   "Move"
  77.       Height          =   255
  78.       Left            =   5160
  79.       TabIndex        =   8
  80.       Top             =   240
  81.       Width           =   855
  82.    End
  83.    Begin VScrollBar VScroll1 
  84.       Height          =   1095
  85.       Left            =   6480
  86.       TabIndex        =   7
  87.       Top             =   120
  88.       Width           =   255
  89.    End
  90.    Begin CommandButton Command1 
  91.       Caption         =   "Exit"
  92.       Height          =   375
  93.       Left            =   4080
  94.       TabIndex        =   0
  95.       Top             =   120
  96.       Width           =   735
  97.    End
  98.    Begin PictureBox Picture1 
  99.       AutoSize        =   -1  'True
  100.       Height          =   495
  101.       Left            =   120
  102.       ScaleHeight     =   0.323
  103.       ScaleMode       =   5  'Inch
  104.       ScaleWidth      =   0.323
  105.       TabIndex        =   3
  106.       Top             =   120
  107.       Width           =   495
  108.    End
  109.    Begin Label Label3 
  110.       AutoSize        =   -1  'True
  111.       Height          =   195
  112.       Left            =   5160
  113.       TabIndex        =   11
  114.       Top             =   2160
  115.       Width           =   75
  116.    End
  117.    Begin Label Label2 
  118.       AutoSize        =   -1  'True
  119.       Height          =   195
  120.       Left            =   5160
  121.       TabIndex        =   10
  122.       Top             =   1800
  123.       Width           =   75
  124.    End
  125.    Begin Label Label1 
  126.       Alignment       =   2  'Center
  127.       Caption         =   "Scaled Image"
  128.       Height          =   255
  129.       Left            =   840
  130.       TabIndex        =   5
  131.       Top             =   120
  132.       Width           =   1335
  133.    End
  134. Sub Command1_Click ()
  135. End Sub
  136. Sub command2_click ()
  137. 'Make sure we have valid scaling values
  138. If scalex = 0 Then scalex = 1
  139. If scaley = 0 Then scaley = 1
  140. 'Set picture2.width to match picture1, with scaling.
  141. 'The 3.14 divisor matches inch dimension with the
  142. '640X480 screen dimensions. Change for other display
  143. 'adapters.
  144. Picture2.width = (picture1.width / 3.14) * scalex
  145. Picture2.height = (picture1.height / 3.14) * scaley
  146. '*Set constants for GDI calls
  147. Const NULL = 0&
  148. Const SRCCOPY = &HCC0020
  149. Const NEWFRAME = 1
  150. Const pixel = 3
  151. '*Display scaled version in Picture2
  152. '*StretchBlt requires pixel coordinates.
  153. picture1.scalemode = 3
  154. Picture2.scalemode = 3
  155. 'Set Dimensions for Picture2
  156. Picture2.scalewidth = picture1.scalewidth / 3.14 * scalex
  157. Picture2.scaleheight = picture1.scaleheight / 3.14 * scaley
  158. '*Do not change the order of these statements.
  159. hMemoryDC% = CreateCompatibleDC(picture1.hDC)
  160. hOldBitMap% = SelectObject(hMemoryDC%, picture1.Picture)
  161. 'Variables for the StretchBlt function:
  162. '1. Source of image HMemeoryDC% -- set above from original picture
  163. '2,3. Positioning on output object. Must be integer, in pixels.
  164. '4,5. Width, height of output image. Here we use the values set above.
  165. '6, Source of image...in this case the memory image set by CreateCompatibleDC% function
  166. '7,8. Don't know. Set to 0 works just fine! Experiment and let me know.
  167. '9,10. X/Y coordinates for how much of original to put in new object. You can use
  168. 'these values for cropping, if you like.
  169. '11. SRCCOPY, as set in constants above. Change at own risk.
  170. ApiError% = StretchBlt(Picture2.hDC, Int(Picture2.left), Int(Picture2.top), Picture2.scalewidth, Picture2.scaleheight, hMemoryDC%, 0, 0, picture1.scalewidth, picture1.scaleheight, SRCCOPY)
  171. hOldBitMap% = SelectObject(hMemoryDC%, hOldBitMap%)
  172. ApiError% = DeleteDC(hMemoryDC%)
  173. Picture2.Refresh
  174. '*Reset scalemodes to previous inch values
  175. picture1.scalemode = 5
  176. Picture2.scalemode = 5
  177. End Sub
  178. Sub Command3_Click ()
  179. '* Print all items other than the image first.
  180. printer.scalemode = 5
  181. printer.currentx = 3
  182. printer.currenty = 3
  183. printer.Print "Hello"
  184. printer.currenty = 4
  185. printer.currentx = 1
  186. printer.drawwidth = 5
  187. printer.Line -Step(printer.currentx + 2, 0)
  188. '*After printing all other elements include your BMP
  189. 'printing routine, as below.
  190. '* Print Scaled Image
  191. '*Make certain we have valid scaling values
  192. If scalex = 0 Then scalex = 1
  193. If scaley = 0 Then scaley = 1
  194. '*Set GDI Constants
  195. Const NULL = 0&
  196. Const SRCCOPY = &HCC0020
  197. Const NEWFRAME = 1
  198. Const pixel = 3
  199. '* StretchBlt requires pixel coordinates.
  200. picture1.scalemode = pixel
  201. printer.scalemode = pixel
  202. '*First two variables are the x,y coordinates (in Pixels)
  203. 'for the placement of images on the printed page. Since the
  204. 'form's ScaleMode is 5 for inches, multiply by 300 to
  205. 'match the the current inch positions of Picture2 on
  206. 'the 300 DPI device.
  207. '*Second pair of variables set the height and width of the
  208. 'graphic to match the pixel size of the original picture
  209. 'in the invisible Picture1 box.
  210. printgraphicx% = Picture2.left * 300
  211. printgraphicy% = Picture2.top * 300
  212. printer.scalewidth = picture1.scalewidth * scalex
  213. printer.scaleheight = picture1.scaleheight * scaley
  214. '*Do not change the order of these statements.
  215. hMemoryDC% = CreateCompatibleDC(picture1.hDC)
  216. hOldBitMap% = SelectObject(hMemoryDC%, picture1.Picture)
  217. 'Variables for the StretchBlt function:
  218. '1. Source of image HMemeoryDC% -- set above from original picture
  219. '2,3. Positioning on output object. Must be integer, in pixels.
  220. '4,5. Width, height of output image. Here we use the values set above.
  221. '6, Source of image...in this case the memory image set by CreateCompatibleDC% function
  222. '7,8. Don't know. Set to 0 works just fine! Experiment and let me know.
  223. '9,10. X/Y coordinates for how much of original to put in new object. You can use
  224. 'these values for cropping, if you like.
  225. '11. SRCCOPY, as set in constants above. Change at own risk.
  226. ApiError% = StretchBlt(printer.hDC, printgraphicx%, printgraphicy%, printer.scalewidth, printer.scaleheight, hMemoryDC%, 0, 0, picture1.scalewidth, picture1.scaleheight, SRCCOPY)
  227. hOldBitMap% = SelectObject(hMemoryDC%, hOldBitMap%)
  228. ApiError% = DeleteDC(hMemoryDC%)
  229. '*Send image and text to printer
  230. printer.NewPage
  231. printer.EndDoc
  232. End Sub
  233. Sub Command4_Click ()
  234. picture1.visible = -1
  235. command2_click
  236. End Sub
  237. Sub Command5_Click ()
  238. picture1.visible = 0
  239. End Sub
  240. Sub Form_Load ()
  241. '*set form and picture ScaleModes
  242. picture1.scalemode = 5
  243. Picture2.scalemode = 5
  244. form1.scalemode = 5
  245. 'set the Move option
  246. option1.value = -1
  247. 'set initial picture width
  248. Picture2.width = 1
  249. Picture2.height = 1
  250. '*Setup scroll bar values
  251. hscroll1.min = -400
  252. hscroll1.max = 400
  253. hscroll1.smallchange = 1
  254. hscroll1.largechange = 10
  255. '*Set Horizontal Scrollbar to center
  256. hscroll1.value = 0
  257. vscroll1.min = -400
  258. vscroll1.max = 400
  259. vscroll1.smallchange = 1
  260. vscroll1.largechange = 10
  261. '*Set Vertical Scrollbar to center
  262. vscroll1.value = 0
  263. '*Make Picture1 box invisible...This picture box, which
  264. 'holds the basic image, does not have to show.  Note that
  265. 'we'll use the printer resolution of this box for sizing.
  266. 'For example, a 300X300 pixel image will print as 1X1 inch
  267. 'on a laser printer.
  268. picture1.visible = 0
  269. '*Load bitmap into Picture1 ... put PAPER.BMP, a Windows
  270. 'background image in the VB directory, or in the default
  271. 'directory, or change the filespec to match it's location.
  272. 'Choose your own, or let user load.
  273. picture1.Picture = LoadPicture("RIBBONS.BMP")
  274. '*Set scaling factors to 1 for full-size image.
  275. 'To reduce or enlarge the original when first displayed,
  276. 'change these figures.
  277. scalex = 1
  278. scaley = 1
  279. '*Display Picture in Picture2
  280. command2_click
  281. End Sub
  282. Sub HScroll1_Change ()
  283. '*If the Move option is selected (default) then add the positive or
  284. 'negative Value of Hscroll1 to the top left of the picture,
  285. 'redraw. Notice that the multiplier is .01 to deal with the
  286. 'inch settings. Scroll Values must be integers., so we can
  287. 'move in .01 inch increments.
  288. If option1.value = -1 Then
  289.     Picture2.left = Picture2.left + (hscroll1.value * .01)
  290.     command2_click
  291.     hscroll1.value = 0
  292.     End If
  293. 'If the Size option is selected, then add the positive or
  294. 'negative Value of Hscroll1 to the scalex variable, then
  295. 'redraw. Notice that the multiplier is .01 to deal with the
  296. 'inch settings. Scroll Values must be integers., so we can
  297. 'move in .01 inch increments.
  298. If option2.value = -1 Then
  299.     scalex = 1 + (hscroll1.value * .01)
  300.     command2_click
  301.     End If
  302. End Sub
  303. Sub VScroll1_Change ()
  304. '*See Hscroll1_Change for explanations.
  305. If option1.value = -1 Then
  306.     Picture2.top = Picture2.top + (vscroll1.value * .01)
  307.     command2_click
  308.     vscroll1.value = 0
  309.     End If
  310. If option2.value = -1 Then
  311.     scaley = 1 + (vscroll1.value * .01)
  312.     command2_click
  313.     End If
  314. End Sub
  315.