[fpc-pascal]Re: Obtaining Windows API handle of a new console. (Marco van de Voort)
Sergey Kosarevsky
kosarevsky at chat.ru
Sat Apr 21 18:23:09 CEST 2001
Hello fpc-pascal-admin,
Saturday, April 21, 2001, 2:00:05 PM, you wrote:
>> I've looked all through the Windows API help system but I've failed to find
>> a method for obtaining the handle of the current console process.
The Win32 API provides no direct method for obtaining the
window handle associated with a console application. However, you can
obtain the window handle by calling FindWindow(). This function retrieves a
window handle based on a class name or window name. Call GetConsoleTitle() to determine the
current console title. Then supply the current console title to FindWindow().
Because multiple windows may have the same title, you should change
the current console window title to a unique title. This will help prevent the
wrong window handle from being returned.
>> Eg. I start prog.exe. I want prog.exe to find out the handle that points to
>> itself, that Windows has created for it.
Function GetConsoleHwnd:hWnd;
Const Title='unique_title'#0;
Var hwndFound:hWnd;
Begin
SetConsoleTitle(pChar(@Title[1]));
Sleep(40); { <- let Windows update the title }
hwndFound:=FindWindow(Nil,pChar(@Title[1]));
Exit(hwndFound);
End;
---------------------------------
Sergey Kosarevsky
[FC Development Team]
http://www.freecommander.boom.ru
freecommander at aport2000.ru
More information about the fpc-pascal
mailing list