Author Topic: Some info regarding $IF precompiler directives  (Read 2063 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
Some info regarding $IF precompiler directives
« on: March 08, 2022, 10:54:52 am »
Code: QB64: [Select]
  1. $IF WIN THEN
  2.         DECLARE LIBRARY
  3.         FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  4.         END DECLARE
  5.     DECLARE LIBRARY ""
  6.         FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  7.     END DECLARE
  8.  
  9. answer = MessageBox(0, "Hi, bplus. You can do this.", "This is platform-agnostic", 0)
  10.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #1 on: March 08, 2022, 10:55:57 am »
Perfect! Thanks I will give it a go!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #2 on: March 08, 2022, 11:01:57 am »
@FellippeHeitor

Would that work in a library BM or BI?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Some info regarding $IF precompiler directives
« Reply #3 on: March 08, 2022, 11:07:03 am »
Code: QB64: [Select]
  1. $IF WIN THEN
  2.         DECLARE LIBRARY
  3.         FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  4.         END DECLARE
  5.     DECLARE LIBRARY ""
  6.         FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  7.     END DECLARE
  8.  
  9. answer = MessageBox(0, "Hi, bplus. You can do this.", "This is platform-agnostic", 0)
  10.  

What's the difference in those two DECLARE LIBRARY statements?  Is the blank quotes necessary for Linux/Mac, but not Windows?  It's something I've never noticed before.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #4 on: March 08, 2022, 11:12:54 am »
@SMcNeill  curious my IDE is coloring the two things different.

Maybe you would know if that would work in BI?

I am thinking of starting include code library, it would have this messageBox and circleFill code for sure!

FellippeHeitor

  • Guest
Re: Some info regarding $IF precompiler directives
« Reply #5 on: March 08, 2022, 11:16:23 am »
Yes, empty quotes are required for non-Windows systems in this case.

FellippeHeitor

  • Guest
Re: Some info regarding $IF precompiler directives
« Reply #6 on: March 08, 2022, 11:18:51 am »
Maybe you would know if that would work in BI?

Yes, no problems.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Some info regarding $IF precompiler directives
« Reply #7 on: March 08, 2022, 11:49:39 am »
@SMcNeill  curious my IDE is coloring the two things different.

Try anything in an $IF ...  $ELSE... set of blocks.  The code that's evaluated as valid is colored and syntax spaced like normal; the code that's excluded isn't.  It's an easy visual way to see what's actually included in your code and what isn't, before you hit the f5 button and compile it.

$LET CHEESE = 2

$IF CHEESE = 1 THEN
    ? "One Cheese!"
$END IF

$IF CHEESE = 2 THEN
    ? "Two Cheese!"
$END IF

Try the above in the IDE and see how it formats and colors the two different $IF blocks.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #8 on: March 08, 2022, 11:52:28 am »
Alright! so it's doing a little interpreter work. Thanks

Offline mdijkens

  • Newbie
  • Posts: 34
Re: Some info regarding $IF precompiler directives
« Reply #9 on: March 08, 2022, 12:01:41 pm »
And it also determines if it gets compiled/linked in your executable and thus (not) include certain libraries

Code: QB64: [Select]
  1. $Let MYLOG = 1
  2.  
  3. Sub log (l$)
  4.   $If MYLOG = DEFINED Then
  5.  
  6.   $End If
  7.  
~ 2 million lines of BASIC

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #10 on: March 13, 2022, 12:57:55 pm »
Well I thought the messageBox thing would be great but it likes to hide under the 2nd window button of QB64 on the tool bar, not even visible to the QB64 app sitting in the window. I thought my program was hanging until I found it when the top right X button wasn't working for QB64 app.

Code: QB64: [Select]
  1. _Title " MessageBox test - look behind the QB64 app on tool bar if not seen on top. Lean on esc to quit... "
  2.  
  3. ' Thank you FellippeHeitor!
  4. $If WIN Then
  5.         Function MessageBox (ByVal ignore&, message$, title$, Byval type&)
  6.     End Declare
  7.     DECLARE LIBRARY ""
  8.     FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  9.     END DECLARE
  10.  
  11. Const xmax = 800, ymax = 600, PI = 3.141592653589793
  12. Screen _NewImage(xmax, ymax, 32)
  13. _ScreenMove 300, 40
  14.  
  15.     Cls
  16.     drawLandscape
  17.     Color &HFFFFFFFF, &HFF000000
  18.     kind = 1 ' 0 is just OK, 1 is OK & Cancel
  19.     Print "Warning a Modal Message Box may come up off screen, you program is waiting for that!."
  20.     answer = MessageBox(0, "You might have to look for me off screen. Lean on escape button to quit. Now you should quit seeing me with Cancel.", "Test MessageBox", kind)
  21.     Print answer
  22.  
  23.     'cant mess with first parameter?
  24.     _Delay 2
  25.     If answer = 2 Then End
  26.     k$ = InKey$ ' curious if key press in messageBox will interfere with inkey$
  27.     If k$ = "q" Then End
  28.     _Limit 1
  29.  
  30. Sub drawLandscape
  31.     'needs midInk, irnd
  32.  
  33.     Dim i As Long, startH As Single, rr As Long, gg As Long, bb As Long
  34.     Dim mountain As Long, Xright As Single, y As Single, upDown As Single, range As Single
  35.     Dim lastx As Single, X As Long
  36.     'the sky
  37.     For i = 0 To ymax
  38.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  39.         Line (0, i)-(xmax, i)
  40.     Next
  41.     'the land
  42.     startH = ymax - 200
  43.     rr = 70: gg = 70: bb = 90
  44.     For mountain = 1 To 6
  45.         Xright = 0
  46.         y = startH
  47.         While Xright < xmax
  48.             ' upDown = local up / down over range, change along Y
  49.             ' range = how far up / down, along X
  50.             upDown = (Rnd * .8 - .35) * (mountain * .5)
  51.             range = Xright + irnd&(15, 25) * 2.5 / mountain
  52.             lastx = Xright - 1
  53.             For X = Xright To range
  54.                 y = y + upDown
  55.                 Color _RGB(rr, gg, bb)
  56.                 Line (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  57.                 lastx = X
  58.             Next
  59.             Xright = range
  60.         Wend
  61.         rr = irnd&(rr - 15, rr): gg = irnd&(gg - 15, gg): bb = irnd&(bb - 25, bb)
  62.         If rr < 0 Then rr = 0
  63.         If gg < 0 Then gg = 0
  64.         If bb < 0 Then bb = 0
  65.         startH = startH + irnd&(5, 20)
  66.     Next
  67.  
  68. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  69.     Color _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  70.  
  71. Function irnd& (n1, n2) 'return an integer between 2 numbers
  72.     Dim l%, h%
  73.     If n1 > n2 Then l% = n2: h% = n1 Else l% = n1: h% = n2
  74.     irnd& = Int(Rnd * (h% - l% + 1)) + l%
  75.  
  76.  
  77.  

So is there anyway to force the MessageBox to make an appearance on top of the QB64 app specially the first time, it often works as expected after that but not always.

What is nice is esc works as alt or short cut to Cancel Click.

Offline Dav

  • Forum Resident
  • Posts: 792
Re: Some info regarding $IF precompiler directives
« Reply #11 on: March 13, 2022, 01:33:27 pm »
It's  been a while since I dabbled with API, but I remember that there is a message box flag that lets you keep it on top of everything.  Perhaps our API guru @SpriggsySpriggs can jump in for percise info, but for now I changed this and it seemed to work for me on Windows.

kind = 1 OR 4096   '4096 is the number for MB_SYSTEMMODAL flag

- Dav

Marked as best answer by on April 16, 2024, 08:30:07 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Some info regarding $IF precompiler directives
« Reply #12 on: March 13, 2022, 01:48:04 pm »
  • Undo Best Answer
  • It's  been a while since I dabbled with API, but I remember that there is a message box flag that lets you keep it on top of everything.  Perhaps our API guru @SpriggsySpriggs can jump in for percise info, but for now I changed this and it seemed to work for me on Windows.

    kind = 1 OR 4096   '4096 is the number for MB_SYSTEMMODAL flag

    - Dav

    MB_TOPMOST = 0x00040000L
    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
    Re: Some info regarding $IF precompiler directives
    « Reply #13 on: March 13, 2022, 02:19:03 pm »
    Thanks guys, I will try and let you know.

    Does that go in the first argument? or what / where to use that number?

    I plan to use it mostly for debugging and Windows only is fine for me, even if Fellippe was offering cross-platform box.

    Offline SMcNeill

    • QB64 Developer
    • Forum Resident
    • Posts: 3972
      • Steve’s QB64 Archive Forum
    Re: Some info regarding $IF precompiler directives
    « Reply #14 on: March 13, 2022, 02:26:33 pm »
    Last argument for the type of box.  Just add or OR the value to whatever the existing number was you were passing.
    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!