home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / PRINTHEL.PRG < prev    next >
Text File  |  1996-06-27  |  4KB  |  150 lines

  1. /////////////////////////
  2. //
  3. //    printhel(lo).prg - print "Hello World!" on the default printer
  4. //
  5. //    Written by:    John M. Skelton, Jun-96.
  6. //
  7. //    Copyright (C) 1993-1996 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
  8. //    All Rights Reserved.
  9. //
  10. /////////////////////////
  11.  
  12. #include "windows.ch"
  13. #include "font.ch"
  14. #include "commdlg.ch"
  15. #include "textmetr.ch"
  16. #define    NO_C4WCLASS
  17. #include "commands.ch"
  18.  
  19.  
  20. function main()
  21. local    oApp, oWnd
  22.  
  23. CREATE APPLICATION oApp                            ;
  24.     WINDOW oWnd                                ;
  25.     TITLE "Clip-4-Win Makes Windows Apps E-A-S-Y!"            ;
  26.     ON INIT DoInit(oWnd)
  27.  
  28. return nil
  29.  
  30.  
  31. static function DoInit(oWnd)
  32. MenuSetup(oWnd)
  33. return nil
  34.  
  35.  
  36. static function DoHello(oWnd)
  37. local    hDC
  38.  
  39. if !empty(hDC := GetPrintDC())        // see also: PrintDlg()
  40.     StartDoc(hDC, "SomeDocument")
  41.  
  42.     StartPage(hDC)
  43.     TextOut(hDC, 50, 50, "Clip-4-Win says: Hello World!")
  44.     EndPage(hDC)
  45.  
  46.     EndDoc(hDC)
  47.     DeleteDC(hDC)
  48. endif
  49. return nil
  50.  
  51.  
  52. static function DoArial(oWnd)
  53. local    hDC, hFont, hOldFont
  54.  
  55. if !empty(hDC := GetPrintDC())        // see also: PrintDlg()
  56.  
  57.     CREATE FONT  HANDLE hFont  NAME "Arial"  SIZE 10  DC hDC
  58.     StartDoc(hDC, "SomeDocument")
  59.  
  60.     StartPage(hDC)
  61.     TextOut(hDC, 50, 50, "Clip-4-Win says: Hello World!")
  62.     hOldFont = SelectObject(hDC, hFont)
  63.     TextOut(hDC, 50, 150, "In Arial 10: Hello World!")
  64.     SelectObject(hDC, hOldFont)
  65.     EndPage(hDC)
  66.  
  67.     EndDoc(hDC)
  68.     DeleteObject(hFont)
  69.     DeleteDC(hDC)
  70. endif
  71. return nil
  72.  
  73.  
  74. static function DoFont(oWnd)
  75. local    hDC, aFont[14], nTenthsPoint, nPtSize, hFont, hOldFont
  76.  
  77. if !empty(hDC := GetPrintDC())        // see also: PrintDlg()
  78.     if ChooseFont(aFont, @nTenthsPoint) != nil
  79.         nPtSize = nTenthsPoint / 10
  80.         CREATE FONT  HANDLE hFont  NAME aFont[LF_FaceName]  SIZE nPtSize  DC hDC
  81.         StartDoc(hDC, "SomeDocument")
  82.  
  83.         StartPage(hDC)
  84.         TextOut(hDC, 50, 50, "Clip-4-Win says: Hello World!")
  85.         hOldFont = SelectObject(hDC, hFont)
  86.         TextOut(hDC, 50, 150, "In " + aFont[LF_FaceName] + " "    ;
  87.                               + ltrim(str(nPtSize)) + ": Hello World!")
  88.         PrintLines(hDC, 50, 250)
  89.         SelectObject(hDC, hOldFont)
  90.         EndPage(hDC)
  91.  
  92.         EndDoc(hDC)
  93.         DeleteObject(hFont)
  94.     endif
  95.     DeleteDC(hDC)
  96. endif
  97. return nil
  98.  
  99.  
  100. static function PrintLines(hDC, nX, nY)
  101. local    i, aTM, nVert := GetDeviceCaps(hDC, VERTRES)    // page height
  102. local    nLineHeight, nLines
  103.  
  104. GetTextMetrics(hDC, @aTM)
  105. nLineHeight = aTM[TM_Height] + aTM[TM_ExternalLeading]
  106. nLines = int((nVert - nY) / nLineHeight)
  107. for i = 1 to nLines
  108.     TextOut(hDC, nX, nY,  "Just filling the paper!")
  109.     nX += aTM[TM_AveCharWidth]
  110.     nY += nLineHeight
  111. next i
  112. return nil
  113.  
  114.  
  115. static function DoBmp(oWnd)
  116. local    hDC, cBmp
  117.  
  118. if !empty(hDC := GetPrintDC())        // see also: PrintDlg()
  119.     StartDoc(hDC, "SomeDocument")
  120.  
  121.     StartPage(hDC)
  122.     TextOut(hDC, 50, 50, "Clip-4-Win says: Hello World!")
  123.     cBmp = ReadDIB("clip4win.bmp")
  124.     ShowDIB(hDC, cBmp, 100, 150)
  125.     EndPage(hDC)
  126.  
  127.     EndDoc(hDC)
  128.     DeleteDC(hDC)
  129. endif
  130. return nil
  131.  
  132.  
  133. static function MenuSetup(oWnd)
  134. MENU IN oWnd
  135.     POPUP "&File"
  136.         MENUITEM "Print &Hello"             ACTION DoHello(oWnd)
  137.         MENUITEM "Print Using &Arial Font"  ACTION DoArial(oWnd)
  138.         MENUITEM "Print Using &Font"        ACTION DoFont(oWnd)
  139.         MENUITEM "Print &Bitmap"            ACTION DoBmp(oWnd)
  140.         MENUITEM SEPARATOR
  141.         MENUITEM "E&xit"   ACTION PostQuitMessage(0)
  142.     ENDPOPUP
  143.     POPUP "&Help"
  144.         MENUITEM "&About"  ACTION MessageBox( , "Easy!", "Clip-4-Win App")
  145.     ENDPOPUP
  146. ENDMENU
  147.  
  148. return nil
  149.  
  150.