Feature request: instrisic Defines for console / gui mode

For other topics related to the FreeBASIC project or its community.
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 15, 2018 13:42

@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
fxm
Posts: 8283
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 15, 2018 14:09

marpon wrote:#if __FB_GUI__ <> 0 'could be also just #if __FB_GUI__

Or:
#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
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 15, 2018 14:23

@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 :-)
fxm
Posts: 8283
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 15, 2018 14:24

marpon wrote:on FBWiki : KeyPgDdfbgui
could be added , only for win32 / win64

KeyPgDdfbgui → fxm [Added paragraph 'Platform differences']
fxm
Posts: 8283
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 15, 2018 14:35

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 :-)

IMHO, 'Not' applies to 'condition' and not to '#If':

If ( Not condition ) Then ...

#if ( Not condition ) ...
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 15, 2018 14:50

@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)
fxm
Posts: 8283
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 16, 2018 5:48

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]
marpon
Posts: 246
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Postby marpon » Sep 16, 2018 16:16

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

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



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
fxm
Posts: 8283
Joined: Apr 22, 2009 12:46
Location: Paris (suburb), FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Postby fxm » Sep 17, 2018 8:48

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]

Always the same problem with the today "freebasic_manual.chm" file.

@admins, @St_W,
Have you an idea (good on wiki) ?
coderJeff
Site Admin
Posts: 2680
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Postby coderJeff » Sep 17, 2018 10:49

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.

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests