My set up is a primary 1920x1080 in front of me and a 1280x1024 secondary to the left. My web browser opens in the secondary monitor amongst many other applications. I rarely open anything on my primary monitor with the exception of my IDE.
Of course, any normal console applications open on my primary monitor which is a pain, for me, if I want to keep them open whilst editing the source code. I used to drag the console window to the secondary monitor and that got hidden if I clicked on another window that was open.
Not any more.<smile>
Below is a little bi file which saves the console window's location in "Loaction.dat" on closing and loads the same on the next opening. There is much more about a console which could be saved but my interest here is only the location. Save "Location.bi" in a folder called, say, "TestLoc".
Location.bi
Code: Select all
#include once "windows.bi"
#include once "file.bi"
DeleteMenu(GetSystemMenu(GetConsoleWindow,False), SC_CLOSE, MF_BYCOMMAND)
Sub on_init( ) Constructor
Dim As Long x, y
If Fileexists("Location.dat") Then
Open "Location.dat" For Binary As #1
Get #1, , x
Get #1, , y
Close #1
SetWindowPos( GetConsoleWindow, HWND_TOPMOST, x, y, 0, 0, SWP_NOSIZE )
End If
End Sub
Sub on_exit( ) Destructor
Dim xy As Rect
GetWindowRect( GetConsoleWindow, @xy )
If Fileexists("Location.dat") Then Kill "Location.dat"
Open "Location.dat" For Binary As #1
Put #1, , xy.left
Put #1, , xy.top
Close #1
End Sub
Test.bas
Code: Select all
#include once "Location.bi"
Print "Main running"
Sleep 1000
Print "Done - Press any key"
Sleep
Now, run Test again and it will open at the position it was on the previous close.
The 'eagle eyed' amongst you will have noticed that the console window does not have a Close button. If we closed the application via the Close button then the location will not get saved, so I removed the Close button. I got caught out a few times and I write the code. <laugh>.
That's it!
If you have just the one monitor and it is a, so called, wide-screen and your IDE is maximised then you will probably have a fair amount of white space on the right hand side. Run your console application, which uses "Location.bi", and drag the console window to the white space area and close. Next time the application will open in the white space. If you click on your IDE window the console window will not become 'hidden' because it is TopMost.
If you have more than one monitor then on first running drag the console window to a secondary window and close. Thereafter, the console will open on the secondary monitor. This assumes, of course, that the secondary monitors are extensions of the primary monitor.
I have a folder called "Experiments" and it is full of snippets testing ideas and many of them now use "Location.bi" everyone of which opens on my secondary monitor by virtue of just the one "Location.dat".
My background is GUI programming with very little Console programming but I should imagine that some of you console guys may have some ideas on improving the above. If you have then post them here so that we can all benefit.