home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / PRINTER.PRG < prev    next >
Text File  |  1992-10-12  |  5KB  |  197 lines

  1. ////////////////////////////
  2. //
  3. //    Clip-4-Win sample source
  4. //
  5. //    Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
  6. //    All Rights Reserved.
  7. //
  8. //    Printing using GDI is shown here.
  9. //    Also, the printer common dialog.
  10. //
  11. ////////////////////////////
  12.  
  13.  
  14. #include "windows.ch"
  15.  
  16.  
  17. static    hWnd, hInst, hPrevInst, nCmdShow
  18. static    cAppName := "Clip-4-Win"
  19.  
  20.  
  21. function main()
  22.  
  23. hWnd = WinSetup()
  24. DoMenu(hWnd)
  25. HideCaret(hWnd)
  26.  
  27. do while .t.
  28.     ChkEvent()
  29.     // no need to process the event (EVENT_MENU is done automatically)
  30. enddo
  31.  
  32. return 0
  33.  
  34.  
  35.  
  36. function WinSetup()
  37. local    hWnd
  38.  
  39. /////////////////////////
  40. //
  41. //    Typical windows-style setup code...
  42. //
  43. /////////////////////////
  44.  
  45.  
  46. hInst = _GetInstance()
  47. hPrevInst = _GetPrevInstance()
  48. nCmdShow = _GetnCmdShow()
  49.  
  50. if hPrevInst == 0
  51.     // need to register the window class
  52.     if !RegisterClass(CS_HREDRAW + CS_VREDRAW,    ;
  53.               hInst,    ;
  54.               0,        ;    // default icon
  55.               0,        ;    // default cursor
  56.               0,        ;    // default background brush
  57.               cAppName)        // app name
  58.  
  59.         // probably out of resources
  60.         quit
  61.     endif
  62. endif
  63.  
  64. // create our main window
  65. hWnd = CreateWindow(cAppName,        ;    // window class
  66.             "Clip-4-Win Printer Demo", ; // caption for title bar
  67.             WS_OVERLAPPEDWINDOW,;    // window style
  68.             CW_USEDEFAULT,    ;    // x co-ordinate
  69.             0,            ;    // y co-ordinate
  70.             300,        ;    // width
  71.             200,        ;    // height
  72.             0,            ;    // hWnd of parent (none)
  73.             0,            ;    // hMenu of menu (none yet)
  74.             hInst)            // our own app instance
  75.  
  76. if hWnd == 0
  77.     // probably out of resources
  78.     quit
  79. endif
  80.  
  81. // make sure it's displayed ...
  82. ShowWindow(hWnd, nCmdShow)
  83.  
  84. // ... and up to date
  85. UpdateWindow(hWnd)
  86.  
  87. return hWnd
  88.  
  89.  
  90. procedure DoPrint()
  91. local    hPrintDC, hIcon, hBrush, hOldBrush, hCursor, hOldCursor
  92. local    nBlack := RGB(0, 0, 0)
  93. local    i, nWidth, nHeight
  94.  
  95. // display printer dialog box, so the user can choose the settings
  96. hPrintDC = GetPrintDC()
  97. if empty(hPrintDC)
  98.     // cancelled by the user
  99.     return
  100. endif
  101.  
  102. // print a test page
  103.  
  104. hCursor = LoadCursor( , IDC_WAIT)
  105. hOldCursor = SetCursor(hCursor)
  106.  
  107. nWidth = GetDeviceCaps(hPrintDC, HORZRES)
  108. nHeight = GetDeviceCaps(hPrintDC, VERTRES)
  109.  
  110. StartDoc(hPrintDC, "TestOutput")
  111. StartPage(hPrintDC)
  112.  
  113. TextOut(hPrintDC, 100, 50, "Clip-4-Win Printer Test Page")
  114. Rectangle(hPrintDC, 0, 0, nWidth, nHeight)
  115. MoveTo(hPrintDC, 0, 0)
  116. LineTo(hPrintDC, nWidth, nHeight)
  117. MoveTo(hPrintDC, nWidth, 0)
  118. LineTo(hPrintDC, 0, nHeight)
  119.  
  120. Arc(hPrintDC,   1000, 1000,   1300, 1200,   1250, 1190,   1100, 1100)
  121.  
  122. hBrush = CreateHatchBrush(HS_HORIZONTAL, nBlack)
  123. hOldBrush = SelectObject(hPrintDC, hBrush)
  124. Chord(hPrintDC, 1500, 1200,   2000, 1350,   1550, 1340,   1400, 1200)
  125. SelectObject(hPrintDC, hOldBrush)
  126. DeleteObject(hBrush)
  127.  
  128. hBrush = CreateHatchBrush(HS_BDIAGONAL, nBlack)
  129. hOldBrush = SelectObject(hPrintDC, hBrush)
  130. Pie(hPrintDC,   100, 1200,   700, 1500,   650, 1490,   120, 1280)
  131. SelectObject(hPrintDC, hOldBrush)
  132. DeleteObject(hBrush)
  133.  
  134. hBrush = CreateHatchBrush(HS_FDIAGONAL, nBlack)
  135. hOldBrush = SelectObject(hPrintDC, hBrush)
  136. Polygon(hPrintDC, { {1000, 250}, {1600, 500}, {1800, 100} })
  137. SelectObject(hPrintDC, hOldBrush)
  138. DeleteObject(hBrush)
  139.  
  140. PolyLine(hPrintDC, { {300, 700}, {100, 900}, {500, 1000} })
  141.  
  142.  
  143. for i = 100 to 500 step 100
  144.     TextOut(hPrintDC, i + 400, i + 100, nstr(i))
  145. next i
  146.  
  147. EndPage(hPrintDC)
  148. EndDoc(hPrintDC)
  149.  
  150. DeleteDC(hPrintDC)
  151.  
  152. SetCursor(hOldCursor)
  153.  
  154. return
  155.  
  156.  
  157. procedure DoExit()
  158. quit
  159. return
  160.  
  161.  
  162. procedure DoAbout()
  163. MessageBox( , "Select File...Print for a test page", "About", MB_OK)
  164. return
  165.  
  166.  
  167. procedure DoMenu(hWnd)
  168. local    hMenu, hPopupMenu
  169.  
  170. if (hMenu := GetMenu(hWnd)) != nil
  171.     DestroyMenu(hMenu)
  172. endif
  173. // do new one (forget old value)
  174. hMenu = CreateMenu()
  175. hPopupMenu = CreatePopupMenu()
  176. AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
  177. AppendMenu(hPopupMenu, "new", MF_GRAYED + MF_STRING, "&New", {|| qout("new")})
  178. AppendMenu(hPopupMenu, "open", MF_GRAYED + MF_STRING, "&Open", {|| qout("open")})
  179. AppendMenu(hPopupMenu, "save", MF_GRAYED + MF_STRING, "&Save", {|| qout("save")})
  180. AppendMenu(hPopupMenu, "saveas", MF_GRAYED + MF_STRING, "Save &As", {|| qout("save as")})
  181. AppendMenu(hPopupMenu, "", MF_SEPARATOR)
  182. AppendMenu(hPopupMenu, "print", MF_ENABLED + MF_STRING, "&Print", {|| DoPrint()})
  183. AppendMenu(hPopupMenu, "", MF_SEPARATOR)
  184. AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|| DoExit()})
  185. hPopupMenu = CreatePopupMenu()
  186. AppendMenu(hMenu, "help", MF_ENABLED + MF_POPUP, "&Help", hPopupMenu)
  187. AppendMenu(hPopupMenu, "about", MF_ENABLED + MF_STRING, "&About", {|| DoAbout()})
  188. SetMenu(hWnd, hMenu)
  189. return
  190.  
  191.  
  192. function nstr(n)
  193. return alltrim(str(n)) + " "
  194.  
  195.  
  196.  
  197.