Screen 0 and Windows 10

New to FreeBASIC? Post your questions here.
Post Reply
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Screen 0 and Windows 10

Post by oog »

Usually I can switch from graphics window back to terminal window with "screen 0". This does not work on Windows 10. If I call "screen 0", the gfx window closes and the terminal window opens, but I can't input and output to the terminal window.

From the code below:

Code: Select all

Print "Back to Terminal Window"
Sleep
has no effect.

Any ideas?


Code: Select all

#ifdef __FB_WIN32__
#include once "windows.bi"
#endif

Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
FreeConsole() ' hide console window (minimize)
#endif

Screen 1
Print "Screen 1"
Print "GFX Window"
Sleep

Screenres 480,320,32
Print "Screenres 480,320,32"
Print "GFX Window"
Sleep

#ifdef __FB_WIN32__
AllocConsole() ' show console window
#endif

Screen 0
Print "Screen 0"
Print "Back to Terminal Window"
Sleep
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Screen 0 and Windows 10

Post by dodicat »

Win 10 here.
I have the same problem.
The last window disappears at screen 0 but focus is not given back to the console.
I have tried nulling a screenpointer, using shell to give the console a name, hoping it would get focus and fiddeled about to no avail.
I am sure there is an api instruction as a workaround somewhere.
But I would call this a bug.
Win 10 changed some things, for example getpixel is no longer usable for fast retrieval of desktop colours.
MoveWindow no longer works properly on fb 64 bits.
And other annoyances.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Screen 0 and Windows 10

Post by fxm »

I have not Win10, but can you test this:

Code: Select all

#ifdef __FB_WIN32__
#include once "windows.bi"
#endif

Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
FreeConsole() ' hide console window (minimize)
#endif

Screen 1
Print "Screen 1"
Print "GFX Window"
Sleep

Screenres 480,320,32
Print "Screenres 480,320,32"
Print "GFX Window"
Sleep

#ifdef __FB_WIN32__
AllocConsole() ' show console window
Dim HandleConsoleWindow As HWND
HandleConsoleWindow = GetConsoleWindow()  'get handle of console window
SetForegroundWindow(HandleConsoleWindow)  'console window gets foreground
SetFocus(HandleConsoleWindow)             'console window gets focus
#endif

Screen 0
Print "Screen 0"
Print "Back to Terminal Window"
Sleep
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Screen 0 and Windows 10

Post by dodicat »

Still no luck with that here fxm.
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re: Screen 0 and Windows 10

Post by oog »

fxm wrote:can you test this ...
Good idea, but does not work for me.

I've tried some variations, also without success.

called SetFocus behind screen 0

Code: Select all

Screen 0

SetForegroundWindow(HandleConsoleWindow)  'console window gets foreground
SetFocus(HandleConsoleWindow)             'console window gets focus
Tried open cons

Code: Select all

Open cons As #1

Print "Screen 0"
Print "Back to Terminal Window"
Print #1, "Terminal Window with open cons"
call "open cons" at program start before "FreeConsole"

Code: Select all

Open cons As #1
Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
FreeConsole() ' hide console window (minimize)
#endif
Nothing seems to work.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Screen 0 and Windows 10

Post by fxm »

Have you ever tested this?

Code: Select all

AllocConsole()
Attachconsole(-1)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Screen 0 and Windows 10

Post by dodicat »

After screen 0 you are able to create a console with columns and rows, give that console a title.
But it stops there.
Even the crt function puts will not write to it, and the console seems to freeze at that point, no code runs beyond sleep.

Code: Select all

#Include "crt.bi"


#ifdef __FB_WIN32__
#include once "windows.bi"
#endif

Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
FreeConsole() ' hide console window (minimize)
#endif

Screen 1
Print "Screen 1"
Print "GFX Window"
Sleep

Screenres 480,320,32
Print "Screenres 480,320,32"
Print "GFX Window"
Sleep

#ifdef __FB_WIN32__
AllocConsole() ' show console window
'Attachconsole(-1)
#EndIf
'Dim HandleConsoleWindow As HWND
'SetForegroundWindow(HandleConsoleWindow)  'console window gets foreground
'SetFocus(HandleConsoleWindow)             'console window gets focus
Screen 0
Shell "MODE CON: COLS=90 LINES=50"
Shell "title new console"

Puts "Hello"

Sleep
beep

Print "Screen 0"
Print "Back to Terminal Window"

Sleep 
Strange, it is difficult even to get a workaround .
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Screen 0 and Windows 10

Post by fxm »

Can you test this workaround on Win10?
The console is only hidden and then restored (no difference, view from the user):

Code: Select all

#ifdef __FB_WIN32__
#include once "windows.bi"
#endif

Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
'FreeConsole()
Dim HandleConsoleWindow As HWND
HandleConsoleWindow = GetConsoleWindow()
ShowWindow(HandleConsoleWindow, SW_HIDE)
#endif

Screen 1
Print "Screen 1"
Print "GFX Window"
Sleep

Screenres 480,320,32
Print "Screenres 480,320,32"
Print "GFX Window"
Sleep

#ifdef __FB_WIN32__ ' show console window
ShowWindow(HandleConsoleWindow, SW_RESTORE)
SetForegroundWindow(HandleConsoleWindow)
SetFocus(HandleconsoleWindow)
#endif

Screen 0
Print "Screen 0"
Print "Back to Terminal Window"
Sleep
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Screen 0 and Windows 10

Post by dodicat »

Test was faulty
Above code by fxm tesed OK
Below code by fxm tested OK
Last edited by dodicat on Oct 26, 2017 15:17, edited 1 time in total.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Screen 0 and Windows 10

Post by fxm »

Perhaps adding a "minimizing" before "restoring"?

Code: Select all

#ifdef __FB_WIN32__
#include once "windows.bi"
#endif

Print "Terminal Window"
Print "Press key to switch windows"
Sleep
#ifdef __FB_WIN32__
'FreeConsole()
Dim HandleConsoleWindow As HWND
HandleConsoleWindow = GetConsoleWindow()
ShowWindow(HandleConsoleWindow, SW_HIDE)
#endif

Screen 1
Print "Screen 1"
Print "GFX Window"
Sleep

Screenres 480,320,32
Print "Screenres 480,320,32"
Print "GFX Window"
Sleep

#ifdef __FB_WIN32__ ' show console window
ShowWindow(HandleConsoleWindow, SW_MINIMIZE)
ShowWindow(HandleConsoleWindow, SW_RESTORE)
SetForegroundWindow(HandleConsoleWindow)
SetFocus(HandleconsoleWindow)
#endif

Screen 0
Print "Screen 0"
Print "Back to Terminal Window"
Sleep
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Screen 0 and Windows 10

Post by dodicat »

fxm
both your codes (minimize or not) work well in fbide with the run command:
cmd /c "<$file>" <$param> & pause

But I am testing on fbedit (bare). --- (And now also tested on fbide without the run command)

OK
It runs on fbide without the above run command (don't need minimize)

MY problem was using fbedit.
(should've known better with the previous problems I have had with fbedit)


Also good on poseidon,
The fbgfx always on top is an extra option.
Up to oog.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Screen 0 and Windows 10

Post by D.J.Peters »

screen or scrennres has some more problems on win10
i study the fbgfx source code but cant find any issue.

Joshy
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re: Screen 0 and Windows 10

Post by oog »

fxm wrote:Perhaps adding a "minimizing" before "restoring"?
Yes, it works now. Thank you, it's great. Minimizing is not necessary.

oog.
Post Reply