2 Replies - 517 Views - Last Post: 28 May 2013 - 09:29 AM Rate Topic: -----

#1 DatSik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-September 12

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

Posted 28 May 2013 - 09:06 AM

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----

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-----

BOOL SetConsoleTextAttribute(

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


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?

Is This A Good Question/Topic? 0
  • +

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

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3823
  • View blog
  • Posts: 13,548
  • Joined: 12-December 12

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

Posted 28 May 2013 - 09:23 AM

I assume GetStdHandle(STD_OUTPUT_HANDLE) will occur a lot and is just a (semi-)standard way of referring to the Console window. This is supplied as the parameter hConsoleOutput.

The help for the other parameter wAttributes seems fairly clear. So

FOREGROUND_RED OR BACKGROUND_BLUE

specifies a red text on a blue background. But, as these are binary values, you could use the binary (or) operator | instead, rather than the word OR. Edited: Actually, is | an operator in Delphi??

You might work through some of the articles, and examples, here at delphi wikia. I don't use Delphi so I don't know of an introductory tutorial to recommend.

This post has been edited by andrewsw: 28 May 2013 - 09:27 AM

Was This Post Helpful? 2
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3823
  • View blog
  • Posts: 13,548
  • Joined: 12-December 12

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

Posted 28 May 2013 - 09:29 AM

The pipe | is the bit-wise OR operator in C. You have to replace this with the word OR in your Delphi code.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1