Hello fpc-pascal-admin,
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
