Author
|
Topic: Use of API with EZGUI
|
Brian Reynolds Member
|
posted 02-18-2004 11:27 PM
I note it has been suggested that EZGUI users could attend a seminar. This sounds great but I doubt if the Australian Tax Office would give me a deduction for my expenses so I'll have to give it a miss. What I would find very useful is some info on using the API with EZGUI. Recently I have made a few enquiries in the forum about different API calls and I've had a good response from Chris which in some cases has allowed me to expand into the use of a few more API calls and get far more value from my PBWin and EZGUI. I think there would probably be a few other EZGUI users who would benefit from a few tutorials on using the API with EZGUI. Please give it some thought. Brian.
|
Eddy Van Esch Member
|
posted 02-19-2004 06:05 AM
Brian,For as far as I can tell, using the API with EZGUI is no different than using the API with plain PBWin. Many API calls need a handle of a window or control. You can retrieve such a handle with EZ_HANDLE. For the rest, it is the same as in PBWin without EZGUI.. My general approach is: if I want to do something in my program, first check if EZGUI can do it. If not, check what API calls I can use to do it. I wouldn't go using API calls without a good reason, just for the sake of it... But definitely get some documentation on the API. Either the large Win32.hlp file, or the (even larger) MSDN CD-ROM.. You can also go to the microsoft website for info on a particular API call: http://msdn.microsoft.com/ Kind regards
------------------ Eddy raimundo4u at yahoo dot com www.devotechs.com -- HIME Huge Integer Math and Encryption library |
Brian Reynolds Member
|
posted 02-25-2004 03:58 PM
Thank you, Eddy. There are quite a few instances where it would be quite useful to use API calls. For example, I have been unable to figure out how to justify text using EZGUI on either a canvas or in the print engine. After a lot of time consuming trial and error I finally got it to work using the APIs for letter spacing and word spacing to put justified text into newspaper and magazine columns. I appreciate that using API calls with EZGUI is just the same as using them with PBWin. All I need is for someone to point me in the right direction to somewhere I can find info on using the API calls with PBWin. I already have all the literature you suggested but where I fall short is appreciating how to use EZGUI or PBWin variables in API calls. How do I handle what appear to be TYPEs in the various API calls? Brian.
[This message has been edited by Brian Reynolds (edited 02-25-2004).] |
Chris Boss Administrator
|
posted 02-25-2004 07:55 PM
Brain,The EZ_DCPrint, EZ_LPrint and EZ_CPrint commands can all be modified in how they print text by using the EZ_SetPrintFormat command. This command allows you to force EZGUI to use the DrawText API function (internally) rather than the TextOut API function, where you can pass API flags that determine how the text is drawn, including justification. The EZGUI inc file has a few API constants (EZGUI'ized with %EZ_ prefix), but you can use others defined in the win32api.inc file.
|
Chris Boss Administrator
|
posted 02-25-2004 08:01 PM
ie.code:
EZ_SetPrintFormat 2, X2&, Y2&, %EZ_VCenter,%DT_RIGHT EZ_LPrint X1&,Y1&, "Some text" EZ_SetPrintFormat 0,0,0,0,0
|
Russ Srole Member
|
posted 02-26-2004 02:53 PM
Brian,I agree with everything Eddy said, and I certainly understand the frustration. The problem is that once you know what you want to do and need to go to the API, then where to start. Sometimes I've spent hours searching for the style, message, api call or whatever to fix what should be a 5 minute problem. And, of course, that's why we've all bought Ezgui, but as Chris has said, Ezgui can't do everything anybody might ever want to do. So my suggestion is to just post the question (either here or on PB) & hopefully someone else has fought the battle & is willing to share. Russ |
dhorner Member
|
posted 02-22-2005 10:53 AM
I'm trying (vainly) to get numbers to print right aligned.Reading this post was a little but help more help is appreciated. This" " 123" " 234" Print 123 234 This: "*****123" "*****234" Prints "*****123" "*****234" It appears that it is ignoring the spaces. Thanks |
Chris Boss Administrator
|
posted 02-22-2005 11:32 AM
Drawing commands should handle spaces properly.You didn't indicate whether you are printing to the printer or a canvas control. The Visual Designer though does remove spaces from the text field, so you will have to modify the code by handle.
|
Gary Stout Member
|
posted 02-22-2005 11:35 AM
Doug, If you wanting to right justify numbers in text box, you can add a line in the design code to do this. I am not at a computer that has any of my programs on it, or I could give you the exact line, but if you search the forum here for "appendstyle", you should find the answer. Let me know if I have missed your point and you need something different. Thanks, Gary |
dhorner Member
|
posted 02-22-2005 12:01 PM
Chris, GarySorry, I am trying to print to a printer. This is one of the many modifications I've tried to print right justified. This version prints left justified. code:
EZ_GetLVItem "CS",%CS_OUTPUT, lPText$, 0, R&, 1, "" lFormat=SPACE$(20) lFormat=RSET$(lPText$,LEN(lPText$)) EZ_Lprint 375,l&,lFormat
Thanks Doug |
Chris Boss Administrator
|
posted 02-22-2005 01:06 PM
Douglas,Your use of the RSET command seems different than what the PB (6.1) docs say ! Your code: code:
lFormat=SPACE$(20) lFormat=RSET$(lPText$,LEN(lPText$))
The correct syntax (according to docs): code:
lFormat=SPACE$(20) RSET lFormat = lPText$
If later versions of PB have a different syntax which allows the use of a length, then possibly your code should look like this: code:
lFormat=RSET$(lPText$,20)
Likely the error is in this block of code and not the EZGUI print commands.
|
dhorner Member
|
posted 02-22-2005 01:24 PM
ChrisI already tried it both way's. I'll try it again and check back. Doug |
dhorner Member
|
posted 02-22-2005 03:55 PM
Still haven't given up hope This is the test code I'm working with to try and get text to right align. It appears to be trying to center the text. Any idea's? code:
SUB FORM1_PRINT_Click() LOCAL I&,l&,lS$,lR& EZ_DefFont 50, "Times New Roman", 12, "P" ' define a printer font DIM EZP AS GLOBAL EZPRINTER, W!, H!, FG&, BG& RANDOMIZE TIMER EZP.Punits=1 EZP.PrintWhat=1 Printer=EZ_ChoosePrinter("FORM1",EZP) EZ_StartDoc "Print" EZ_StartPage EZ_UseFont 50 FOR I&=1 TO 50 lS$=SPACE$(20) RSET lS$ = FORMAT$(RND(1,50),"$###,###.00") EZ_Lprint 10,l&,lS$ 'MsgBox Str$(Len(lS$)) '<<< This shows 20 lS$=SPACE$(20) lS$=RSET$(FORMAT$(RND(1,50),"$###,###.00"),20) EZ_Lprint 200,l&,lS$ 'MsgBox Str$(Len(lS$)) '<<< This shows 20 lS$=SPACE$(20) lS$=RSET$(FORMAT$(RND(1,50),"$###,###.00"),LEN(FORMAT$(RND(1,50),"$###,###.00"))) EZ_Lprint 300,l&,lS$ 'MsgBox Str$(Len(lS$)) '<<< Variable based on len of RND(1,50) l&=l&+20 NEXT I& EZ_EndPage EZ_EndDoc END SUB
|
Brian Reynolds Member
|
posted 02-22-2005 05:11 PM
I first posted this item some time ago but after a recent addition to it, I have reviewed all the advice again. What I originally sought was an easy way to justify text. The advice I got suggests it is really quite simply as EZ_SetPrintFormat offers aligning to the right, left and so on. What I still want to do is align the text on both sides as in a newspaper or magazine column. I can't EZ_SetPrintFormat to do that. Can anyone explain how it is done? Brian.
|
Bert Mercier Member
|
posted 02-22-2005 06:23 PM
Don't you have to use a monospaced font. I think like "Courier New" to print in columnar format. For other fonts I break up the location of the decimal and/or comma then print the numbers from that location.Bert Mercier |
Bert Mercier Member
|
posted 02-22-2005 07:14 PM
Try this very fast programming not pretty code:
Sub FORM1_PRINT_Click() Local EZP As EZPRINTER, TotalRec As Long, Ctr As Long Local W!, H!, n&, LinePerPage As Long, I&, Row As Long, LP& Dim Col(1 To 7) As Long Local LineThickness As Single Local LineLength As Long Local LineSpacing As Long Local TextRow As Long Local Rec As Long Local lS$ EZP.PrintWhat=1 EZP.AllowPages=1 EZP.AllowSelection=0 EZP.CollateFlag=0 EZP.FromPage=1 EZP.MinPage=1 EZP.MaxPage=1 EZP.PUnits=1 If EZ_ChoosePrinter("FORM1", EZP) Then EZ_StartDoc "My Document 1" EZ_DefFont 50, "Times New Roman", 12, "" ' define a printer font EZ_GetTextSize 50, "X", W!, H!, 2 EZ_DefFont 51, "Courier New", 12, "" 'Bold Underline LinePerPage= 28 'Int(EZP.AHeight/H!) formula for height of characters LineThickness = 1 LineLength = 795 LineSpacing = 15 EZ_Color 0, -1 TotalRec = UBound(gTmpRecord()) EZP.ToPage = RoundUp(TotalRec + 1, LinePerPage) Col(1) = 5 'Column location Col(2) = 100 Col(3) = 190 Col(4) = 580 Col(5) = 640 Col(6) = 690 Col(7) = 800 For I&=1 To EZP.Copies 'Number of copies selected from the print dialog For N&=EZP.FromPage To EZP.ToPage EZ_StartPage Row = 60 'Starting row to print list TextRow = 105 For LP&= 0 To LinePerPage 'LinePerPage counts how many grid rows per sheet EZ_DoEvents 10 'lS$=Space$(11) lS$ = Format$(Rnd(1,50),"$###,###.00") EZ_UseFont 50 For Ctr = 0 To Len(lS$) EZ_Lprint Col(2),Row + LineSpacing,Mid$(lS$,Len(lS$)-Ctr,1) Col(2) = Col(2) - W! Next Ctr Col(2) = 100 EZ_UseFont 51 EZ_Lprint Col(3),Row + LineSpacing,lS$ Row = Row + LineSpacing Next LP& EZ_EndPage Next N& Next I& EZ_FreeFont 50 EZ_FreeFont 51 EZ_EndDoc End If End Sub
You just have to insert a space for monospaced fontsBert |
dhorner Member
|
posted 02-23-2005 08:36 AM
Dup[This message has been edited by dhorner (edited 02-23-2005).] |
dhorner Member
|
posted 02-23-2005 08:40 AM
Gent'sI can't believe this is that difficult. Someone has to have an easier answer. Added:
Well I was wrong http://www.powerbasic.com/support/forums/Forum4/HTML/001642.html Doug
|
Bert Mercier Member
|
posted 02-23-2005 10:31 AM
Maybe I need to understand the problem. But what are you trying to right justify the decimal point or the last number of the decimal? It seems by getting the average width of the numbers and then locating each character you would then make the font monospaced but could control the alignment.Bert Mercier |
dhorner Member
|
posted 02-23-2005 11:19 AM
The code below works. If I used EZ_GetTextSize 50, "X", W!, H!, 2 the W! is 11 which spaces out the characters to much. If I put a hard 8 in the lCol& calculation then the spacing is much better. I'm using code:
EZ_DefFont 50, "Times New Roman", 10, "" ' define a printer font EZ_DefFont 51, "Times New Roman", 10, "PB" ' define a printer font LOCAL R&, lI&,lSI&,lPText$,l&,lCol&,lRow&,lCtr& DIM lFormat AS STRING * 12 DIM EZP AS EZPRINTER, W!, H!, FG&, BG& EZ_Color -1, -1 EZP.Punits=1 EZP.PrintWhat=1 EZP.AllowPages=1 EZP.AllowSelection=0 EZP.CollateFlag=0 EZP.FromPage=1 EZP.MinPage=1 EZP.MaxPage=1 Printer=EZ_ChoosePrinter("CS",EZP) EZ_StartDoc "Customer Aging Report" EZ_SetPrintFormat 0, 0, 0, %EZ_VCenter,%DT_RIGHT EZ_UseFont 50 EZ_GetTextSize 50, "X", W!, H!, 2 More Code Here... lCol&=475 FOR lCtr& = 0 TO LEN(lPText$) EZ_Lprint lCol&,l&,MID$(lPText$,LEN(lPText$)-lCtr&,1) lCol& = lCol& - 8 NEXT lCtr&
I'm fine with what needs to be done just not understanding why the Char Width is not more accurate. |
Bert Mercier Member
|
posted 02-23-2005 01:26 PM
My thinking is that you are measuring "X" and the value for "X" will be different than "1" because the font is proportional. You could compute in advance the Width of "0 to 9", "." , "$" and "," then adjust your spacing accordingly to have columns that line up.Bert Mercier |
dhorner Member
|
posted 02-23-2005 02:15 PM
BertUnderstand now ... Geeze Thanks for the patience and the help! Doug |
Brian Reynolds Member
|
posted 02-23-2005 06:33 PM
Centring text and/or figures or aligning them on the right is really quite simple in EZGUI but no-one seems to know how to justify text so that a column of text is aligned on both sides. In the newspaper game that is what we call "justified" text. If it is aligned on the left only, it is referred to as ragged right. If it is aligned on the right only, it is referred to as ragged left. If each line is centred, it is referred to as ragged centre. You will note that most newspaper columns are aligned on the left and aligned full out on the right - that is what we call "justified". "Justified" is what I am trying to achieve. Apparently EZGUI doesn't do that. AM I RIGHT? Brian.
|
Bert Mercier Member
|
posted 02-23-2005 07:55 PM
No it can be done the same way as you would when you want to justify to the right. I would first get the line you want to print and store it in a string. You should set the first letter on the left column and the last on th right column. then it is just a matter of adding the width of all the remaining characters and comparing it with the space in between the first and last character. If you give some extra "weight" to the spaces you should be able to do it in no time. The hardest part would be to know all the characters that you want on the line. If I had an economical printer to use at home so I print some garbage I could get it done.All the functions you need to do this is in EZ so no use of the API is required. If you can't figure it out, just leave a message and if I find time at work I will start it for you. You should be able to create a sub like Declare Sub Prnt_JustifyLR(Str as string, lCol as long,rCol as long, Row as long) Bert Mercier [This message has been edited by Bert Mercier (edited 02-23-2005).] | |