Print RichText/Editor

Share your advanced PureBasic knowledge/code with the community.
LuckyLuke
Enthusiast
Enthusiast
Posts: 181
Joined: Fri Jun 06, 2003 2:41 pm
Location: Belgium

Print RichText/Editor

Post by LuckyLuke »

Code updated for 5.20+

Finally managed to print contents of richtext control.
Any comments/optimisations are welcome ...

Special thanks to El_Choni :!: :!: :!:

Code: Select all

Global PrinterDC

Procedure  StartPrint(Doc.s)
    mDI.DOCINFO
    mDI\cbSize = SizeOf(DOCINFO)
    mDI\lpszDocName = @Doc
    mDI\lpszOutput = 0
    StartDoc_(PrinterDC,mDI)
EndProcedure

Procedure PrintRichText(hWnd, hInst, rtfEdit, LM, RM, TM, BM)
   ;
   ;  Purpose:
   ;           Prints the contents of an RTF text box given it;s handle, the
   ;           calling program;s handle(s), And the page margins.
   ;
   ;  Parameters:
   ;           hWnd     = Parent window (used for print common dlg)
   ;           hInst    = Instance of calling program
   ;           rtfEdit  = Handle of rich edit control
   ;           LM       = Left Margin in inches
   ;           RM       = Right Margin in inches
   ;           TM       = Top Margin in inches
   ;           BM       = Bottom Margin in inches
   ;
   fr.FORMATRANGE
   pd.PRINTDLG
   ;- Setup the print common dialog
   pd\lStructSize = SizeOf(PRINTDLG)
   pd\hwndOwner = hWnd
   pd\hDevMode = #Null
   pd\hDevNames = #Null
   pd\nFromPage = 0
   pd\nToPage = 0
   pd\nMinPage = 0
   pd\nMaxPage = 0
   pd\nCopies = 0
   pd\hInstance = hInst
   pd\Flags = #PD_RETURNDC | #PD_PRINTSETUP
   pd\lpfnSetupHook = #Null
   pd\lpSetupTemplateName = #Null
   pd\lpfnPrintHook = #Null
   pd\lpPrintTemplateName = #Null
   
   If PrintDlg_(pd)
     b = GlobalLock_(pd\hDevNames)       
     drv.s  = PeekS(b + PeekW(b))
     name.s = PeekS(b + PeekW(b + 2))

     PrinterDC = CreateDC_(drv,name,0,GlobalLock_(pd\hDevMode))
       
     fr\hdc = PrinterDC
     fr\hdcTarget = PrinterDC
     fr\chrg\cpMin = 0
     fr\chrg\cpMax = -1
     fr\rc\top = TM*1440
     fr\rcPage\top = fr\rc\top
     fr\rc\left = LM*1440
     fr\rcPage\left = fr\rc\left
       ;- Get page dimensions in Twips
     iWidthTwips = Int((GetDeviceCaps_(PrinterDC, #HORZRES)/GetDeviceCaps_(PrinterDC, #LOGPIXELSX))*1440)
     iHeightTwips = Int((GetDeviceCaps_(PrinterDC, #VERTRES )/GetDeviceCaps_(PrinterDC, #LOGPIXELSY))*1440)
     fr\rc\right = iWidthTwips-RM*1440
     fr\rcPage\right = fr\rc\right
     fr\rc\Bottom = iHeightTwips-BM*1440
     fr\rcPage\bottom = fr\rc\bottom
     
     StartPrint("RTF Printing")
     StartPage_(PrinterDC)

       ;- This does the printing. We send messages
       ;  to the edit box telling it to format it;s
       ;  text to fit the Printer;s DC.
       ;
     iTextOut = 0
     iTextAmt = SendMessage_(rtfEdit, #WM_GETTEXTLENGTH, 0, 0)
     While iTextOut<iTextAmt
       iTextOut = SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, fr)
       If iTextOut<iTextAmt
         iTextAmt = iTextAmt - iTextOut
         EndPage_(PrinterDC)
         StartPage_(PrinterDC)
         fr\chrg\cpMin = iTextOut
         fr\chrg\cpMax = -1
       EndIf
     Wend
     SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, #Null)
     ;- Finish the printing.
     EndPage_(PrinterDC)
     EndDoc_(PrinterDC)
     DeleteDC_(PrinterDC)
  EndIf
EndProcedure

Procedure StreamFileInCallback(hFile, pbBuff, cb, pcb)
  ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1
EndProcedure

Procedure loadFile(pFilePath.s)
  If ReadFile(0, pFilePath)
    If GetExtensionPart(pFilePath)="rtf"
      uFormat = #SF_RTF
    Else
      uFormat = #SF_TEXT
    EndIf
    edstr.EDITSTREAM
    edstr\dwCookie = FileID(0)
    edstr\dwError = 0
    edstr\pfnCallback = @StreamFileInCallback()
    SendMessage_(GadgetID(0), #EM_STREAMIN, uFormat, edstr)
    CloseFile(0)
  Else
    MessageRequester("Error", "Error Occured While Opening File", #PB_MessageRequester_Ok)
  EndIf
EndProcedure

If OpenWindow(0, 200, 50, 640, 400,"RTF PRINTING", #PB_Window_SystemMenu)=0:End:EndIf
If CreateMenu(0, WindowID(0))=0:End:EndIf
  MenuTitle("&File")
    MenuItem(0, "&Open")
    MenuItem(1, "&Print")
    MenuItem(2, "&Quit")
EditorGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_O, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_P, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_Q, 2)
Repeat
  EventID = WaitWindowEvent()
  If EventID=#PB_Event_Menu
    Select EventMenu()
      Case 0
        FileName$ = OpenFileRequester("", "", "All files|*.*", 0)
        If FileName$
          loadFile(FileName$)
        EndIf
      Case 1
        PrintRichText(WindowID(0), GetModuleHandle_(0), GadgetID(0), 0, 0, 0, 0)
      Case 2
        Quit = 1
    EndSelect
  ElseIf EventID=#PB_Event_CloseWindow
    Quit = 1
  EndIf
Until Quit
End 
User avatar
J. Baker
Addict
Addict
Posts: 2182
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

just tested it on windows xp and it works great, nice job. :D
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Hi,
I think there is a bug in this. If you try to print something over a page and lets say there is a half a page left to print it won't print the half of the page just the full page. Please help. As an example I just tried to print the source to this example.

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Awesome

Post by LJ »

Awesome work Luck and El-Choni.

This is way off the subject, but I noticed this .rtf box looks just like a web control. I wonder if it is possible to simulate a .rtf input box with a web control? The advantages being that .html allows for the same formating available with the .rtf control, but then adds many, many possibilities like embeded graphic images, sound, java script, hyperlinks, and so on. And printing is very easy, either a java scipt "Click here to Print", or simple left clicking over the web control and selecting Print.

Has anyone entertained this idea before and attempted to simulate all the functionality of a rtf control with a web control?
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

RJP Computing wrote:Hi,
I think there is a bug in this. If you try to print something over a page and lets say there is a half a page left to print it won't print the half of the page just the full page. Please help. As an example I just tried to print the source to this example.

Thanks
Has anybody else seen this problem.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
LuckyLuke
Enthusiast
Enthusiast
Posts: 181
Joined: Fri Jun 06, 2003 2:41 pm
Location: Belgium

Post by LuckyLuke »

RJP Computing.

There is a bug in this :oops:
Following code will solve the problem.

Code: Select all

While iTextOut<iTextAmt 
   iTextOut = SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, fr)            
   If iTextOut<iTextAmt                   
      EndPage_(PrinterDC) 
      StartPage_(PrinterDC) 
      fr\chrg\cpMin = iTextOut 
      fr\chrg\cpMax = -1  
      iTextAmt = iTextAmt - iTextOut 
      iTextOut = 0
   EndIf 
Wend
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

The last lines are missing, when I print it.
Maybe, its because you set EndPage before StartPage.
The While Wend is only done one time.

here is an example for EditorGadgets, we have deveoped in the German Forum. So some Varaibles and comments are in German, but I think, thats not a problem:

"Seitenrand links ..." is the margin at printing, left, top, right, bottom. It not the same, as margin in the richedit, this margin does not effect the printing

Code: Select all

;############################################ 
;Inhalt vom 
;EditorGadget auf Standard-Drucker ausgeben 
; 
;Author : Andreas 
;Juni 2003 
;ergänzt von Wichtel und Joro 
; 
;sämtliche Formatierungen die im EditorGadget 
;vorgenommen werden (Farbe, Font usw.), 
;werden auf den Drucker übernommen. 
;############################################ 
Global GadgetNr,GadgetNr_hWnd 
#Seitenrandlinks=80 
#Seitenrandrechts=81 
#Seitenrandoben=82 
#Seitenrandunten=83 


;####################################################################### 
;die 2 Procedure basieren auf El_Choni's Beispiel 
Procedure StreamFileIn_Callback(hFile, pbBuff, cb, pcb) 
ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1 
EndProcedure 

Procedure FileStreamIn(FileID.l, File.s, Gadget.l,Option.l) 
Protected File 
Protected FileID 
Protected Gadget 
Protected StreamData.EDITSTREAM 
If ReadFile(FileID, File) 
StreamData\dwCookie = UseFile(FileID) 
StreamData\dwError = #Null 
StreamData\pfnCallback = @StreamFileIn_Callback() 
SendMessage_(GadgetNr_hWnd, #EM_STREAMIN, Option, @StreamData) 
CloseFile(FileID) 
EndIf 
EndProcedure 
;####################################################################### 

;unbedingt diese Struktur benutzen 
;mit der Struktur von PB geht es nicht ! 
Structure DInfo1 
cbSize.l 
lpszDocname.l 
lpszOutput.l 
lpszDataType.l 
fwType.w 
EndStructure 


Procedure PrintWindow() 
WindowWidth = 200 
WindowHeight = 40 
If OpenWindow(10, 0, 0, WindowWidth, WindowHeight, #PB_Window_WindowCentered, "Printing") 
SetWindowPos_(WindowID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) 
CreateGadgetList(WindowID(10)) 
TextGadget(0, 10, 10, 180, 20,"Drucke Seite") 
EndIf 
EndProcedure 


Procedure EditorPrint(Dokument.s) 
  Protected DC ,a 
  lppd.PRINTDLGAPI; Struktur für die API Druckerauswahl 
  lppd\lStructsize=SizeOf(PRINTDLGAPI) 
  lppd\Flags=#PD_ALLPAGES| #PD_HIDEPRINTTOFILE | #PD_NOSELECTION | #PD_RETURNDC |#PD_PRINTSETUP 
  printdlg_(lppd); API Druckerauswahl 
   DC=lppd\hdc; hier kommt der Device Context zurück 
  mydevmode.DEVMODE 
  *Pointer.DEVMODE 
  *Pointer=GlobalLock_(lppd\hdevmode) 
  Papierlaenge=*Pointer\dmPaperlength 
  Papierbreite=*Pointer\dmPaperwidth 
  ppmm.f=(*Pointer\dmYResolution/10)/2.54 
  GlobalFree_(hdevmode) 
  cRect.RECT 
  FormatRange.FORMATRANGE 
  Docinfo.DInfo1 
  Docinfo\cbSize = SizeOf(DInfo1) 
  Docinfo\lpszDocname = @Dokument.s 
  Docinfo\lpszOutput = #Null 
  Docinfo\lpszDataType = #Null 
  Docinfo\fwType = 0 
  PrintWindow() 
  SetGadgetText(0, "Druckvorbereitung") 
  Result=StartDoc_(DC,Docinfo) 
  LastChar = 0 
  Randlinks=GetGadgetState(#Seitenrandlinks) 
  Randrechts=GetGadgetState(#Seitenrandrechts) 
  Randoben=GetGadgetState(#Seitenrandoben) 
  Randunten=GetGadgetState(#Seitenrandunten) 
  ActivateGadget(GadgetNr); stürzt ohne Activate ab und zu ab 
  MaxLen = Len(GetGadgetText(GadgetNr))-SendMessage_(GadgetNr_hWnd,#EM_GETLINECOUNT,0,0) 
  OldMapMode = GetMapMode_(DC) 
  SetMapMode_(DC,#MM_TWIPS) 
  OffsetX = Randlinks*ppmm.f-GetDeviceCaps_(DC,#PHYSICALOFFSETX) 
  If OffsetX < GetDeviceCaps_(DC,#PHYSICALOFFSETX):OffsetX=GetDeviceCaps_(DC,#PHYSICALOFFSETX):EndIf 
  OffsetY=-Randoben*ppmm.f+GetDeviceCaps_(DC,#PHYSICALOFFSETY) 
  If OffsetY > -GetDeviceCaps_(DC,#PHYSICALOFFSETY): OffsetY = -GetDeviceCaps_(DC,#PHYSICALOFFSETY):EndIf 
  HorzRes=((Papierbreite/10-Randrechts))*ppmm.f 
  If HorzRes > GetDeviceCaps_(DC,#HORZRES) :HorzRes=GetDeviceCaps_(DC,#HORZRES):EndIf 
  VertRes=-(Papierlaenge/10)*ppmm.f+Randunten*ppmm.f 
  If VertRes < -GetDeviceCaps_(DC,#VERTRES):VertRes=-GetDeviceCaps_(DC,#VERTRES):EndIf 
  SetRect_(cRect,OffsetX,OffsetY,HorzRes,VertRes) 
  DPtoLP_(DC,cRect,2) 
  SetMapMode_(DC,OldMapMode) 
  FormatRange\hdc = DC 
  FormatRange\hdcTarget = DC 
  FormatRange\rc\left = cRect\left 
  FormatRange\rc\top = cRect\top 
  FormatRange\rc\right = cRect\right 
  FormatRange\rc\bottom = cRect\bottom 
  FormatRange\rcPage\left = cRect\left 
  FormatRange\rcPage\top = cRect\top 
  FormatRange\rcPage\right = cRect\right 
  FormatRange\rcPage\bottom = cRect\bottom 
  a = 1 
  Repeat 
    SetGadgetText(0, "Drucke Seite : "+ Str(a)) 
    Result=StartPage_(DC) 
    FormatRange\chrg\cpMax = -1 
    LastChar = SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,#True,@FormatRange) 
    FormatRange\chrg\cpMin = LastChar 
    SendMessage_(GadgetNr_hWnd,#EM_DISPLAYBAND,0,cRect) 
    a + 1 
    EndPage_(DC) 
  Until LastChar >= MaxLen Or LastChar = -1 
  SetGadgetText(0, "Fertig") 
  CloseWindow(10) 
  EndDoc_(DC) 
  SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,0,0) 
EndProcedure  

If OpenWindow(0, 10, 10, 640, 480, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window") 
  If CreateGadgetList(WindowID()) 
  GadgetNr_hWnd=EditorGadget(1, 0, 0, WindowWidth()-100,WindowHeight()) 
  GadgetNr=1 
  ButtonGadget(2, WindowWidth()-90,10,80,24,"Drucken") 
  ButtonGadget(3, WindowWidth()-90,40,80,24,"Laden") 
  TextGadget(10,WindowWidth()-100,95, 100, 20,"Seitenränder in mm") 

  SpinGadget(#Seitenrandlinks, WindowWidth()-90,150, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandlinks,20) 
  SetGadgetText(#Seitenrandlinks,Str(GetGadgetState(#Seitenrandlinks))) 
  TextGadget(11,WindowWidth()-90,125, 80, 20,"links") 

  SpinGadget(#Seitenrandrechts, WindowWidth()-90,200, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandrechts,20) 
  SetGadgetText(#Seitenrandrechts,Str(GetGadgetState(#Seitenrandrechts))) 
  TextGadget(12,WindowWidth()-90,175, 80, 20,"rechts") 

  SpinGadget(#Seitenrandoben, WindowWidth()-90,250, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandoben,20) 
  SetGadgetText(#Seitenrandoben,Str(GetGadgetState(#Seitenrandoben))) 
  TextGadget(13,WindowWidth()-90,225, 80, 20,"oben") 

  SpinGadget(#Seitenrandunten, WindowWidth()-90,300, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandunten,20) 
  SetGadgetText(#Seitenrandunten,Str(GetGadgetState(#Seitenrandunten))) 
  TextGadget(14,WindowWidth()-90,275, 80, 20,"unten") 
  EndIf 
  Repeat 
  EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow 
    Quit = 1 
    EndIf 
    If EventID = #PB_EventGadget 
    Select EventGadgetID() 
      Case 2 
      EditorPrint(DName$) 
      Case 3 
      DName$ = OpenFileRequester("Datei laden :","*.*", "Text-Dateien | *.txt | Rich Text Files | *.rtf", 0) 
      If UCase(GetExtensionPart(DName$)) = "RTF" 
      FileStreamIn(0,DName$, 1,#SF_RTF) 
      Else 
      FileStreamIn(0,DName$, 1,#SF_TEXT) 
      EndIf 
      Case #Seitenrandlinks 
          If spinc=2 
             spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandlinks) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandlinks,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandrechts 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandrechts) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandrechts,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandoben 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandoben) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandoben,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandunten 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandunten) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandunten,Str(spin)) 
            WindowEvent() 
          EndIf 
    EndSelect 
    EndIf 
  Until Quit = 1 
EndIf 
End 
Johannes
LuckyLuke
Enthusiast
Enthusiast
Posts: 181
Joined: Fri Jun 06, 2003 2:41 pm
Location: Belgium

Post by LuckyLuke »

JoRo

I get into an endless loop when I push the print button.
I'm using a HP LaserJet 4100 PCL 6 as network printer on a Windows NT machine.

Using this code works fine here :

Code: Select all

Global PrinterDC 

Procedure  StartPrint(Doc.s) 
    mDI.DOCINFO 
    mDI\cbSize = SizeOf(DOCINFO) 
    mDI\lpszDocName = @Doc 
    mDI\lpszOutput = 0 
    StartDoc_(PrinterDC,mDI) 
EndProcedure 

Procedure PrintRichText(hWnd, hInst, rtfEdit, LM, RM, TM, BM) 
   ; 
   ;  Purpose: 
   ;           Prints the contents of an RTF text box given it;s handle, the 
   ;           calling program;s handle(s), And the page margins. 
   ; 
   ;  Parameters: 
   ;           hWnd     = Parent window (used for print common dlg) 
   ;           hInst    = Instance of calling program 
   ;           rtfEdit  = Handle of rich edit control 
   ;           LM       = Left Margin in inches 
   ;           RM       = Right Margin in inches 
   ;           TM       = Top Margin in inches 
   ;           BM       = Bottom Margin in inches 
   ; 
   fr.FORMATRANGE 
   pd.PRINTDLGAPI 
   ;- Setup the print common dialog 
   pd\lStructSize = SizeOf(PRINTDLGAPI) 
   pd\hwndOwner = hWnd 
   pd\hDevMode = #NULL 
   pd\hDevNames = #NULL 
   pd\nFromPage = 0 
   pd\nToPage = 0 
   pd\nMinPage = 0 
   pd\nMaxPage = 0 
   pd\nCopies = 0 
   pd\hInstance = hInst 
   pd\Flags = #PD_RETURNDC | #PD_PRINTSETUP 
   pd\lpfnSetupHook = #NULL 
   pd\lpPrintSetupTemplateName = #NULL 
   pd\lpfnPrintHook = #NULL 
   pd\lpPrintTemplateName = #NULL 
    
   If printdlg_(pd) 
     b = GlobalLock_(pd\hDevNames)        
     drv.s  = PeekS(b + PeekW(b)) 
     name.s = PeekS(b + PeekW(b + 2)) 

     PrinterDC.l = CreateDC_(drv,name,0,GlobalLock_(pd\hDevMode)) 
        
     fr\hdc = PrinterDC 
     fr\hdcTarget = PrinterDC 
     fr\chrg\cpMin = 0 
     fr\chrg\cpMax = -1 
     fr\rc\top = TM*1440 
     fr\rcPage\top = fr\rc\top 
     fr\rc\left = LM*1440 
     fr\rcPage\left = fr\rc\left 
       ;- Get page dimensions in Twips 
     iWidthTwips = Int((GetDeviceCaps_(PrinterDC, #HORZRES)/GetDeviceCaps_(PrinterDC, #LOGPIXELSX))*1440) 
     iHeightTwips = Int((GetDeviceCaps_(PrinterDC, #VERTRES )/GetDeviceCaps_(PrinterDC, #LOGPIXELSY))*1440) 
     fr\rc\right = iWidthTwips-RM*1440 
     fr\rcPage\right = fr\rc\right 
     fr\rc\Bottom = iHeightTwips-BM*1440 
     fr\rcPage\bottom = fr\rc\bottom 
      
     StartPrint("RTF Printing") 
     StartPage_(PrinterDC) 

       ;- This does the printing. We send messages 
       ;  to the edit box telling it to format it;s 
       ;  text to fit the Printer;s DC. 
       ; 
     iTextOut = 0 
     iTextAmt = SendMessage_(rtfEdit, #WM_GETTEXTLENGTH, 0, 0) 
     While iTextOut<iTextAmt 
       iTextOut = SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, fr)            
       If iTextOut<iTextAmt                   
         EndPage_(PrinterDC) 
         StartPage_(PrinterDC) 
         fr\chrg\cpMin = iTextOut 
         fr\chrg\cpMax = -1  
         iTextAmt = iTextAmt - iTextOut 
         iTextOut = 0
       EndIf 
     Wend 
     SendMessage_(rtfEdit, #EM_FORMATRANGE, 1, #NULL) 
     ;- Finish the printing. 
     EndPage_(PrinterDC) 
     EndDoc_(PrinterDC) 
     DeleteDC_(PrinterDC) 
  EndIf 
EndProcedure 

Procedure StreamFileInCallback(hFile, pbBuff, cb, pcb) 
  ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1 
EndProcedure 

Procedure loadFile(pFilePath.s) 
  If ReadFile(0, pFilePath) 
    If GetExtensionPart(pFilePath)="rtf" 
      uFormat = #SF_RTF 
    Else 
      uFormat = #SF_TEXT 
    EndIf 
    edstr.EDITSTREAM 
    edstr\dwCookie = UseFile(0) 
    edstr\dwError = 0 
    edstr\pfnCallback = @StreamFileInCallback() 
    SendMessage_(GadgetID(0), #EM_STREAMIN, uFormat, edstr) 
    CloseFile(0) 
  Else 
    MessageRequester("Error", "Error Occured While Opening File", #PB_MessageRequester_Ok) 
  EndIf 
EndProcedure 

If OpenWindow(0, 200, 50, 640, 400, #PB_Window_SystemMenu,"RTF PRINTING")=0:End:EndIf 
If CreateMenu(0, WindowID())=0:End:EndIf 
  MenuTitle("&File") 
    MenuItem(0, "&Open") 
    MenuItem(1, "&Print") 
    MenuItem(2, "&Quit") 
If CreateGadgetList(WindowID())=0:End:EndIf 
EditorGadget(0, 0, 0, WindowWidth(), WindowHeight()) 
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_O, 0) 
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_P, 1) 
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_Q, 2) 
Repeat 
  EventID = WaitWindowEvent() 
  If EventID=#PB_EventMenu 
    Select EventMenuID() 
      Case 0 
        FileName$ = OpenFileRequester("", "", "All files|*.*", 0) 
        If FileName$ 
          loadFile(FileName$) 
        EndIf 
      Case 1 
        PrintRichText(WindowID(), GetModuleHandle_(0), GadgetID(0), 0, 0, 0, 0) 
      Case 2 
        Quit = 1 
    EndSelect 
  ElseIf EventID=#PB_Event_CloseWindow 
    Quit = 1 
  EndIf 
Until Quit 
End
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

oh, that was a misunderstanding:
I meant in your code the while wend loop is only done one time and I think, its because you take first EndPage and then StartPage, but I am not sure.

The endless loop in our codeexample sometimes appears. But it is not clear, why.
I think, the GetTextLength -CountLines is not the optimal way, better would be to use Send Message with EM-Setsel and Getsel, but as if have posted in bugreports, this does not work.

Our example works with the EditorGadget, that is the main differnence and the possibility to choose the margins with spingadgets.

Johannes
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

I still have problems with LuckyLukes code. If you try to print more then 3-4 pages it doesn't print them all. We are so close. I need this option bad.

Thanks for all of your guys help so far. I know we can get this thing working.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

@RJP Computing

I have changed the MaxLen part. Now it must work.
If hte german parts are probelm for you, I will translate them, else....

Code: Select all

;############################################ 
;Inhalt vom 
;EditorGadget auf Standard-Drucker ausgeben 
; 
;Author : Andreas 
;Juni 2003 
;ergänzt von Wichtel und Joro 
; 
;sämtliche Formatierungen die im EditorGadget 
;vorgenommen werden (Farbe, Font usw.), 
;werden auf den Drucker übernommen. 
;############################################ 
Global GadgetNr,GadgetNr_hWnd 
#Seitenrandlinks=80 
#Seitenrandrechts=81 
#Seitenrandoben=82 
#Seitenrandunten=83 

Structure textlaenge
  flags.w
  codepage.b
EndStructure
;####################################################################### 
;die 2 Procedure basieren auf El_Choni's Beispiel 
Procedure StreamFileIn_Callback(hFile, pbBuff, cb, pcb) 
ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1 
EndProcedure 

Procedure FileStreamIn(FileID.l, File.s, Gadget.l,Option.l) 
Protected File 
Protected FileID 
Protected Gadget 
Protected StreamData.EDITSTREAM 
If ReadFile(FileID, File) 
StreamData\dwCookie = UseFile(FileID) 
StreamData\dwError = #Null 
StreamData\pfnCallback = @StreamFileIn_Callback() 
SendMessage_(GadgetNr_hWnd, #EM_STREAMIN, Option, @StreamData) 
CloseFile(FileID) 
EndIf 
EndProcedure 
;####################################################################### 

;unbedingt diese Struktur benutzen 
;mit der Struktur von PB geht es nicht ! 
Structure DInfo1 
cbSize.l 
lpszDocname.l 
lpszOutput.l 
lpszDataType.l 
fwType.w 
EndStructure 


Procedure PrintWindow() 
WindowWidth = 200 
WindowHeight = 40 
If OpenWindow(10, 0, 0, WindowWidth, WindowHeight, #PB_Window_WindowCentered, "Printing") 
SetWindowPos_(WindowID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) 
CreateGadgetList(WindowID(10)) 
TextGadget(0, 10, 10, 180, 20,"Drucke Seite") 
EndIf 
EndProcedure 


Procedure EditorPrint(Dokument.s) 
  Protected DC ,a 
  lppd.PRINTDLGAPI; Struktur für die API Druckerauswahl 
  lppd\lStructsize=SizeOf(PRINTDLGAPI) 
  lppd\Flags=#PD_ALLPAGES| #PD_HIDEPRINTTOFILE | #PD_NOSELECTION | #PD_RETURNDC |#PD_PRINTSETUP 
  printdlg_(lppd); API Druckerauswahl 
   DC=lppd\hdc; hier kommt der Device Context zurück 
  mydevmode.DEVMODE 
  *Pointer.DEVMODE 
  *Pointer=GlobalLock_(lppd\hdevmode) 
  Papierlaenge=*Pointer\dmPaperlength 
  Papierbreite=*Pointer\dmPaperwidth 
  ppmm.f=(*Pointer\dmYResolution/10)/2.54 
  GlobalFree_(hdevmode) 
  cRect.RECT 
  FormatRange.FORMATRANGE 
  Docinfo.DInfo1 
  Docinfo\cbSize = SizeOf(DInfo1) 
  Docinfo\lpszDocname = @Dokument.s 
  Docinfo\lpszOutput = #Null 
  Docinfo\lpszDataType = #Null 
  Docinfo\fwType = 0 
  PrintWindow() 
  SetGadgetText(0, "Druckvorbereitung") 
  Result=StartDoc_(DC,Docinfo) 
  LastChar = 0 
  Randlinks=GetGadgetState(#Seitenrandlinks) 
  Randrechts=GetGadgetState(#Seitenrandrechts) 
  Randoben=GetGadgetState(#Seitenrandoben) 
  Randunten=GetGadgetState(#Seitenrandunten) 
  ActivateGadget(GadgetNr); stürzt ohne Activate ab und zu ab 
  lang.Textlaenge
    lang\flags=0 
    MaxLen=SendMessage_(GadgetID(GadgetNr),#EM_GETTEXTLENGTHEX ,@lang,0) 
  OldMapMode = GetMapMode_(DC) 
  SetMapMode_(DC,#MM_TWIPS) 
  OffsetX = Randlinks*ppmm.f-GetDeviceCaps_(DC,#PHYSICALOFFSETX) 
  If OffsetX < GetDeviceCaps_(DC,#PHYSICALOFFSETX):OffsetX=GetDeviceCaps_(DC,#PHYSICALOFFSETX):EndIf 
  OffsetY=-Randoben*ppmm.f+GetDeviceCaps_(DC,#PHYSICALOFFSETY) 
  If OffsetY > -GetDeviceCaps_(DC,#PHYSICALOFFSETY): OffsetY = -GetDeviceCaps_(DC,#PHYSICALOFFSETY):EndIf 
  HorzRes=((Papierbreite/10-Randrechts))*ppmm.f 
  If HorzRes > GetDeviceCaps_(DC,#HORZRES) :HorzRes=GetDeviceCaps_(DC,#HORZRES):EndIf 
  VertRes=-(Papierlaenge/10)*ppmm.f+Randunten*ppmm.f 
  If VertRes < -GetDeviceCaps_(DC,#VERTRES):VertRes=-GetDeviceCaps_(DC,#VERTRES):EndIf 
  SetRect_(cRect,OffsetX,OffsetY,HorzRes,VertRes) 
  DPtoLP_(DC,cRect,2) 
  SetMapMode_(DC,OldMapMode) 
  FormatRange\hdc = DC 
  FormatRange\hdcTarget = DC 
  FormatRange\rc\left = cRect\left 
  FormatRange\rc\top = cRect\top 
  FormatRange\rc\right = cRect\right 
  FormatRange\rc\bottom = cRect\bottom 
  FormatRange\rcPage\left = cRect\left 
  FormatRange\rcPage\top = cRect\top 
  FormatRange\rcPage\right = cRect\right 
  FormatRange\rcPage\bottom = cRect\bottom 
  a = 1 
  Repeat 
    SetGadgetText(0, "Drucke Seite : "+ Str(a)) 
    Result=StartPage_(DC) 
    FormatRange\chrg\cpMax = -1 
    LastChar = SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,#True,@FormatRange) 
    FormatRange\chrg\cpMin = LastChar 
    SendMessage_(GadgetNr_hWnd,#EM_DISPLAYBAND,0,cRect) 
    a + 1 
    EndPage_(DC) 
  Until LastChar >= MaxLen Or LastChar = -1 
  SetGadgetText(0, "Fertig") 
  CloseWindow(10) 
  EndDoc_(DC) 
  SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,0,0) 
EndProcedure  

If OpenWindow(0, 10, 10, 640, 480, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window") 
  If CreateGadgetList(WindowID()) 
  GadgetNr_hWnd=EditorGadget(1, 0, 0, WindowWidth()-100,WindowHeight()) 
  GadgetNr=1 
  ButtonGadget(2, WindowWidth()-90,10,80,24,"Drucken") 
  ButtonGadget(3, WindowWidth()-90,40,80,24,"Laden") 
  TextGadget(10,WindowWidth()-100,95, 100, 20,"Seitenränder in mm") 

  SpinGadget(#Seitenrandlinks, WindowWidth()-90,150, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandlinks,20) 
  SetGadgetText(#Seitenrandlinks,Str(GetGadgetState(#Seitenrandlinks))) 
  TextGadget(11,WindowWidth()-90,125, 80, 20,"links") 

  SpinGadget(#Seitenrandrechts, WindowWidth()-90,200, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandrechts,20) 
  SetGadgetText(#Seitenrandrechts,Str(GetGadgetState(#Seitenrandrechts))) 
  TextGadget(12,WindowWidth()-90,175, 80, 20,"rechts") 

  SpinGadget(#Seitenrandoben, WindowWidth()-90,250, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandoben,20) 
  SetGadgetText(#Seitenrandoben,Str(GetGadgetState(#Seitenrandoben))) 
  TextGadget(13,WindowWidth()-90,225, 80, 20,"oben") 

  SpinGadget(#Seitenrandunten, WindowWidth()-90,300, 50, 20, 0, 100) 
  SetGadgetState(#Seitenrandunten,20) 
  SetGadgetText(#Seitenrandunten,Str(GetGadgetState(#Seitenrandunten))) 
  TextGadget(14,WindowWidth()-90,275, 80, 20,"unten") 
  EndIf 
  Repeat 
  EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow 
    Quit = 1 
    EndIf 
    If EventID = #PB_EventGadget 
    Select EventGadgetID() 
      Case 2 
      EditorPrint(DName$) 
      Case 3 
      DName$ = OpenFileRequester("Datei laden :","*.*", "Text-Dateien | *.txt | Rich Text Files | *.rtf", 0) 
      If UCase(GetExtensionPart(DName$)) = "RTF" 
      FileStreamIn(0,DName$, 1,#SF_RTF) 
      Else 
      FileStreamIn(0,DName$, 1,#SF_TEXT) 
      EndIf 
      Case #Seitenrandlinks 
          If spinc=2 
             spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandlinks) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandlinks,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandrechts 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandrechts) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandrechts,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandoben 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandoben) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandoben,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Seitenrandunten 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Seitenrandunten) 
            spinc=spinc+1 
            SetGadgetText(#Seitenrandunten,Str(spin)) 
            WindowEvent() 
          EndIf 
    EndSelect 
    EndIf 
  Until Quit = 1 
EndIf 
End 
Johannes
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

@Joro
Can you please translate it.
I don't know any German. That would be AWSOME :!:
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

Okay, here the translation.
I hope, it is bugfree. The openfile dialog is now correct working

Code: Select all

;############################################ 
;Content
;EditorGadget print on a standard printer 
; 
;Author : Andreas 
;June 2003 
;extended by Wichtel and Joro 
; 
;all formatting in the editorgadget will be
;printed 
;############################################ 
Global GadgetNr,GadgetNr_hWnd 
#Margin_left=80 
#Margin_right=81 
#Margin_top=82 
#Margin_bottom=83 

Structure textlength
  flags.w
  codepage.b
EndStructure
;####################################################################### 
;the 2 Procedures are based on El_Choni's example
Procedure StreamFileIn_Callback(hFile, pbBuff, cb, pcb) 
ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1 
EndProcedure 

Procedure FileStreamIn(FileID.l, File.s, Gadget.l,Option.l) 
Protected File 
Protected FileID 
Protected Gadget 
Protected StreamData.EDITSTREAM 
If ReadFile(FileID, File) 
StreamData\dwCookie = UseFile(FileID) 
StreamData\dwError = #Null 
StreamData\pfnCallback = @StreamFileIn_Callback() 
SendMessage_(GadgetNr_hWnd, #EM_STREAMIN, Option, @StreamData) 
CloseFile(FileID) 
EndIf 
EndProcedure 
;####################################################################### 

;structure to set the documentproperties
Structure DInfo1 
cbSize.l 
lpszDocname.l 
lpszOutput.l 
lpszDataType.l 
fwType.w 
EndStructure 


Procedure PrintWindow() 
WindowWidth = 200 
WindowHeight = 40 
If OpenWindow(10, 0, 0, WindowWidth, WindowHeight, #PB_Window_WindowCentered, "Printing") 
SetWindowPos_(WindowID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) 
CreateGadgetList(WindowID(10)) 
TextGadget(0, 10, 10, 180, 20,"printing page") 
EndIf 
EndProcedure 


Procedure EditorPrint(document.s) 
  Protected DC ,a 
  lppd.PRINTDLGAPI; structure for the Api printer selection 
  lppd\lStructsize=SizeOf(PRINTDLGAPI) 
  lppd\flags=#PD_ALLPAGES| #PD_HIDEPRINTTOFILE | #PD_NOSELECTION | #PD_RETURNDC |#PD_PRINTSETUP 
  printdlg_(lppd);  Printerselection API  
   DC=lppd\hdc; here the device context is coming back
If DC<>-1
  mydevmode.DEVMODE 
  *Pointer.DEVMODE 
  *Pointer=GlobalLock_(lppd\hdevmode) 
  paperlength=*Pointer\dmPaperlength 
  paperwidth=*Pointer\dmPaperwidth 
  ppmm.f=(*Pointer\dmYResolution/10)/2.54 ; pixel per millimeter
  GlobalFree_(hdevmode) 
  cRect.RECT 
  FormatRange.FORMATRANGE 
  Docinfo.DInfo1 
  Docinfo\cbSize = SizeOf(DInfo1) 
  Docinfo\lpszDocname = @document.s 
  Docinfo\lpszOutput = #Null 
  Docinfo\lpszDataType = #Null 
  Docinfo\fwType = 0 
  PrintWindow() 
  SetGadgetText(0, "preparing for printing") 
  Result=StartDoc_(DC,Docinfo) 
  LastChar = 0 
  leftmargin=GetGadgetState(#Margin_left) 
  rightmargin=GetGadgetState(#Margin_right) 
  topmargin=GetGadgetState(#Margin_top) 
  bottommargin=GetGadgetState(#Margin_bottom) 
  ActivateGadget(GadgetNr); seems that it sometimes crashes without activating , you can try to leave it 
  long.textlength
    long\flags=0 
    MaxLen=SendMessage_(GadgetID(GadgetNr),#EM_GETTEXTLENGTHEX ,@long,0) 
 
  OldMapMode = GetMapMode_(DC) 
  SetMapMode_(DC,#MM_TWIPS) 
  OffsetX = leftmargin*ppmm.f-GetDeviceCaps_(DC,#PHYSICALOFFSETX) 
  If OffsetX < GetDeviceCaps_(DC,#PHYSICALOFFSETX):OffsetX=GetDeviceCaps_(DC,#PHYSICALOFFSETX):EndIf 
  OffsetY=-topmargin*ppmm.f+GetDeviceCaps_(DC,#PHYSICALOFFSETY) 
  If OffsetY > -GetDeviceCaps_(DC,#PHYSICALOFFSETY): OffsetY = -GetDeviceCaps_(DC,#PHYSICALOFFSETY):EndIf 
  HorzRes=((paperwidth/10-rightmargin))*ppmm.f 
  If HorzRes > GetDeviceCaps_(DC,#HORZRES) :HorzRes=GetDeviceCaps_(DC,#HORZRES):EndIf 
  VertRes=-(paperlength/10)*ppmm.f+bottommargin*ppmm.f 
  If VertRes < -GetDeviceCaps_(DC,#VERTRES):VertRes=-GetDeviceCaps_(DC,#VERTRES):EndIf 
  SetRect_(cRect,OffsetX,OffsetY,HorzRes,VertRes) 
  DPtoLP_(DC,cRect,2) 
  SetMapMode_(DC,OldMapMode) 
  FormatRange\hdc = DC 
  FormatRange\hdcTarget = DC 
  FormatRange\rc\left = cRect\left 
  FormatRange\rc\top = cRect\top 
  FormatRange\rc\right = cRect\right 
  FormatRange\rc\bottom = cRect\bottom 
  FormatRange\rcPage\left = cRect\left 
  FormatRange\rcPage\top = cRect\top 
  FormatRange\rcPage\right = cRect\right 
  FormatRange\rcPage\bottom = cRect\bottom 
  a = 1 
  Repeat 
    SetGadgetText(0, "Printing page : "+ Str(a)) 
    Result=StartPage_(DC) 
    FormatRange\chrg\cpMax = -1 
    LastChar = SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,#True,@FormatRange) 
    FormatRange\chrg\cpMin = LastChar 
    SendMessage_(GadgetNr_hWnd,#EM_DISPLAYBAND,0,cRect) 
    a + 1 
    EndPage_(DC) 
  Until LastChar >= MaxLen Or LastChar = -1 
  SetGadgetText(0, "Fertig") 
  CloseWindow(10) 
  EndDoc_(DC) 
  SendMessage_(GadgetNr_hWnd,#EM_FORMATRANGE,0,0) 
EndIf
EndProcedure  

If OpenWindow(0, 10, 10, 640, 480, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window") 
  If CreateGadgetList(WindowID()) 
  GadgetNr_hWnd=EditorGadget(1, 0, 0, WindowWidth()-100,WindowHeight()) 
  GadgetNr=1 
  ButtonGadget(2, WindowWidth()-90,10,80,24,"Print") 
  ButtonGadget(3, WindowWidth()-90,40,80,24,"Open document") 
  TextGadget(10,WindowWidth()-100,95, 100, 20,"margin in mm") 

  SpinGadget(#Margin_left, WindowWidth()-90,150, 50, 20, 0, 100) 
  SetGadgetState(#Margin_left,20) 
  SetGadgetText(#Margin_left,Str(GetGadgetState(#Margin_left))) 
  TextGadget(11,WindowWidth()-90,125, 80, 20,"left") 

  SpinGadget(#Margin_right, WindowWidth()-90,200, 50, 20, 0, 100) 
  SetGadgetState(#Margin_right,20) 
  SetGadgetText(#Margin_right,Str(GetGadgetState(#Margin_right))) 
  TextGadget(12,WindowWidth()-90,175, 80, 20,"right") 

  SpinGadget(#Margin_top, WindowWidth()-90,250, 50, 20, 0, 100) 
  SetGadgetState(#Margin_top,20) 
  SetGadgetText(#Margin_top,Str(GetGadgetState(#Margin_top))) 
  TextGadget(13,WindowWidth()-90,225, 80, 20,"top") 

  SpinGadget(#Margin_bottom, WindowWidth()-90,300, 50, 20, 0, 100) 
  SetGadgetState(#Margin_bottom,20) 
  SetGadgetText(#Margin_bottom,Str(GetGadgetState(#Margin_bottom))) 
  TextGadget(14,WindowWidth()-90,275, 80, 20,"bottom") 
  EndIf 
  Repeat 
  EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow 
    Quit = 1 
    EndIf 
    If EventID = #PB_EventGadget 
    Select EventGadgetID() 
      Case 2 
      EditorPrint(DName$) 
      Case 3 
      DName$ = OpenFileRequester("Open File :","*.txt", "Text-Files ( *.txt) | *.txt | Rich Text Files  (*.rtf)|*.rtf", 0) 
      If UCase(GetExtensionPart(DName$)) = "RTF" 
      FileStreamIn(0,DName$, 1,#SF_RTF) 
      Else 
      FileStreamIn(0,DName$, 1,#SF_TEXT) 
      EndIf 
      Case #Margin_left 
          If spinc=2 
             spinc=0 
          Else 
            spin=GetGadgetState(#Margin_left) 
            spinc=spinc+1 
            SetGadgetText(#Margin_left,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Margin_right 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Margin_right) 
            spinc=spinc+1 
            SetGadgetText(#Margin_right,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Margin_top 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Margin_top) 
            spinc=spinc+1 
            SetGadgetText(#Margin_top,Str(spin)) 
            WindowEvent() 
          EndIf 
        Case #Margin_bottom 
          If spinc=2 
            spinc=0 
          Else 
            spin=GetGadgetState(#Margin_bottom) 
            spinc=spinc+1 
            SetGadgetText(#Margin_bottom,Str(spin)) 
            WindowEvent() 
          EndIf 
    EndSelect 
    EndIf 
  Until Quit = 1 
EndIf 
End 

Johannes
Post Reply