TextOut(How do I use it)?

This is a discussion on TextOut(How do I use it)? within the Windows Programming forums, part of the Platform Specific Boards category; Nono, he msg is only composed of WPARAM and LPARAM. Those are the only two pieces of info in there, ...

  1. #16
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Nono, he msg is only composed of WPARAM and LPARAM. Those are the only two pieces of info in there, and the HIWORD and LOWORD are ways to get at different parts of them.

  2. #17
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Oh, I see. Your graph couldn't have been better.

    --Garfield
    1978 Silver Anniversary Corvette

  3. #18
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Back to the subject. SyntaxBubble, post your code or attach the file. Then we can look at it fully.

    --Garfield the Great
    1978 Silver Anniversary Corvette

  4. #19
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    Hi,

    I am trying to get a multi-line string (m_Poem) to print out -- how do you get the Textout to acknowledge the carriage returns, instead of printing them out as little boxes? Or is there a better function to use? This is Visual C++, btw.

    if (dcPrint.StartDoc(&myPrintjob)>=0)
    {
    dcPrint.StartPage();

    dcPrint.TextOut(10,10,m_Poem);

    dcPrint.EndPage();

    dcPrint.EndDoc();

    dcPrint.DeleteDC();
    }

  5. #20
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Try this.

    First find out how big the font prints out with

    GetTextExtentPoint32(hdcPrinter, sBuffer, lstrlen(sBuffer), &Size);

    the Size struct will be stacked with values

    Size.cx is the length of the string across
    Size.cy is the height of the text


    You will need a loop for each line of the poem

    After each line increment the Y Cood by the Size.cy

    Size.cx can be used to justify text
    ie
    (Width-Size.cx)/2 == Center
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #21
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Or is there a better function to use? <<

    Or you could always try DrawText:
    Code:
    case WM_PAINT:
      {
      PAINTSTRUCT ps;
      BeginPaint(hwnd,&ps);
        TCHAR chTxt[]=TEXT("Said the apple to the orange,\n")
                      TEXT("Oh, I wanted you to come\n")
                      TEXT("Close to me and kiss me to the core.\n")
                      TEXT("Then you might know me like no other orange\n")
                      TEXT("Has ever done\n")
                      TEXT("Before");
        RECT rc;
        GetClientRect(hwnd,&rc);
        InflateRect(&rc,-30,-30);
        SetBkMode(ps.hdc,TRANSPARENT);
        DrawText(ps.hdc, chTxt, lstrlen(chTxt), &rc, DT_WORDBREAK);
      EndPaint(hwnd,&ps);
      return 0;
      }
    (Words 'borrowed' from Al Stewart's - a small fruit song). Hope that helps.

    edit: format
    Note: If you use mingw compiler(gcc v3.2) then multi-line text is deprecated. Just use one TEXT macro to enclose the whole of the text which can still occupy multiple lines rather than one usage per line of text.
    Last edited by Ken Fitlike; 12-13-2002 at 12:07 AM.

  7. #22
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    Thanks. I was trying to do an example from a book and replace their text string with a variable. It prints out, but it's all on one line, LOL. I was thinking I'd have to loop, but my VC++ MSDN file is corrupted for some reason (probably because I had installed VB.net, then removed it after I got mad at it for not having a decent packager like the old one), & I couldn't find the string length function in the book.

    Anyway, what I really wanted to do was build sort of like an e-book. So I wanted to print out using a string variable, which would vary in length, depending on the poem that the user selects. What I need to do is loop through a string, and look for a specific character (\r\n) & use that as the string length, then go on to the next part of the string, & so on. There has to be a way to do this in C++, I've done it in Cold Fusion.

    This is the whole code for the printing function.
    void CPoetryDlg::OnPrint()
    {
    // TODO: Add your control notification handler code here
    //Construct a CPrint Dialog object
    CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
    if (dlgPrint.DoModal()==IDOK)
    {

    //Attach printer DC from dialog to a CDC object
    CDC dcPrint;
    dcPrint.Attach(dlgPrint.GetPrinterDC());

    //Create and fill a Docinfo structure
    DOCINFO myPrintjob;
    myPrintjob.cbSize=sizeof(myPrintjob);
    myPrintjob.lpszDocName="myPrintjob";
    myPrintjob.lpszOutput=NULL;
    myPrintjob.lpszDatatype=NULL;
    myPrintjob.fwType=NULL;

    //Start printing document
    if (dcPrint.StartDoc(&myPrintjob)>=0)
    {
    dcPrint.StartPage();
    dcPrint.TextOut(10,10,m_Poem);
    dcPrint.EndPage();
    dcPrint.EndDoc();
    dcPrint.DeleteDC();
    }
    }

    }

    Argh! Why is this board completely ignoring my formattting?

    Anyway...is there a good, advanced, free printing tutorial online that would cover this? I can't afford to buy another $40 programming book at the moment.
    Last edited by emilyh; 12-13-2002 at 05:35 AM.

  8. #23
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Then you really should use DrawText(), it will take care of that for you. But novacains idea is basically what I use for printing, and in fact you can wrap these up into functions quite easily. SetTextAlign() is helpful too, and be sure to set the BackMode to TRANSPARENT if the background is colored.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #24
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    Thanks for the help.

  10. #25
    Registered User
    Join Date
    Jul 2009
    Posts
    1
    I know this is a very old thread, but it's where I found the answer to my issue but it raises a question for me.

    Why does this work (specifically the part IDM_FILE_NEW)

    Code:
    switch (wmId) {
            case IDM_FILE_EXIT:
              DestroyWindow(hWnd);
              break;
            case IDM_FILE_NEW:
              hdc = GetDC(hWnd);
              TextOut(hdc, 5, 5, greeting1, _tcslen(greeting1));
              ReleaseDC(hWnd, hdc);
              break;
            case IDM_ABOUT:
              DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
              break;
            default:
              return DefWindowProc(hWnd, message, wParam, lParam);
          }
    but the following has no effect at all.
    Code:
    switch (wmId) {
            case IDM_FILE_EXIT:
              DestroyWindow(hWnd);
              break;
            case IDM_FILE_NEW:
              hdc = BeginPaint(hWnd, &ps);
              TextOut(hdc, 5, 5, greeting1, _tcslen(greeting1));
              EndPaint(hWnd, &ps);
              break;
            case IDM_ABOUT:
              DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
              break;
            default:
              return DefWindowProc(hWnd, message, wParam, lParam);
          }
    do the BeginPaint, and EndPaint functions only work in the context of

    Code:
    case WM_PAINT:
    ...
    break;
    because that doesn't make sense to me.

  11. #26
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Holy Thread Necrophillia!

    Yes, BeginPaint() can only be called in response to a WM_PAINT msg.
    It is not valid to call it from within any other msg.

    Also the HDC, rect, etc from the BeginPaint will only be valid if there has been a call to InvalidateRect() (which sets the area requiring a redraw).

    I suggest putting abreak point in and looking at the values returned.



    Please start a new thread next time...

    EDIT: seven years and I am still answering the same question....
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21