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; I had the code before, but I somehow lost it. How do I use TextOut?...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question TextOut(How do I use it)?

    I had the code before, but I somehow lost it. How do I use TextOut?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hi,

    BOOL TextOut(
    HDC hdc, // handle to device context
    int nXStart, // x-coordinate of starting position
    int nYStart, // y-coordinate of starting position
    LPCTSTR lpString, // pointer to string
    int cbString // number of characters in string
    );


    Eg:

    TextOut(hdc, 10, 10, "Printing Text", 13);

    Hope That Helps...

    Cheers
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Arg!!! You got to it before me TNT. I'm new to Windows programming (1 week to be exact) and I actaully had the answer to it. Oh well, at least I know I know it.

    WINDOWS PROGRAMMING IS GREAT!!!

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post There's one problem when I run it now

    Well, I tried:

    HDC hdc;

    TextOut(hdc,10,10,"Hi",2);

    but no text shows up.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    forgot to assign hdc to something

    hdc = GetDC(hwnd);

  6. #6
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post Still got..

    I tried:

    HDC hdc;

    hdc = GetDC(hwnd);

    TextOut(hdc,10,10,"Hi",2);

    but it didn't show up.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    KEN is right, you forgot to assign the HDC to something. You could do what KEN said:
    [code]
    HDC hdc;
    hdc = GetDC(hwnd);

    TextOut(hdc, 10, 10, TEXT("TEST"), 4);

    ReleaseDC(hwnd, hdc); // don't forget to release the HDC
    [code]
    Or you could use another set of functions known as BeginPaint and EndPaint:
    Code:
    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps); // where ps is defined PAINTSTRUCT
    
    TextOut(hdc, 10, 10, TEXT("TEST"), 4);
    
    EndPaint(hwnd, &ps);
    return 0;
    So, there are a couple of ways. You would normally use BeginPaint and EndPaint inside the WM_PAINT message. And then GetDC and ReleaseDC outside of it.

    --Garfield

    How's that for just one week of learning Windows Programming
    1978 Silver Anniversary Corvette

  8. #8
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    then try...

    PAINTSTRUCT ps;
    HDC hdc;

    hdc = BeginPaint(hwnd, &ps);
    TextOut(hdc,10,10,"Hi",2);
    EndPaint(hwnd, &ps);

    Ack! Garfield beat me to it while I was replying...damn you, garfield!

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >
    I tried:

    HDC hdc;

    hdc = GetDC(hwnd);

    TextOut(hdc,10,10,"Hi",2);

    but it didn't show up.
    <

    Maybe you need to release the HDC (ReleaseDC(hwnd)). I don't know if that's the problem though. By the way, I'll have to check the parameters for ReleaseDC, it doesn't look right.

    --Garfield
    1978 Silver Anniversary Corvette

  10. #10
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    KEN, am I on the right track? After all, I'm really new to Windows programming. Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  11. #11
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    sure, but I dunno if releasing the DC would do much to stop the text from showing up...

  12. #12
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeh, I didn't think it would cause the text not to appear. Maybe it is the rest of his code. And, KEN, do I have the parameters right for ReleaseDC? Thanks.

    --Garfield

    (Wow, 10 posts in 9 minutes. That has to be a record)
    1978 Silver Anniversary Corvette

  13. #13
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Oh, and garfield I can't send large PMs, so in response to you PM...

    Here's how I want you to think of a message from now on (and if you look at the struct MSG I'm not far off)


    Windows Messages:
    PHP Code:
    WPARAM                            LPARAM
    ------------------------------------------------------
    |                              |                     |
    |                              |                     |
    |         
    HIWORD               |   HIWORD            |
    |                              |                     |
    |                              |                     |
    | ---------------------------------------------------|
    |                              |                     |
    |                              |                     |
    |                              |                     |
    |           
    LOWORD             |  LOWORD             |
    |                              |                     |
    |                              |                     |
    ------------------------------------------------------ 
    Kinda gettin the picture? Every time a message is sent to windows, the WPARAM is to the main window, and LPARAM is a message to any child window, etc. The Hiword and loword contain additional data such as coordinates.
    Last edited by -KEN-; 11-02-2001 at 04:00 PM.

  14. #14
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, so LPARAM and WPARAM are just additional information of the MSG? And HIWORD and LOWARD are different ways to get at the different information? Thanks. I guess I understand.

    --Garfield
    1978 Silver Anniversary Corvette

  15. #15
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    whoo. I got my graph working right...

Page 1 of 2 12 LastLast
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