• Log in or sign up for an account here: https://www.sythe.org/login

Best place to see examples on how to use Win32 API function in delphi

Kar Na Vor

Member
Joined
May 25, 2013
Sythe Gold
0
Messages
26
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----

Code:
begin
   SetConsoleTextAttribute(GetStdHandle(
                          STD_OUTPUT_HANDLE),
                          FOREGROUND_RED OR
                          BACKGROUND_BLUE);

  Writeln('Red text on a blue background !');
  ReadLn;
end.

----------End working code---------------------

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

Code:
BOOL SetConsoleTextAttribute(

    HANDLE hConsoleOutput,  // handle of console screen buffer  
    WORD wAttributes    // text and background colors 
   );

Code:
Parameters

hConsoleOutput

Identifies a console screen buffer. The handle must have GENERIC_READ access.

wAttributes

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:

FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
------End Delphi help------

Can someone please tell me what cylinder in my head is not firing on this?
 
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
There are two arguments for the console text function you have there, one is the window handle and one is the color. The window handle is basically just a window ID, so that we can find and manipulate the console window. The colors are, well, colors, and by introducing OR, you can put two arguments in one (setting the foreground color and background color at once).


For experimenting with the API, your function calls will be the same in C++ as they are in Delphi. Most Win32 calls use constants which are really just numbers, so you won't often have to worry about type conversions.
 
Runescape Gamblingrunescape gambling
Back
Top