[Solved] Programmatically placing the console at some position ? lazarus / 21-General ---------------------------------------------------------------------- BrunoK · 2023-06-25 12:41 Win10, Lazarus trunk. When I debug an application,  I toggle off Win32 gui application (-WG) off so it is possible to view DebugLn and family function output. Annoyingly, it is necessary to move the console from under the debugged application window with the mouse. Is there a way, at the start of running the application, to set programmatically the console window position. ---------------------------------------------------------------------- TRon · 2023-06-25 12:54 Quote from: BrunoK on June 25, 2023, 02:41:00 pmIs there a way, at the start of running the application, to set programmatically the console window position. If memory serves me correctly (it has been a while for me to have used windows) you can use API calls findwindow and setwindowpos. M$ must have some online examples in c (which can easily be ported back to Pascal). ---------------------------------------------------------------------- BrunoK · 2023-06-25 13:09 Quote from: TRon on June 25, 2023, 02:54:00 pmIf memory serves me correctly (it has been a while for me to have used windows) you can use API calls findwindow and setwindowpos. M$ must have some online examples in c (which can easily be ported back to Pascal). Thanks. Searching in that direction. ---------------------------------------------------------------------- TRon · 2023-06-25 13:47 Pfft  Took me long enough to come up with this. For setwindowpos, please do a search for it on the forums here. BTW: I used to use console API functions such as getconsolewindow but that seems deprecated these days, see f.e. https://learn.microsoft.com/en-us/windows/console/getconsolewindow hence the suggestion to use findwindow as that is more generic. For more information on dropping console API see https://learn.microsoft.com/en-us/windows/console/classic-vs-vt ---------------------------------------------------------------------- BrunoK · 2023-06-25 17:04 Thank you TRon. The www.swissdelphicenter.ch stuff has been useful to search info. I found that I can move the console with : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   lConsoleHWND:=Windows.GetConsoleWindow;  Windows.SetWindowPos(lConsoleHWND, HWND_TOP, -2700, 200, 0, 0, SWP_SHOWWINDOW+SWP_NOSIZE);  Windows.GetWindowRect(lConsoleHWND, lRect);I have to figure now out the correct coordinates because my 2 screens are different in size and resolution. ---------------------------------------------------------------------- 440bx · 2023-06-25 20:50 Quote from: BrunoK on June 25, 2023, 02:41:00 pmWhen I debug an application,  I toggle off Win32 gui application (-WG) off so it is possible to view DebugLn and family function output. That's perfectly fine but, a GUI can dynamically create a console whenever needed for debugging purposes. That spares the programmer from having to change the application type and recompile.  That said, that method requires a little extra work to inform the RTL that a console has been created (otherwise outputting to the console causes an access violation.)  I posted an example of doing it that way some time back, I can find it if you're interested in that method.  Another plus of this method is that the console can be made to appear only when a bug has been detected and the first output line can be a unique string that identifies the code that created it.  This makes it trivial to find the code using "find" for the identifier in a text editor. Quote from: BrunoK on June 25, 2023, 02:41:00 pmAnnoyingly, it is necessary to move the console from under the debugged application window with the mouse. Is there a way, at the start of running the application, to set programmatically the console window position. Yes, and using SetWindowPos is perfectly fine but, MoveWindow, which is usually simpler can also be used. HTH.