Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I output text to my main SDI window ?

How do I output text to my main SDI window ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
17 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    How about TextOut()?


    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

    G Offline
    G Offline
    glweid
    wrote on last edited by
    #6

    David Any example of using TextOut() ? Thanks !

    D 1 Reply Last reply
    0
    • G glweid

      David Any example of using TextOut() ? Thanks !

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #7

      The documentation is pretty self-explanatory. Here's another example.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      G 1 Reply Last reply
      0
      • D David Crow

        The documentation is pretty self-explanatory. Here's another example.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        G Offline
        G Offline
        glweid
        wrote on last edited by
        #8

        How do you set the hdc ?

        D 1 Reply Last reply
        0
        • G glweid

          How do you set the hdc ?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #9

          You don't. It's passed as a parameter to the OnDraw() method.

          void CMyView::OnDraw( CDC *pDC )
          {
          pDC->TextOut(...);
          }


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          G 1 Reply Last reply
          0
          • D David Crow

            You don't. It's passed as a parameter to the OnDraw() method.

            void CMyView::OnDraw( CDC *pDC )
            {
            pDC->TextOut(...);
            }


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            G Offline
            G Offline
            glweid
            wrote on last edited by
            #10

            Thanks for the info but I'm getting confused. I have a have a ClientSocket::OnReceive() method that reads a CString from a socket(). I want to print this CString directly to my SDI (CView) window. Do I call OnDraw() from this method ?? Thanks again !

            D R 2 Replies Last reply
            0
            • G glweid

              Thanks for the info but I'm getting confused. I have a have a ClientSocket::OnReceive() method that reads a CString from a socket(). I want to print this CString directly to my SDI (CView) window. Do I call OnDraw() from this method ?? Thanks again !

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #11

              You never call OnDraw() manually. It is called by the framework when drawing needs to take place. At this point, the framework is basically asking, "What do you want to draw?". It might be wise to read up on the relationship between the document and the view. In a nutshell, the document holds the data that the view renders, or to put it another way, the view renders the data that the document holds. So, when you receive data via a socket, the document needs to be updated with the received data. The document, in turn, tells the view that something has changed and that a redraw is needed.


              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

              1 Reply Last reply
              0
              • G glweid

                Thanks for the info but I'm getting confused. I have a have a ClientSocket::OnReceive() method that reads a CString from a socket(). I want to print this CString directly to my SDI (CView) window. Do I call OnDraw() from this method ?? Thanks again !

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #12

                Derive your view from CEditView.  Then, each time you want to append a line of text to the view, do this:

                CString strTextReadBySocket = ...;
                CString strText;
                myEditView.GetEditCtrl().GetWindowText (strText);
                strText += _T("\r\n") + strTextReadBySocket;
                myEditView.GetEditCtrl().SetWindowText (strText);

                /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                G A 2 Replies Last reply
                0
                • R Ravi Bhavnani

                  Derive your view from CEditView.  Then, each time you want to append a line of text to the view, do this:

                  CString strTextReadBySocket = ...;
                  CString strText;
                  myEditView.GetEditCtrl().GetWindowText (strText);
                  strText += _T("\r\n") + strTextReadBySocket;
                  myEditView.GetEditCtrl().SetWindowText (strText);

                  /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                  G Offline
                  G Offline
                  glweid
                  wrote on last edited by
                  #13

                  Ravi Thanks, this works but after a while of printing text to the window I get an Out of memory errors. Is there a limit to how much data can be written to the window ?? Thanks Gary

                  G 1 Reply Last reply
                  0
                  • G glweid

                    Ravi Thanks, this works but after a while of printing text to the window I get an Out of memory errors. Is there a limit to how much data can be written to the window ?? Thanks Gary

                    G Offline
                    G Offline
                    glweid
                    wrote on last edited by
                    #14

                    I increased by buffer size to 4096 when receiving data and the memory errors are gone. How can I get the cursor to stay at the bottom of the window ?? Thanks Gary

                    R 2 Replies Last reply
                    0
                    • G glweid

                      I increased by buffer size to 4096 when receiving data and the memory errors are gone. How can I get the cursor to stay at the bottom of the window ?? Thanks Gary

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #15

                      Gary, you might find it convenient to use a CFormView instead of a CEditView and use my History Edit Control[^] class. Also, Joseph Newcomer has written an excellent Logging List Control[^] class. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                      1 Reply Last reply
                      0
                      • R Ravi Bhavnani

                        Derive your view from CEditView.  Then, each time you want to append a line of text to the view, do this:

                        CString strTextReadBySocket = ...;
                        CString strText;
                        myEditView.GetEditCtrl().GetWindowText (strText);
                        strText += _T("\r\n") + strTextReadBySocket;
                        myEditView.GetEditCtrl().SetWindowText (strText);

                        /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                        A Offline
                        A Offline
                        axid3j1al
                        wrote on last edited by
                        #16

                        I am trying to subclass a CEditView in an sdi app and am having a few problems. Basically I have the above SetWindowText statment in a class which extends from CEdit. Now If I create a CEdit control at resource time and put it on a dialog and then call SubclassDlgItem everything is ok. However I would would really like to mimic the Visual Studio Output Window. What I did was to try and call SubClassWindow in my CEditView derived SDI view in the OnCreate Handler. However this fails and I read I need to Call SubClassDlgItem for the CEdit Dialog obtained by GetEditCtrl() which is defined in the CView. However how do I work out the resource id of the CEdit which is created in the CEditView? I guess if I Create a CEdit control dynamically on a CFormView I would know the resource ID. Basically I am trying to get a general debugging routine which I can attach to any CEdit or CEditView (Which is dynamically created). I would prefer this than a log window which is a separate window from my application. Regards, Axe,

                        1 Reply Last reply
                        0
                        • G glweid

                          I increased by buffer size to 4096 when receiving data and the memory errors are gone. How can I get the cursor to stay at the bottom of the window ?? Thanks Gary

                          R Offline
                          R Offline
                          Ravi Bhavnani
                          wrote on last edited by
                          #17

                          // Scroll the edit view to the bottom
                          myEditView.LineScroll (myEditView.GetLineCount(), 0);

                          /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups