home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
PRINTER.PRG
< prev
next >
Wrap
Text File
|
1992-10-12
|
5KB
|
197 lines
////////////////////////////
//
// Clip-4-Win sample source
//
// Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// Printing using GDI is shown here.
// Also, the printer common dialog.
//
////////////////////////////
#include "windows.ch"
static hWnd, hInst, hPrevInst, nCmdShow
static cAppName := "Clip-4-Win"
function main()
hWnd = WinSetup()
DoMenu(hWnd)
HideCaret(hWnd)
do while .t.
ChkEvent()
// no need to process the event (EVENT_MENU is done automatically)
enddo
return 0
function WinSetup()
local hWnd
/////////////////////////
//
// Typical windows-style setup code...
//
/////////////////////////
hInst = _GetInstance()
hPrevInst = _GetPrevInstance()
nCmdShow = _GetnCmdShow()
if hPrevInst == 0
// need to register the window class
if !RegisterClass(CS_HREDRAW + CS_VREDRAW, ;
hInst, ;
0, ; // default icon
0, ; // default cursor
0, ; // default background brush
cAppName) // app name
// probably out of resources
quit
endif
endif
// create our main window
hWnd = CreateWindow(cAppName, ; // window class
"Clip-4-Win Printer Demo", ; // caption for title bar
WS_OVERLAPPEDWINDOW,; // window style
CW_USEDEFAULT, ; // x co-ordinate
0, ; // y co-ordinate
300, ; // width
200, ; // height
0, ; // hWnd of parent (none)
0, ; // hMenu of menu (none yet)
hInst) // our own app instance
if hWnd == 0
// probably out of resources
quit
endif
// make sure it's displayed ...
ShowWindow(hWnd, nCmdShow)
// ... and up to date
UpdateWindow(hWnd)
return hWnd
procedure DoPrint()
local hPrintDC, hIcon, hBrush, hOldBrush, hCursor, hOldCursor
local nBlack := RGB(0, 0, 0)
local i, nWidth, nHeight
// display printer dialog box, so the user can choose the settings
hPrintDC = GetPrintDC()
if empty(hPrintDC)
// cancelled by the user
return
endif
// print a test page
hCursor = LoadCursor( , IDC_WAIT)
hOldCursor = SetCursor(hCursor)
nWidth = GetDeviceCaps(hPrintDC, HORZRES)
nHeight = GetDeviceCaps(hPrintDC, VERTRES)
StartDoc(hPrintDC, "TestOutput")
StartPage(hPrintDC)
TextOut(hPrintDC, 100, 50, "Clip-4-Win Printer Test Page")
Rectangle(hPrintDC, 0, 0, nWidth, nHeight)
MoveTo(hPrintDC, 0, 0)
LineTo(hPrintDC, nWidth, nHeight)
MoveTo(hPrintDC, nWidth, 0)
LineTo(hPrintDC, 0, nHeight)
Arc(hPrintDC, 1000, 1000, 1300, 1200, 1250, 1190, 1100, 1100)
hBrush = CreateHatchBrush(HS_HORIZONTAL, nBlack)
hOldBrush = SelectObject(hPrintDC, hBrush)
Chord(hPrintDC, 1500, 1200, 2000, 1350, 1550, 1340, 1400, 1200)
SelectObject(hPrintDC, hOldBrush)
DeleteObject(hBrush)
hBrush = CreateHatchBrush(HS_BDIAGONAL, nBlack)
hOldBrush = SelectObject(hPrintDC, hBrush)
Pie(hPrintDC, 100, 1200, 700, 1500, 650, 1490, 120, 1280)
SelectObject(hPrintDC, hOldBrush)
DeleteObject(hBrush)
hBrush = CreateHatchBrush(HS_FDIAGONAL, nBlack)
hOldBrush = SelectObject(hPrintDC, hBrush)
Polygon(hPrintDC, { {1000, 250}, {1600, 500}, {1800, 100} })
SelectObject(hPrintDC, hOldBrush)
DeleteObject(hBrush)
PolyLine(hPrintDC, { {300, 700}, {100, 900}, {500, 1000} })
for i = 100 to 500 step 100
TextOut(hPrintDC, i + 400, i + 100, nstr(i))
next i
EndPage(hPrintDC)
EndDoc(hPrintDC)
DeleteDC(hPrintDC)
SetCursor(hOldCursor)
return
procedure DoExit()
quit
return
procedure DoAbout()
MessageBox( , "Select File...Print for a test page", "About", MB_OK)
return
procedure DoMenu(hWnd)
local hMenu, hPopupMenu
if (hMenu := GetMenu(hWnd)) != nil
DestroyMenu(hMenu)
endif
// do new one (forget old value)
hMenu = CreateMenu()
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
AppendMenu(hPopupMenu, "new", MF_GRAYED + MF_STRING, "&New", {|| qout("new")})
AppendMenu(hPopupMenu, "open", MF_GRAYED + MF_STRING, "&Open", {|| qout("open")})
AppendMenu(hPopupMenu, "save", MF_GRAYED + MF_STRING, "&Save", {|| qout("save")})
AppendMenu(hPopupMenu, "saveas", MF_GRAYED + MF_STRING, "Save &As", {|| qout("save as")})
AppendMenu(hPopupMenu, "", MF_SEPARATOR)
AppendMenu(hPopupMenu, "print", MF_ENABLED + MF_STRING, "&Print", {|| DoPrint()})
AppendMenu(hPopupMenu, "", MF_SEPARATOR)
AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|| DoExit()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "help", MF_ENABLED + MF_POPUP, "&Help", hPopupMenu)
AppendMenu(hPopupMenu, "about", MF_ENABLED + MF_STRING, "&About", {|| DoAbout()})
SetMenu(hWnd, hMenu)
return
function nstr(n)
return alltrim(str(n)) + " "