Feature request: instrisic Defines for console / gui mode
Re: Feature request: instrisic Defines for console / gui mode
@fxm good and quick done :-)
on FBWiki : KeyPgDdfbgui
could be added , only for win32 / win64
the example
#if __FB_GUI__ <> 0 'could be also just #if __FB_GUI__
#print Executable subsystem: gui
#else
#print Executable subsystem: console
#endif
can also be the opposite
#if not __FB_GUI__ 'notice the not
#print Executable subsystem: console
#else
#print Executable subsystem: gui
#endif
on FBWiki : KeyPgDdfbgui
could be added , only for win32 / win64
the example
#if __FB_GUI__ <> 0 'could be also just #if __FB_GUI__
#print Executable subsystem: gui
#else
#print Executable subsystem: console
#endif
can also be the opposite
#if not __FB_GUI__ 'notice the not
#print Executable subsystem: console
#else
#print Executable subsystem: gui
#endif
Re: Feature request: instrisic Defines for console / gui mode
Or:marpon wrote:#if __FB_GUI__ <> 0 'could be also just #if __FB_GUI__
#if __FB_GUI__ = True
#print Executable subsystem: gui
#else
#print Executable subsystem: console
#endif
I usually code this way (with relational operators) to avoid an unexpected response if the intrinsic is not defined as for the following example:
#if __FB_CONSOLE__
#print Executable subsystem: console
#else
#print Executable subsystem: gui
#endif
Re: Feature request: instrisic Defines for console / gui mode
@fxm
understand, please as you like <> 0 or = true
i"m not sure the "not" usage on #if is somewhere explained
i use chm, and did not found that usage
it is my c notions to push me trying that :-)
understand, please as you like <> 0 or = true
i"m not sure the "not" usage on #if is somewhere explained
i use chm, and did not found that usage
it is my c notions to push me trying that :-)
Re: Feature request: instrisic Defines for console / gui mode
KeyPgDdfbgui → fxm [Added paragraph 'Platform differences']marpon wrote:on FBWiki : KeyPgDdfbgui
could be added , only for win32 / win64
Re: Feature request: instrisic Defines for console / gui mode
IMHO, 'Not' applies to 'condition' and not to '#If':marpon wrote:i"m not sure the "not" usage on #if is somewhere explained
i use chm, and did not found that usage
it is my c notions to push me trying that :-)
If ( Not condition ) Then ...
#if ( Not condition ) ...
Re: Feature request: instrisic Defines for console / gui mode
@aggree
is why i've tested it, do not care...
thank's again for the reaction
on the sleep extension feature, it will be another story, as i think we have to work on the fb_sleep function of the rtlib side,
i'm even not be able to compile the rtlib (to test my mingw tool-chain installation)
is why i've tested it, do not care...
thank's again for the reaction
on the sleep extension feature, it will be another story, as i think we have to work on the fb_sleep function of the rtlib side,
i'm even not be able to compile the rtlib (to test my mingw tool-chain installation)
Re: Feature request: instrisic Defines for console / gui mode
I don'y know why all links to the '__FB_GUI__' page (including the page title) appear as '__Fb_Gui__' only in the .chm documentation file (while everywhere defined in full capital letters).
Maybe because the "PrintToc" page had not been updated yet?
So I try that:
PrintToc → fxm [Manual generated update]
Maybe because the "PrintToc" page had not been updated yet?
So I try that:
PrintToc → fxm [Manual generated update]
Re: Feature request: instrisic Defines for console / gui mode
extend for sleep without value in code as Jocep Roca was suggesting
in fact it does not exist any safe solution, at compile time , the test is too restrictive,
the only safe way is to do specific tests at run time
i've made a first draft , not complete because it should also take into account ScreenRes function
the case not very well done is in gui mode (without console) and opening a gfx graphic window
after closing the gfx graphic mode, even if you attach console with AllocConsole (), the console opens but is not working ,
probably that behaviour was not tested before,
i trap the case for screen function only, with overloaded function (static inside) to check if it was used,
but has to be expanded for general case for screenres also
only 1 static incremented by both functions screen and screenres can do the trick,
but it could be better to restore an initial clean state to allow a normal working AllocConsole (), i let it for someone interrested ...
i did not noticed problems if not using gfx window
in fact it does not exist any safe solution, at compile time , the test is too restrictive,
the only safe way is to do specific tests at run time
i've made a first draft , not complete because it should also take into account ScreenRes function
Code: Select all
''''try both possibilities -s gui and -s console
#include once "windows.bi"
#if __FB_GUI__
private function isgui()as long
return 1
end function
#else
private function isgui()as long
return 0
end function
#endif
#undef Screen
declare function fb_screen alias "fb_GfxScreen"( _
byval mode as long, byval depth as long=8, byval num_pages as long = 0, _
byval flags as long = 0, byval refresh_rate as long = 0) as long
private Function screen( byval mode as long, byval depth as long=8, byval num_pages as long = 0, _
byval flags as long = 0, byval refresh_rate as long = 0) as long
STATIC timesCalled As long = 0
dim as long ret
if mode = -9 then
IF timesCalled > 0 then return timesCalled
return 0
end if
ret = fb_screen (mode, depth, num_pages, flags, refresh_rate)
IF ScreenPtr <> 0 then timesCalled += 1
return ret
End function
sub mysleep()
IF screenptr then
print "existing gui graphic mode"
sleep
ELSEif isgui() then
IF screen(-9) = 0 then
if GetConsoleCP() then
print "existing console"
sleep
else
AllocConsole ()
print " created console"
sleep
end if
else
messagebox(0, "was before in gui graphic mode", "Indefined Sleep", MB_ICONWARNING + MB_SYSTEMMODAL)
end if
else
print "console mode"
sleep
endif
end sub
'' hack, undefine only 1version of SLEEP, (by chance it is the right one , because 2 exists)
#undef sleep
'' declare the rtlib functions
declare sub fb_Sleep alias "fb_Sleep" ( byval amount as long = -1 )
'' SLEEP interceptors
function Sleep overload ( byval amount as long = -1 ) as long
print " - SLEEP(1) intercepted!"
if amount < 0 then mysleep() : return 0
fb_Sleep( amount ) '' call original sleep command
return 0
end function
' main part
Dim w As Integer, h As Integer
Dim depth As Integer
Dim driver_name As String
print "message in console"
Screen 15, 32
' Obtain info about current mode
ScreenInfo w, h, depth,,,,driver_name
Print Str(w) + "x" + Str(h) + "x" + Str(depth);
Print " using " + driver_name + " driver"
sleep
' Quit graphics mode
'Screen 0 ' this one close gfx window and clears the console if exists
' Quit graphics mode without clearing console if exists
screen 0 , 0 , 0 , &h80000000
'obtain info about desktop
ScreenInfo w, h, depth,,,,driver_name
Print "Desktop running at " + Str(w) + "x" + Str(h) + "x" + Str(depth);
print " using " + driver_name + " driver"
sleep
after closing the gfx graphic mode, even if you attach console with AllocConsole (), the console opens but is not working ,
probably that behaviour was not tested before,
i trap the case for screen function only, with overloaded function (static inside) to check if it was used,
but has to be expanded for general case for screenres also
only 1 static incremented by both functions screen and screenres can do the trick,
but it could be better to restore an initial clean state to allow a normal working AllocConsole (), i let it for someone interrested ...
i did not noticed problems if not using gfx window
Re: Feature request: instrisic Defines for console / gui mode
Always the same problem with the today "freebasic_manual.chm" file.fxm wrote:I don'y know why all links to the '__FB_GUI__' page (including the page title) appear as '__Fb_Gui__' only in the .chm documentation file (while everywhere defined in full capital letters).
Maybe because the "PrintToc" page had not been updated yet?
So I try that:
PrintToc → fxm [Manual generated update]
@admins, @St_W,
Have you an idea (good on wiki) ?
Re: Feature request: instrisic Defines for console / gui mode
Sorry, I should have seen earlier. __FB_GUI__ needs to be added to doc\manual\templates\default\keywords.lst. This file is used to normalize the case of keywords in documentation pages, titles, links, examples. Can get this fixed on the next wiki snapshot.
Re: Feature request: instrisic Defines for console / gui mode
REMARK: on the current implementation of: __FB_GUI__ (console = 0 = FALSE | gui = -1 = TRUE)
COMPLAINT: makes evaluation more complex, than needed/desired!
Proposed simplification:Which is currently NOT possible, without a value or boolean, check. (it always returns TRUE, currently!)
COMPLAINT: makes evaluation more complex, than needed/desired!
Proposed simplification:
- only define __FB_GUI__ -- if "-s gui" is detected, otherwise, don't define it, at all!
(The same as: __FB_64BIT__ implementation!)
Code: Select all
#Ifdef __FB_GUI__ '' alternative #Ifndef ... #If defined(__FB_GUI__) = more verbose
...
#Else
...
#EndIf
Code: Select all
'' current:
#If __FB_GUI__ = TRUE '' or: #If __FB_GUI__ <> 0
...
#Else
...
#EndIf
Re: Feature request: instrisic Defines for console / gui mode
Yep, that's a lot simpler thanMrSwiss wrote:Code: Select all
#Ifdef __FB_GUI__ ... #Else ... #EndIf
Code: Select all
#if fbgui
print "it's GUI"
#else
print "it's Console"
#endif
Re: Feature request: instrisic Defines for console / gui mode
A bit of a simpleton comment? (see comments in your code)
jj2007 wrote:Yep, that's a lot simpler thanCode: Select all
#if fbgui '' don't work anyhow print "it's GUI" '' if it would work, always GUI #else print "it's Console" '' never used #endif
Re: Feature request: instrisic Defines for console / gui mode
The platform (e.g. __FB_WIN32__, __FB_64BIT__) intrinsic defines are defined/not defined. All other intrinsic defines are defined to a value.
By setting the intrinsic to a value, the intrinsic define can be substituted wherever a constant could be used, for example:
That ease of substitution can't be done if the symbol is maybe defined, or is maybe not defined.
By setting the intrinsic to a value, the intrinsic define can be substituted wherever a constant could be used, for example:
Code: Select all
#if __FB_GUI__ andalso __FB_OUT_EXE__
'' some code
#endif
sub StartLog( mode as boolean = __FB_GUI__ )
end sub
Re: Feature request: instrisic Defines for console / gui mode
Yet it works (although I do not like this use):MrSwiss wrote:A bit of a simpleton comment? (see comments in your code)jj2007 wrote:Yep, that's a lot simpler thanCode: Select all
#if fbgui '' don't work anyhow print "it's GUI" '' if it would work, always GUI #else print "it's Console" '' never used #endif
Code: Select all
#if __fb_gui__
#print "it's GUI" ' if (__fb_gui__ is defined) and (__fb_gui__ <> 0)
#else
#print "it's Console" ' if (__fb_gui__ is undefined) or (__fb_gui__ = 0)
#endif