CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013

    Best place to see examples of WinAPI examples for Delphi

    well i have been experimenting with the Win32 API in Delphi and I'm unsure on where to look on examples to use them..seeing how the MSDN only show's C++ examples.

    I have dug through Delphi 7's help file and well... im a little confused so i will just paste my working code i found and the code the help files shows me, i dont understand how it translates into my working code...unless the code im using is some how butchered up.

    so here is the code im experimenting with now using the SetConsoleTextAttribute function

    ----My code that i know works and changes color----

                              FOREGROUND_RED OR
      Writeln('Red text on a blue background !');
    ----------End working code---------------------

    --------Now here is a snip from the official delphi documentation-----

    BOOL SetConsoleTextAttribute(
        HANDLE hConsoleOutput,  // handle of console screen buffer  
        WORD wAttributes    // text and background colors 
    Identifies a console screen buffer. The handle must have GENERIC_READ access.
    Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:
    ------End Delphi help------

    Can someone please tell me what cylinder in my head is not firing on this?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Best place to see examples of WinAPI examples for Delphi

    Your code matches the official delphi documentation. The first parameter to SetConsoleTextAttribute is a handle to the console screen buffer. This is what GetStdHandle(STD_OUTPUT_HANDLE) provides - a handle to the standard output. The second parameter to SetConsoleTextAttribute is the character attributes. In your case you are setting the foreground red and the background blue by or'ing the two values.

    If you are using many of the console functions in one program, normally you would obtain the output handle only once, store this in a variable and then use this variable whenever the documentation requires a handle to console output.
    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++17 Compiler: Microsoft VS2017 (15.7.4)

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.