CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] [Code Blocks] - how add\use TextOut()?

    i'm trying use the TextOut() function. but i see 2 problems:
    1 - how can i had the libgdi32.a by code?
    2 - if i link the library, why i can't see the text?


    Code:
    #include <iostream>
    #include <string.h>
    #include <windows.h>
    //#include <WinGdi.h>
    
    
    using namespace std;
    
    int main()
    {
        //TextBlink("hello world", 10,20,3,5);
        HDC hDC=GetDC(GetConsoleWindow());
        SetTextColor(hDC,6);
        TextOut(hDC,1,5,"hello world",strlen("hello world"));
        cin.get();
    }
    can anyone advice me?

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [Code Blocks] - how add\use TextOut()?

    Consoles have their own way of displaying text/setting colours etc.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [Code Blocks] - how add\use TextOut()?

    Quote Originally Posted by 2kaud View Post
    Consoles have their own way of displaying text/setting colours etc.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    my problem was in these line:
    Code:
    strlen("hello world")
    i correct that line in these way:
    Code:
    strlen("hello world")+1
    now the text it's showed

    readers: these code works, but don't forget that if, on your compiler, the text isn't showed then add '+1' or delete. seems that works without it on VC++, but not on mingw32 compiler. so test it for see if the text is printed... thanks

    i have another question: with linker options, i can add the libgdi32.a for use the graphic functions. my question is: how can i add these library by code?
    Last edited by Cambalinho; November 1st, 2013 at 03:03 PM.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [Code Blocks] - how add\use TextOut()?

    TextOut takes as a fifth parameter the actual number of characters to output. So for "Hello World" this number is 11. If you make it 12 you also output the c string terminating null which is not what you want. If it only works for strlen() + 1, then there is another issue. If the number to output is less than 11 in this example, say 5, then just Hello would be output. If nothing is output that is a different problem.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [Code Blocks] - how add\use TextOut()?

    Quote Originally Posted by 2kaud View Post
    TextOut takes as a fifth parameter the actual number of characters to output. So for "Hello World" this number is 11. If you make it 12 you also output the c string terminating null which is not what you want. If it only works for strlen() + 1, then there is another issue. If the number to output is less than 11 in this example, say 5, then just Hello would be output. If nothing is output that is a different problem.
    but i continue with same problem: how can i add the libgdi32.a by code?
    (#pragma comment(lib,"") isn't portable)

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [Code Blocks] - how add\use TextOut()?

    with linker options, i can add the libgdi32.a for use the graphic functions. my question is: how can i add these library by code?
    Your compiler suite doesn't come with documentation? Every system comes with documentation concerning how to link to an external library.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [Code Blocks] - how add\use TextOut()?

    Quote Originally Posted by Paul McKenzie View Post
    Your compiler suite doesn't come with documentation? Every system comes with documentation concerning how to link to an external library.

    Regards,

    Paul McKenzie
    i know do it with IDE(linker options). but i can't find the mingw documention for these. only by comands(line commands) i can add it to the link, but not using the language code

  8. #8
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [Code Blocks] - how add\use TextOut()?

    Quote Originally Posted by Cambalinho View Post
    i know do it with IDE(linker options). but i can't find the mingw documention for these. only by comands(line commands) i can add it to the link, but not using the language code
    There is no "language code". The linker is separate from the compiler.

    The way you specify what to link is not part of the C++ language. It is solely up to the environment as to how to add libraries.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [Code Blocks] - how add\use TextOut()?

    Quote Originally Posted by Paul McKenzie View Post
    There is no "language code". The linker is separate from the compiler.

    The way you specify what to link is not part of the C++ language. It is solely up to the environment as to how to add libraries.

    Regards,

    Paul McKenzie
    understood.. thanks for all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured