home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / programr / vbasic / metalib / metademo.frm (.txt) < prev    next >
Visual Basic Form  |  1992-03-04  |  20KB  |  393 lines

  1. MetaFile
  2. MetaFiles!
  3. Form1,
  4. DrawJet
  5.     Click Me!
  6. Picture1
  7. SaveMeta
  8.     Save Meta
  9. LoadMeta
  10.     Load Meta
  11.     PrintMeta
  12. Print Meta
  13. AboutBox
  14. About...
  15. Command1
  16. Command1_Click^
  17. CreateMetaFile
  18.     rectangle%
  19. CloseMetaFile
  20. PlayMetaFile
  21. Picture1
  22. testmetaW
  23. Form_Click;
  24. printer7
  25. Ellipse
  26. SetMapMode
  27. MM_ANISOTROPIC
  28. SetWindowExt
  29. SetViewPortExt{
  30. scalewidth
  31. ScaleHeight
  32. SetWindowOrg
  33. MM_TWIPS
  34. MM_ISOTROPIC
  35. width
  36. heightW
  37. BeginPaint
  38. lpPaint
  39. PAINTSTRUCT!
  40. pstruct
  41. Rectp
  42. ferase{
  43. rcpaint@
  44. fRestoreE
  45. fincupdate
  46. rgbReserved
  47. Left`
  48. right
  49. botomj
  50. frestorL
  51. MetafilehWnd
  52. Form1
  53. rectang6
  54. GetFocusT
  55. GetClientRectN
  56. lpRect
  57. bottomd
  58.     scalemode
  59. MetaRectangle
  60. gMdc(
  61. MetaEllipse`
  62. Command2_Click9
  63. MetaCircle
  64. Radius
  65. NotUsed
  66. Startt
  67. Finisht
  68. Aspect
  69. Command3_Click
  70. GetDeviceCaps
  71. TEXTCAPS@
  72.     TC_CR_ANY
  73.     CURVECAPS
  74. CC_NONE
  75. CC_CIRCLES
  76. CC_PIE
  77. CC_CHORD)
  78. CC_ELLIPSES
  79. CC_WIDE
  80.     CC_STYLED
  81. CC_WIDESTYLED|
  82. CC_INTERIORSk
  83. MetaFile
  84. LC_POLYLINE
  85. LINECAPSf
  86. MetaArcw
  87. MetaLine
  88. MetaMove
  89. MetaLineFrom
  90. Picture1_Click
  91. Form_Resize
  92. @    Form_Load 
  93. MetaInitializeU
  94. PicBox
  95. picboz
  96. ctlname
  97. Visible
  98. FALSE
  99. SaveMeta_Click0
  100. MetaSaveFile`
  101. MetaFileName
  102. MFFileName
  103. LoadMeta_Clickp
  104. MetaLoadFile
  105. MetaFile_ReSize
  106. Resize
  107. DeleteMetafile
  108. FileNum,
  109.     CreatePen
  110.     nPenStyle
  111. nWidth
  112. crColor
  113. PS_SOLID
  114. SelectObject=
  115. HExtc    
  116. DrawMore_Click
  117. OldPen
  118. RedPenI
  119. BluePen&    
  120. GreenPenZ
  121. BlackPen
  122. FirstOldPen;
  123. DeleteObject|
  124. hMdcq
  125. OriginalPen
  126. PrintMeta_Click
  127. DrawJet_Click
  128. MM_TEXTq
  129. MetaText
  130. LOGFONT
  131. lfHeight
  132. lfWidth    
  133. lfEscapementL
  134. lfOrientation0
  135. lfWeight
  136. lfItalic
  137. lfUnderline?
  138. lfStrikeOut
  139.     lfCharSet^
  140. lfOutPrecision
  141. lfClipPrecision~
  142.     lfQuality
  143. lfPitchAndFamily
  144. lfFaceName
  145. LF_FACESIZE
  146. CreateFontIndirectI
  147.     lpLogFont~    
  148. FontType
  149. OldFont
  150. MetaFill
  151. FloodStyle
  152. FloodColor
  153. FloodHatch7    
  154. BorderColorY
  155. BS_HATCHED
  156. HS_DIAGCROSS
  157.     BrushType
  158. lbStyle#
  159. lbColor
  160. lbHatch
  161.     FloodFill
  162. Brush
  163. CreateBrushIndirect
  164. OldBrush
  165. screen
  166.     scalewith\
  167. mousepointerM
  168. Form_UnloadI    
  169. Cancel
  170. OEM_CHARSET
  171. FW_BOLD
  172. PROOF_QUALITY
  173. VARIABLE_PITCHr    
  174.     FF_MODERN
  175.     FW_NORMAL
  176. FIXED_PITCH
  177. FF_ROMAN
  178. szFaceName
  179. retval
  180. GetTextFace
  181. FF_SWISSc
  182. fontsR
  183. currentyH
  184. currentx
  185. FF_DONTCAREy
  186. FF_DECORATIVEn
  187. WindowState
  188. AboutBox_Click
  189. Credits
  190. MetaRecordStart
  191. MetaRecordStop$
  192. XScale
  193. YScale
  194. fYScale
  195. fXScale
  196. ffYScale+
  197. ffXScale
  198. sizeb
  199. MetaLineStep
  200.     Currently
  201. notice
  202. picture3
  203. correctF
  204. routine
  205.     hardcoded
  206. Picture1_Paint
  207.  The code in this module plays a metafile when picture1 is resized..
  208.  A jet is drawn with a maximum with (including borders) of 1400 and a
  209.  maximum height of 1600.  (These are scaled with the fXScale% and the fYScale%).
  210.  We are still having some problems making certain function operate correctly and
  211.  we have noted these problems in the code with sample code commented out.t
  212.  Currently, you will notice that the picture can't replay itself back to the
  213.  correct size with out the play routine knowing what it's dimensions are..
  214.  They are hardcoded in our demo.
  215.  If you know what our problem is, please let us know.b
  216.  Also, the flood fill routine is buggy.  (ie: UAE!)  This wouldu
  217.  be a great addition, if it worked.  Another bug is when I try to reselect
  218.  the original objects (in the DrawJet event).  UAE!!
  219.  Also, if you intend to draw an ellipse, use the MetaCircle function, not the
  220.  MetaArc function.  The arc won't draw correctly (esp on the PostScript printer) if youu
  221.  have start=0 radians and finish=2*pi radians.
  222. Form_Resize
  223.  This event handler takes care of actually playing the metafile onto the screen.
  224.  Don't do anything if the form is minimized.
  225.  Must have scalemode set to pixels.x
  226.  MapMode is like setting the VB scale properties.  We are generally concerned with
  227.  only two MapModes at this point; either MM_ANISOTROPIC or MM_ISOTROPIC.  For ourr
  228.  purposes, all they do is set how the X axis relates to the Y axis.  If you set it
  229.  to MM_ANISOTROPIC then the Y axis and X axis can be scaled independently.  If you
  230.  set it to MM_ANISOTROPIC then the Y axis will always be dependent on the X axis.a
  231.  In other words, if you double the X dimension, the Y dimension will also double.u
  232.  This is useful if you want to insure that a circle always looks like a circle
  233.  instead of an ellipse, etc.
  234.  Setting the WindowExt is part of the way you tell windows how to scale your drawing.w
  235.  Your drawing should be relative to the window extent you define.  Window extentst
  236.  are in logical units.  We suggest that you make them at least as large as your 
  237.  screen.  We have a 1024x768 screen so we set the Window extent to 1400 x 1600.1
  238.  Notice that we've scaled the window extent with the fXScale% and fYScale% factors
  239.  that we define in the DrawJet routine.  This way you can easily experiment with
  240.  changing the Window Extent while maintaining the correct proportions for ther
  241.  jet drawing. 
  242.  This sets the origin of the window to 0,0.  This is like setting ScaleLeft andt
  243.  ScaleTop.
  244.  Next we wanted to find the ScaleWidth and ScaleHeight of the picture boxe
  245.  so we could make the drawing as large as would fit.  Unfortunately, when we
  246.  used the ScaleWidth and ScaleHeight properties those values seemed to bet
  247.  slightly off from what we needed.  Instead we called the api GetClientRect()e
  248.  for the picture box.  Then next three steps perform this task.e
  249.  The last step before actually playing the metafile is to set the viewport extent.
  250.  By always setting it to the inside dimensions of the picture box, we insure that 
  251.  the jet metafile will always be played as large as the picture box will hold.
  252.  Finally, this next statement causes the jet drawing to be displayed.a
  253. SaveMeta_Click
  254.  This routine saves the metafile to disk in the SDK metafile format.
  255. Enter the file name"
  256. Meta-Save"
  257. LoadMeta_Click
  258.  This routine takes care of loading loading a metafile from disk..
  259. Enter the file name"
  260. Meta-Load"
  261. Load Failed"
  262. Meta-load"
  263. PrintMeta_Click
  264.  This routine takes care of playing the metafile to the printer.  Notice that thee
  265.  steps involved are almost identical to the steps used for playing the metafile to
  266.  the screen.  We simply substituted Printer.hdc for Picture1.hdc..
  267. Must use pixels for GDI calls0
  268. DrawJet_Click
  269.  Define the pens that will be used.  These don't need to beh
  270.  in the metafile itself.  Pens are used for defining color
  271.  line width, etc.i
  272.  These following instructions are not used because we couldn't
  273.  get the floodfill function to work.  Therefore they are commented
  274.  out.t
  275. BrushType.lbStyle = BS_HATCHED
  276. BrushType.lbColor = RGB(10, 20, 30)0
  277. BrushType.lbHatch = HS_DIAGCROSS
  278. Brush% = CreateBrushIndirect(BrushType)
  279. OldBrush% = SelectObject(gMdc%, Brush%)
  280. When a metafile is drawn, its dimensions are dependent on the logical size of the original
  281. drawing, the logical units of the window in which the object will be drawn (theh
  282. Window extent), and the device units of the drawing surface in the window (the
  283. Viewport extent).  When the metafile is played (drawn) to the picture box the original
  284. size of the drawing is measured relative to the window extent.  So, for example, ife
  285. you draw a horizontal line that is 10 units long and the window extent of the picturec
  286. box is 10 units wide, then the line will extend the entire width of the picture box.
  287. Both the length of the line and the window extent of the picture box are in logicalg
  288. units.  If you enlarge or decrease the actual size of the picture box, it is still
  289. 10 units wide and the line will still extend across its entire length.
  290. The third important measurement is the viewport extent.  The size of this measuremente
  291. is in device units (always use Pixels).  If, now, the size of the drawing, the windowi
  292. extent, and the viewport extent are all equal to 10, then we would have a very small
  293. 10 pixel x 10 pixel window containing a horizontal line.  If the viewport is increased,a
  294. (i.e., by enlarging the size of the picture box), then the size of the line will also 
  295. increase proportionally.  If the window extent is increased to 20, then the length oft
  296. the line will appear to shrink to 1/2 the width of the picture box. 
  297. From our experiments, it seems best to set the Window extent to values larger than the
  298. size of the screen (in pixels) and then scale the drawing commands accordingly.  Remembere
  299. that the size of the object you draw will be relative to the Window extent.  This createse
  300. a problem if the Window extent is too small.  If you draw a vertical line when the
  301. horizontal window extent is a small number, such as 10, you are saying in a sense that
  302. the entire window width is only 10 units wide.  If the viewport extent is something like
  303. 100 pixels, then it takes 10 pixels to make up one logical unit.  If a vertical is 1 unit 
  304. wide, it is actually 10 pixels wide.  Thus the line would appear very thick.  If you
  305. always set the window extent to a value larger than the screen dimensions (in pixels) you)
  306. will never have this problem.b
  307. In this routine we do the drawing.  We set the window and viewport extents in then
  308. code for the form_resize event.v
  309. Initialize the process of recording the meta file.  This needs to be done everytimey
  310. before drawing a metafile.
  311.  Draw Wings And Nose of the jet.  Note that all units are in pixels and the origin isi
  312.  at the upperleft of the picture box.  gMdc% is the Device Context for the metafile.
  313.  It was created in the call to MetaRecordStart().  It was meant to be hidden for all ofl
  314.  our drawing commands, but it is still needed for some of the windows api calls that wea
  315.  haven't wrapped yet.  SelectObject is such a api function.  It is used to make thee
  316.  specified object current.  In the following case it is making the BluePen% the currentr
  317.  pen for the metafile.  This is analogous to setting the forecolor property.
  318.  Our first drawing command is the MetaMove command.  It is analogous to the PSet method.
  319.  The MetaLineStep drawing command is analogous to the VB Line method when using theg
  320.  Step qualifier.  In other words, it draws a line from the current location,
  321.  established with the MetaMove command, to the point passed in the parameters.
  322.  These lines will all be drawn in Blue since we selected the BluePen% object above.b
  323.  Draw Tail
  324.  Draw it with the Black pen.
  325.  The MetaLine command is analogous to the VB Line method when not using the Step
  326.  qualifier.  It draws a line from one point to the other.  Note, though that ita
  327.  does not include that ending point as part of the line.  This is different than
  328.  the VB line method.  This is a good area for improvement later.
  329.  Draw Canopy
  330.  Use green to draw the canopy.
  331.  The MetaArc function is analogous to the Circle method when drawing only a part
  332.  of the circle.  We have had some problems with this function on PostScriptc
  333.  printers.  The fifth and sixth parameters specify the start and end of the arce
  334.  in terms of radians.  If we set the start to 0 and the end to 2 * PI, then we get
  335.  a circle on our HP Laser Jet, but nothing on our PostScript.  Therefore, we don't
  336.  recommend using the command for drawing full circles.  Use the MetaCircle command
  337.  instead.t
  338.  Draw Weapons Pylons on the wingsl
  339.  Use the red pen for the pylons.
  340.  The MetaRectangle command is analogous to the Line method with the B parameter.
  341.  Just specify the coordinates of the upper left corner as the first twot
  342.  parameters and the lower right corner as the las two parameters.s
  343.  Draw rotated text on the wing.  We struggled with rotated text for a long time, but
  344.  thanks to a solution uploaded to Compuserve by Ted Young we have it working.  This 
  345.  same technique will work with the standard print method to a picture box.  It seems
  346.  our main problem was in using the CreateFont api function.  When we switched to the
  347.  CreateFontIndirect api instead, it worked.r
  348.  To print text to a metafile you first need to define the font using the api
  349.  LOGFONT structure which we have declared here with the variable FontType.
  350.  It didn't seem that any of the members of this structure were self explanatory.
  351.  We experimented a lot to get what we want.  We got rotation to work only when wee
  352.  had the lfCharSet and lfPitchAndFamily members set exactly as you see them.  It
  353.  would work with different values on the printer, but not on the screen.  The 
  354.  actual rotation is defined with the lfEscapement member.  Set it to a value inu
  355.  tenths of a degree.  In other words 900 (90 * 10) is 90 degrees rotation.
  356. Modern
  357. This is the angle in tenths of a degree)
  358. FontType.lfItalic  As String * 1
  359. FontType.lfUnderline  As String * 1
  360. FontType.lfStrikeOut  As String * 1
  361. FontType.lfOutPrecision As String * 1
  362. FontType.lfClipPrecision As String * 1
  363.  Now that we have defined the font it's time to actually create it.e
  364.  Finally SelectObject makes our newly created font the current font.
  365.  And the MetaText wrapper function actuall writes the text to theo
  366.  metafile.
  367.  Flood Fill the Canopy
  368.  (can't get this to work...)
  369.  This is one area we are still having problems with.  Maybe someone else will 
  370.  have a suggestion.  Following is the code that we couldn't get to work.
  371.  The result was a UAE.
  372. b% = MetaFill(70, 60, RGB(0, 255, 0))
  373. OldPen% = SelectObject(gMdc%, OriginalPen%)
  374. OldBrush% = SelectObject(gMdc%, OldBrush%)
  375.  Finally, we are done with the drawing.  We need to do some housecleaning nowg
  376.  to close the metafile.  This is all taken care of with the MetaRecordStop
  377.  wrapper routine.t
  378.  Delete the pens & fonts to free the resources
  379. If Brush% <> 0 Then b% = DeleteObject(Brush%)%
  380.  So far all that we have done is create a metafile in memory someplace that 
  381.  contains all of our drawing commands.  Nothing has appeared on the screen ore
  382.  the printer so far.  Making the drawing appear on the screen or printer ise
  383.  called "playing the metafile."e
  384.  The code that plays back the metafile is in the resize event.
  385. Form_Unload
  386. AboutBox_Click
  387. Command1_Click
  388. Form_Load
  389. For this demo, we have defined an X and Y scale factor which affects both the size of thee
  390. drawing and the size of the window extents.  By varying these values fXScale% and fYScale%
  391. you can see how it affects the picture.n
  392. Picture1_Paint
  393.