SRL Archive - General

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


DatSik

2013-05-28 12:12:19

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?

Brandon

2013-05-28 12:49:16

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


Other than this line, what exactly is the question/problem :S
I don't see a question here..

Also, that word your looking for is interoperability OR P/Invoke.


http://www.blong.com/Conferences/BorConUK97/WinAPI/Api.htm
http://www.blong.com/Articles/DotNetInteropD8/Interop1/Win32AndDotNetInterop.htm


Here's some sample translations:



HWND FindWindow(LPTCSTR Class, LPTCSTR WindowTitle);
HWND SetParent(HWND Child, HWND Parent);
bool SetWindowPos(HWND Handle, HWND HandleAfter, int x, int y, int cx, int cy, uint32_t Flags);


Function FindWindow(Class, WindowTitle: PChar): HWND;
Function SetParent(Child, Parent: HWND): HWND;
Function SetWindowPos(Handle, HandleAfter: HWND; X, Y, CX, CY: Integer; Flags: Word) : Boolean;

DatSik

2013-05-28 13:27:14

From: Brandon
Other than this line, what exactly is the question/problem :S
I don't see a question here..

Also, that word your looking for is interoperability OR P/Invoke.


http://www.blong.com/Conferences/BorConUK97/WinAPI/Api.htm
http://www.blong.com/Articles/DotNetInteropD8/Interop1/Win32AndDotNetInterop.htm


Here's some sample translations:



HWND FindWindow(LPTCSTR Class, LPTCSTR WindowTitle);
HWND SetParent(HWND Child, HWND Parent);
bool SetWindowPos(HWND Handle, HWND HandleAfter, int x, int y, int cx, int cy, uint32_t Flags);


Function FindWindow(Class, WindowTitle: PChar): HWND;
Function SetParent(Child, Parent: HWND): HWND;
Function SetWindowPos(Handle, HandleAfter: HWND; X, Y, CX, CY: Integer; Flags: Word) : Boolean;


You said you dont see a question here lol … i forgot the question mark in my thread title… thats my question.

To put it roughly i want to know where i can find out how to use winapi's in delphi.. with solid delphi examples. The MSDN only shows c++ examples.

Thank you for your post! it was helpful. now lets see if you can help me now

Brandon

2013-05-28 14:21:47

From: DatSik
You said you dont see a question here lol … i forgot the question mark in my thread title… thats my question.

To put it roughly i want to know where i can find out how to use winapi's in delphi.. with solid delphi examples. The MSDN only shows c++ examples.

Thank you for your post! it was helpful. now lets see if you can help me now



You mean you want me to find you a DephiWinapi Documentation link that most likely doesn't exist?


1. You're using C API's in Delphi which does work but you can't expect to find full fledge docs dedicated to C examples in Delphi. The most you'll find is calling some C functions in delphi or a blog with some examples.

2. Delphi/Pascal is pretty damn old and barely used and fairly similar.. TBH, this site and Scar-Divi is the only places I've seen it being used.

3. When learning to call API's from another language in the one you want, you need to learn the calling convention (stdcall, cdecl, etc) and from there on, the syntax should be easy to come up with.


Now I can write you examples but that's beside the point. You want WINAPI websites for Delphi and you will have quite a hard time finding them. It's already pretty hard learning it in C++ (when just starting out)..

StackOverflow is just about one of the best programming sites for any language and I believe that would be roughly the most you'd find. Ex: http://stackoverflow.com/questions/tagged/delphi+delphi-2010

If you find a site that shows you the examples in pascal, translating to delphi is moot.


The most I can do is guide you or write you up very basic examples (I no longer have FPC or any delphi/pascal compilers) so what I write will be from memory or translation.


Tell me what you want to do first or what code you're having a problem with and I can help you from there.