|
-
Dec 23rd, 2002, 01:10 PM
#1
Plotting on the printer
I'm posting this one a second time as I didn't get a satisfactory answer the first time.
I want to plot marks on a sheet of paper according to their x & y coordinates, and the printer scale must be 1:1, i.e. if the coordinates are for example (53,67) relative to the origin, then I want to actually measure 53 and 67 mm with a ruler. The origin is to be set at approximately the center of the sheet (don't care if the margins are not quite symmetric)
I've used the printer.width and printer.height properties. For my current printer settings (paper size, orientation & whatnot) I'm getting 11904 nd 16834 respectively. How can I convert these numbers into mm?
Merry Christmas to you all!
-
Dec 23rd, 2002, 01:52 PM
#2
PowerPoster
Well
VB Code:
Printer.ScaleMode = vbMillimeters
It's a start....
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Dec 23rd, 2002, 02:17 PM
#3
Frenzied Member
Plot:
Code:
' plot position x = 40 y = 55
Printer.CurrentX = 40
Printer.CurrentY = 55
Printer.Print "X" or whatever
You are actually better off using the DrawText api to position and print data. You can use a lot of DT_ constants to position the text the way you want it, using a graphics font like Zap Dingats or Math Symbols, etc.
Code:
Private Const DT_ACCEPT_DBCS = (&H20)
Private Const DT_AGENT = (&H3)
Private Const DT_BOTTOM = &H8
Private Const DT_CALCRECT = &H400
Private Const DT_CENTER = &H1
Private Const DT_CHARSTREAM = 4
Private Const DT_DISPFILE = 6
Private Const DT_DISTLIST = (&H1)
Private Const DT_EDITABLE = (&H2)
Private Const DT_EDITCONTROL = &H2000
Private Const DT_END_ELLIPSIS = &H8000
Private Const DT_EXPANDTABS = &H40
Private Const DT_EXTERNALLEADING = &H200
Private Const DT_FOLDER = (&H1000000)
Private Const DT_FOLDER_LINK = (&H2000000)
Private Const DT_FOLDER_SPECIAL = (&H4000000)
Private Const DT_FORUM = (&H2)
Private Const DT_GLOBAL = (&H20000)
Private Const DT_HIDEPREFIX = &H100000
Private Const DT_INTERNAL = &H1000
Private Const DT_LEFT = &H0
Private Const DT_LOCAL = (&H30000)
Private Const DT_MAILUSER = (&H0)
Private Const DT_METAFILE = 5
Private Const DT_MODIFIABLE = (&H10000)
Private Const DT_MODIFYSTRING = &H10000
Private Const DT_MULTILINE = (&H1)
Private Const DT_NOCLIP = &H100
Private Const DT_NOFULLWIDTHCHARBREAK = &H80000
Private Const DT_NOPREFIX = &H800
Private Const DT_NOT_SPECIFIC = (&H50000)
Private Const DT_ORGANIZATION = (&H4)
Private Const DT_PASSWORD_EDIT = (&H10)
Private Const DT_PATH_ELLIPSIS = &H4000
Private Const DT_PLOTTER = 0
Private Const DT_PREFIXONLY = &H200000
Private Const DT_PRIVATE_DISTLIST = (&H5)
Private Const DT_RASCAMERA = 3
Private Const DT_RASDISPLAY = 1
Private Const DT_RASPRINTER = 2
Private Const DT_REMOTE_MAILUSER = (&H6)
Private Const DT_REQUIRED = (&H4)
Private Const DT_RIGHT = &H2
Private Const DT_RTLREADING = &H20000
Private Const DT_SET_IMMEDIATE = (&H8)
Private Const DT_SET_SELECTION = (&H40)
Private Const DT_SINGLELINE = &H20
Private Const DT_TABSTOP = &H80
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WAN = (&H40000)
Private Const DT_WORD_ELLIPSIS = &H40000
Private Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub
'In a form
Private Sub Form_Load()
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
-
Dec 24th, 2002, 04:46 AM
#4
Re: Well
Originally posted by James Stanich
VB Code:
Printer.ScaleMode = vbMillimeters
It's a start....
I'm afraid I've got stuck right after that start. I still need to know the printer.width and printer.height values in mm. The reason is I must draw the coordinate axes as well, by using the printer.line method. Both axes must be drawn from -100 to +100 mm so that (0,0) lies at the approximate center of the sheet.
Do you know how to convert from those values I mentioned in my first post (11904 & 16834) to mm or inches?
-
Dec 24th, 2002, 04:51 AM
#5
Originally posted by jim mcnamara
You are actually better off using the DrawText api to position and print data.
That's interesting but at first glance it looks like it's intended for printing rather than plotting (i.e. using the printer.line method) As a matter of fact I didn't quite get to try it out as the code crashed when I tried to run it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|