Announcement

Collapse
No announcement yet.

I know I have seen this... How do you "print to a form?"

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • I know I have seen this... How do you "print to a form?"

    No controls - just put some text on a form like PRINT in PBCC - I a sure I have seen this recently...

  • #2
    I suppose you could draw the text (everything is graphics) directly on the dialog, but it would be a lot more complicated than adding a text control. Pray tell, the reason and/or goal?
    "Not my circus, not my monkeys."

    Comment


    • #3
      No good reason Eric - just thought I had seen it some place. And I remember thinking "holy cow look at that!"

      Comment


      • #4
        In PBCC PRINT "prints" on the console.

        So maybe you want something in PBWin? Like TXT.PRINT on a TXT.WINDOW?

        Cheers,
        Dale

        Comment


        • #5
          Code:
          PBCC6 program
          FUNCTION PBMAIN
          
          LOCAL hWin AS LONG
          
          GRAPHIC WINDOW NEW "Printed to a window", 100,100,800,600 TO hWin
          GRAPHIC ATTACH hWin,0
          
          GRAPHIC PRINT "Hello"
          GRAPHIC PRINT "This is printing to a graphic window.
          GRAPHIC PRINT "Is this what you were after?"
          
          
          WAITKEY$
          END FUNCTION

          Comment


          • #6
            Doesn't the Win32 API function TextOut() do this? When you tell it where to write the text, you can specify the handle to the form (or its DC). https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
            Dan

            Comment


            • #7
              TextOut() example..
              Code:
              #Compile Exe
              #Include "WIN32API.INC"
              
              Global XX&, YY&
              '------------------/
              
              Function PBMain () As Long
               Local hDlg As Dword, X, Y As Long
                XX = 200 : YY = 150
                Dialog New 0, "TextOut() test", , , XX, YY, %WS_Caption Or %WS_SysMenu, 0 To hDlg
                  ' Naked Dialog
                Dialog Show Modal hDlg, Call DlgProc
              
              End Function
              '------------------/PBMain
              
              CallBack Function DlgProc() As Long
               Local hDC As Long
                Select Case CbMsg
                  Case %WM_InitDialog
              
                  Case %WM_Paint
                   Local Ps As PAINTSTRUCT
                    hDC = BeginPaint(CbHndl, Ps)
                      ShowText(hDC)                   ' Place text on dialog's background
                    EndPaint CbHndl, PS
              
                  Case %WM_Command
                    Select Case CbCtl
                      Case %IdCancel
                        Dialog End CbHndl, CbCtl
                    End Select
              
                End Select
              End Function
              '------------------/
              
               ' TT Erik Christensen's sample code
              Sub SetText(ByVal hDC As Long, ByVal TextStr As String, X As Long, Y As Long, TxCol As Long)
               Local lpsz As AsciiZ * 255
               Local tm As TEXTMETRIC
              
                  SetTextAlign(hDC, %TA_CENTER)  '%TA_LEFT '
                  SetTextColor(hDC, TxCol)
                  SetBkColor(hDC, GetSysColor(%COLOR_3DFACE))
                  GetTextMetrics(hDC, tm)
              
                  lpsz=TextStr
                  TextOut hDC, X, Y, lpsz, ByVal Len(lpsz)
                  ' Go one line down
                  Y = Y + tm.tmHeight
              End Sub
              '------------------/SetText
              
              Sub ShowText(hDC As Long)
               Local X, Y As Long
                X = XX*1.5/2 : Y = YY/2
                Call SetText(hDC,"TextOut", X, Y, RGB(225,0,0))
                Call SetText(hDC,"Demonstration", X, Y, RGB(0,164,0))
                Call SetText(hDC,"In Colour!",X ,Y, RGB(0,0,255))
              End Sub
              '------------------/ShowText
              Rgds, Dave

              Comment

              Working...
              X