QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Richard on October 29, 2021, 12:31:59 am

Title: How to remove title Bar from graphics screen?
Post by: Richard on October 29, 2021, 12:31:59 am
Fullscreen does not show Title Bar - want the same feature when not in full screen graphics.  The wiki example only seems to work for text screens.
Title: Re: How to remove title Bar from graphics screen?
Post by: FellippeHeitor on October 29, 2021, 09:30:56 am
This is the exact example from the wiki with added graphics screen (indicated by comments):

Code: QB64: [Select]
  1. '============
  2. 'NOBORDER.BAS
  3. '============
  4.  
  5.     FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
  6.  
  7.     FUNCTION GetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
  8.     FUNCTION SetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
  9.     FUNCTION SetWindowPos& (BYVAL hwnd AS LONG, BYVAL hWndInsertAfter AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG, BYVAL wFlags AS LONG)
  10.  
  11. GWL_STYLE = -16
  12. WS_BORDER = &H800000
  13.  
  14. 'these are the only lines Fellippe added for this reply --------------------------------------------------------------------------
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16. FOR i = 1 TO 100
  17.     CIRCLE (RND * _WIDTH, RND * _HEIGHT), RND * 100, _RGB32(RND * 255, RND * 255, RND * 255)
  18. 'these were the only lines Fellippe added for this reply ------------------------------------------------------------------------
  19.  
  20. _TITLE "No Border"
  21. hwnd& = _WINDOWHANDLE 'FindWindow(0, "No Border" + CHR$(0))
  22.  
  23. PRINT "Press any key for no border...": A$ = INPUT$(1)
  24.  
  25. winstyle& = GetWindowLongA&(hwnd&, GWL_STYLE)
  26. a& = SetWindowLongA&(hwnd&, GWL_STYLE, winstyle& AND NOT WS_BORDER)
  27. a& = SetWindowPos&(hwnd&, 0, 0, 0, 0, 0, 39)
  28.  
  29. PRINT "Press any key to get back border...": SLEEP
  30.  
  31. winstyle& = GetWindowLongA&(hwnd&, GWL_STYLE)
  32. a& = SetWindowLongA&(hwnd&, GWL_STYLE, winstyle& OR WS_BORDER)
  33. a& = SetWindowPos&(hwnd&, 0, 0, 0, 0, 0, 39)
  34.  
  35. PRINT "The end"
  36.  

Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 29, 2021, 09:41:30 am
You may need to add a small _DELAY in the program at startup, so the window handle is created and reported properly for you.
Title: Re: How to remove title Bar from graphics screen?
Post by: Richard on October 29, 2021, 10:49:31 am
@FellippeHeitor @SMcNeill

Thanks for reply but...



  [ This attachment cannot be displayed inline in 'Print Page' view ]  




However - the title bar is still present (only BLACK and cannot write to same). I even have delays of 2 seconds and still no different.

In FULLSCREEN mode there is "no lost display real estate" for title bar.
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 29, 2021, 11:06:17 am
I can duplicate this effect perfectly on my machine.  The titlebar doesn't actually disappear; it simply goes black and inactive, with the window still taking up the same amount of space as previously.  I don't remember this being the usual behavior for Win 10, but my stuff is now on the new Win 11 builds and this is how it's working. 

It may simply be a change from windows itself, and not something which we can easily fix.
Title: Re: How to remove title Bar from graphics screen?
Post by: FellippeHeitor on October 29, 2021, 11:31:36 am
The fact is: The API call does work. You may wanna check if it's triggering a _RESIZE event.
Title: Re: How to remove title Bar from graphics screen?
Post by: Richard on October 29, 2021, 11:52:45 am
@FellippeHeitor @SMcNeill

Ran program with $RESIZE:ON to compare effect




  [ This attachment cannot be displayed inline in 'Print Page' view ]  


$RESIZE:ON  "adds a bit more" to the title bar area.





I am using Windows 10 build 21H1 Pro x64 (updated OCT 2021)   +   dev v2.1 c48bf67
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 29, 2021, 11:58:01 am
The fact is: The API call does work. You may wanna check if it's triggering a _RESIZE event.

It's not a Resize issue.  I can add $RESIZE to the program and manually resize it all I want, and that black space up top remains with the window.  It's some new interaction between Win 11 and QB64 with the window -- the command is only blacking out (hiding) the title area now, but it's not actually getting rid of it.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

The picture here should show the white window borderline nicely to show what it's doing now.
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 29, 2021, 07:51:13 pm
I just checked and discovered while it works, as advertised in V1.3, it fails to remove the title bar in v 2.0.

Edit: Wow, worse problem then I originaly thought. V2.0 completely mangled even my most fundamental transparent window without border routine...

Code: QB64: [Select]
  1. CONST HWND_TOPMOST%& = -1
  2. CONST SWP_NOSIZE%& = &H1
  3. CONST SWP_NOMOVE%& = &H2
  4. CONST SWP_SHOWWINDOW%& = &H40
  5.  
  6.     FUNCTION GetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
  7.     FUNCTION SetWindowPos& (BYVAL hWnd AS LONG, BYVAL hWndInsertAfter AS _OFFSET, BYVAL X AS INTEGER, BYVAL Y AS INTEGER, BYVAL cx AS INTEGER, BYVAL cy AS INTEGER, BYVAL uFlags AS _OFFSET)
  8.     FUNCTION SetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
  9.     FUNCTION GetForegroundWindow&
  10.     FUNCTION SetLayeredWindowAttributes& (BYVAL hwnd AS LONG, BYVAL crKey AS LONG, BYVAL bAlpha AS _UNSIGNED _BYTE, BYVAL dwFlags AS LONG)
  11. SCREEN _NEWIMAGE(600, 480, 32)
  12. GWL_STYLE = -16
  13. ws_border = &H800000
  14. WS_VISIBLE = &H10000000
  15. _TITLE "Borderless Window"
  16. DIM hwnd AS LONG
  17. Level = 175
  18. SetWindowOpacity hwnd, Level
  19.  
  20. winstyle2& = GetWindowLongA&(hwnd, GWL_STYLE)
  21. winstyle& = -12582913
  22. a& = SetWindowLongA&(hwnd, GWL_STYLE, winstyle& AND WS_VISIBLE) ' AND NOT WS_VSCROLL) ' AND NOT ws_border)
  23. a& = SetWindowPos&(hwnd, 0, 0, 0, 0, 0, 39)
  24. msg$ = "Welcome to Translucent Windows Without Borders!"
  25. i = 16
  26. COLOR &HFFFFFFFF, &H0 ' white foreground, transparent background
  27.     _LIMIT 60
  28.     FGwin& = GetForegroundWindow&
  29.     IF hwnd <> FGwin& THEN ' QB64 no longer in focus.
  30.         WHILE _MOUSEINPUT: WEND
  31.         a& = SetWindowPos&(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_SHOWWINDOW)
  32.         DO: _LIMIT 30: LOOP UNTIL hwnd = GetForegroundWindow&
  33.     END IF
  34.     IF INKEY$ = CHR$(27) THEN EXIT DO
  35.     FOR y = 480 TO 0 STEP -1
  36.         FOR x = 640 TO 0 STEP -1
  37.             PSET (x, 480 - y), _RGB(y / 2 MOD 256, 100, 200) ' (x MOD 512 XOR y) MOD 256, y MOD 256)
  38.         NEXT
  39.     NEXT
  40.     _PRINTSTRING (92, 1), msg$
  41.     _PRINTSTRING (1, 464), "Press Esc to quit."
  42.     _PRINTSTRING (250, i), "Hi Chez-Pete!"
  43.     _DISPLAY
  44.     i = i + 1
  45.     IF i > 464 THEN i = 16
  46.  
  47. SUB SetWindowOpacity (hwnd AS LONG, Level)
  48.     DIM Msg AS LONG
  49.     CONST G = -20
  50.     CONST LWA_ALPHA = &H2
  51.     CONST WS_EX_LAYERED = &H80000
  52.     Msg = GetWindowLongA&(hwnd, G)
  53.     Msg = Msg OR WS_EX_LAYERED
  54.     action = SetWindowLongA&(hwnd, G, Msg)
  55.     action = SetLayeredWindowAttributes(hwnd, 0, Level, LWA_ALPHA)
  56.  

Try it in V1.3 or 1.5. It works fine. It does absolutely nothing in V2.0. So does the code need a rewrite, or is this a V2.0 bug?
 
Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: Dav on October 29, 2021, 09:10:23 pm
Hi @Pete.  I get the same running that code as is - works in v1.5, but not in v2.0.  I've found that in QB64 v2 I now *have* to add more _DELAY after the SCREEN call to get windowhandle working.  Maybe v2 sets the screen faster than previous versions?  Anywho, after putting in _DELAY 1 your code works in QB64 v2 now. At least for me in 32-bit Win7.

- Dav
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 29, 2021, 09:31:49 pm
@Dav Hi Dav,

I just tried your _DELAY suggestion. Got it working with...

_DELAY .2
SCREEN _NEWIMAGE(600, 480, 32)

A .1 delay failed. Weirdly, too. Two blank consoles opened. Doubling to .2 corrected everything.

I agree, there seems to be some slower response from this later version. I experienced delay issues with using hardware imaging as well. Windows API calls often need delays as well. I mean the greatest thing ever would be some checking function like _FILEEXISTS() does for files so the next statement in the program flow would not be executed until the API function was returned. I've made a few of those.

I am wondering if this delay needed before rendering the SCREEN image could be tweaked. I don't do graphics, but I didn't think delays to render a screen image would ever be necessary.

Thanks for the solution!

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 29, 2021, 09:39:10 pm
Another thing I've noticed recently is that QB64 can't decide if programs are aware of hidh resolution scaling or not.  V2.0 didn't upscale screens on my monitor, so QB64 ran under a massive 3840x2160 desktop, with 0 scaling.  V2.0.1 now uses the 100% scaling so it effectively reports my desktop as being 1920x1080 resolution and automatically doubles the size of everything.  Every few upgrades, this behavior seems to toggle back and forth in our versions, with the user having no control over it.  Is this autoscaling an issue messing with things?  Is there some way we can make the option a meta-command to toggle if auto-scale is on, or off, by default in our programs?

From the way it sounds, these things work in older versions, but not newer ones, so it doesn't appear to be any sort of windows system change that's causing the issue.
Title: Re: How to remove title Bar from graphics screen?
Post by: Dav on October 29, 2021, 09:49:44 pm
I forgot to mention, one thing I did notice that can eliminate the need for a small delay, is if you do an _ICON call at the beginning.  I sometimes put _ICON -11 at the top of my test programs, and when doing that I never need to add a _DELAY to prevent issues.

- Dav
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 29, 2021, 09:51:47 pm
@Dav Hi Dav,

I just tried your _DELAY suggestion. Got it working with...

_DELAY .2
SCREEN _NEWIMAGE(600, 480, 32)

A .1 delay failed. Weirdly, too. Two blank consoles opened. Doubling to .2 corrected everything.

I agree, there seems to be some slower response from this later version. I experienced delay issues with using hardware imaging as well. Windows API calls often need delays as well. I mean the greatest thing ever would be some checking function like _FILEEXISTS() does for files so the next statement in the program flow would not be executed until the API function was returned. I've made a few of those.

I am wondering if this delay needed before rendering the SCREEN image could be tweaked. I don't do graphics, but I didn't think delays to render a screen image would ever be necessary.

Thanks for the solution!

Pete

@Pete What you're seeing here has been happening forever and ever in QB64.  It's part of our startup behavior.  If you watch closely, all QB64 programs start out in SCREEN 0. 

_DELAY .2
SCREEN _NEWIMAGE(600, 480, 32)

Even with your little 2-line snippet above, what SCREEN mode was your program in before that _DELAY statement was issued?

Yep!  Your favorite!  SCREEN 0!

So QB64 makes a screen...  Windows gives it a handle...
QB64 frees that screen...  Without a delay, you might get that handle...
Windows frees the handle, Makes a new screen... Without a delay, you might get the blank handle...
Windows gives the new screen its handle...

There's several race conditions at work here, which can result in your _WINDOWHANDLE returning garbage for you. 

My suggestion is to get into the habit of placing a delay of *at least* 0.2 seconds after each SCREEN or _NEWIMAGE statement, before you go referencing it via _WINDOWHANDLE or other means. 
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 29, 2021, 10:06:11 pm
You guys are so lucky I'm not a "developer" on this project because you'd all get this popup at start up...

                    Are you sure you want to leave SCREEN 0? N/N

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: mpgcan on October 30, 2021, 03:30:19 am
I had a delay problem similar to this, one of you guys provided a neat solution which seems to work on this. At the top of your script add the following line :
Code: QB64: [Select]
  1. Do: Loop Until _ScreenExists 'before using _WindowHandle or _title

Worked on this:
Code: QB64: [Select]
  1. Do: Loop Until _ScreenExists 'before using _WindowHandle or _title
  2.  
  3. Const HWND_TOPMOST%& = -1
  4. Const SWP_NOSIZE%& = &H1
  5. Const SWP_NOMOVE%& = &H2
  6. Const SWP_SHOWWINDOW%& = &H40
  7.  
  8.     Function GetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long)
  9.     Function SetWindowPos& (ByVal hWnd As Long, Byval hWndInsertAfter As _Offset, Byval X As Integer, Byval Y As Integer, Byval cx As Integer, Byval cy As Integer, Byval uFlags As _Offset)
  10.     Function SetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long, Byval dwNewLong As Long)
  11.     Function GetForegroundWindow&
  12.     Function SetLayeredWindowAttributes& (ByVal hwnd As Long, Byval crKey As Long, Byval bAlpha As _Unsigned _Byte, Byval dwFlags As Long)
  13. Screen _NewImage(600, 480, 32)
  14. GWL_STYLE = -16
  15. ws_border = &H800000
  16. WS_VISIBLE = &H10000000
  17. _Title "Borderless Window"
  18. Dim hwnd As Long
  19. Level = 175
  20. SetWindowOpacity hwnd, Level
  21.  
  22. winstyle2& = GetWindowLongA&(hwnd, GWL_STYLE)
  23. winstyle& = -12582913
  24. a& = SetWindowLongA&(hwnd, GWL_STYLE, winstyle& And WS_VISIBLE) ' AND NOT WS_VSCROLL) ' AND NOT ws_border)
  25. a& = SetWindowPos&(hwnd, 0, 0, 0, 0, 0, 39)
  26. msg$ = "Welcome to Translucent Windows Without Borders!"
  27. i = 16
  28. Color &HFFFFFFFF, &H0 ' white foreground, transparent background
  29.     _Limit 60
  30.     FGwin& = GetForegroundWindow&
  31.     If hwnd <> FGwin& Then ' QB64 no longer in focus.
  32.         While _MouseInput: Wend
  33.         a& = SetWindowPos&(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_SHOWWINDOW)
  34.         Do: _Limit 30: Loop Until hwnd = GetForegroundWindow&
  35.     End If
  36.     If InKey$ = Chr$(27) Then Exit Do
  37.     For y = 480 To 0 Step -1
  38.         For x = 640 To 0 Step -1
  39.             PSet (x, 480 - y), _RGB(y / 2 Mod 256, 100, 200) ' (x MOD 512 XOR y) MOD 256, y MOD 256)
  40.         Next
  41.     Next
  42.     _PrintString (92, 1), msg$
  43.     _PrintString (1, 464), "Press Esc to quit."
  44.     _PrintString (250, i), "Hi Chez-Pete!"
  45.     _Display
  46.     i = i + 1
  47.     If i > 464 Then i = 16
  48.  
  49. Sub SetWindowOpacity (hwnd As Long, Level)
  50.     Dim Msg As Long
  51.     Const G = -20
  52.     Const LWA_ALPHA = &H2
  53.     Const WS_EX_LAYERED = &H80000
  54.     Msg = GetWindowLongA&(hwnd, G)
  55.     Msg = Msg Or WS_EX_LAYERED
  56.     action = SetWindowLongA&(hwnd, G, Msg)
  57.     action = SetLayeredWindowAttributes(hwnd, 0, Level, LWA_ALPHA)
  58.  
All the best.
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 30, 2021, 07:12:55 am
That solution created a memory problem. In other words, I forgot that keyword existed! Oh well, by tomorrow I'll forget how $^$%# I got about forgetting about _SCREENEXISTS, so I've got that going for me.

Well thanks for that, and for the further discussion of race conditions by Steve. Now here's a couple more things for discussion...

1) Don't you guys think _SCREEEXISTS should just be an inherent part of all SCREEN commands? In otherwords the code doesn't precede until the SCREEN is rendered?

2) In my code that @mpgcan modified, I would have put _SCREENEXISTS after the screen call:

SCREEN _NEWIMAGE(600, 480, 32)

but he put it at the beginning of the program, and it still worked. To me, that indicates the race problem is not with making the graphics screen, but with making the start up, SCREEN 0 screen. @SMcNeill  Does that assumption seem correct?

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 30, 2021, 07:55:25 am
@Pete The problem, I found in the past, with ScreenExists is it's an internal one-time flag.  (Unless it's been modified to be different over time.)

This means ScreenExists starts as a 0 (False) value.  Then, once that initial SCREEN 0 screen is created, it gets a value of -1 (True).  From that point on, it stays true as you will always have a visible screen for your program.

The issue can arise as in the code above (or as simplified below):

DO: LOOP UNTIL _SCREENEXISTS 'This will pause your program until that initial SCREEN 0 is generated and registered properly.
SCREEN _NEWIMAGE(640, 480, 32)
PRINT _WINDOWHANDLE

That Print statement above may, or may not, work as intended.  You might get the handle for the initial SCREEN 0.  You might get the handle 0 where it was freed, but the new screen isn't registered back to us yet.  You might get what you expect.

The screen does indeed exist at this point, but we're swapping screens and as such Windows may not be reporting what the updated handle is back to us just yet.

As I mentioned above, I'd play it safe and *always* toss a _DELAY .2 in there after initializing that screen for the first time, just to be safe. 

The reason why you don't want an automatic delay in all SCREEN commands would be for something a little unusual like this:

ScreenOne = _NEWIMAGE(640, 480, 32)
ScreenTwo = _NEWIMAGE(640, 480, 32)

Do
    i= i + 1 MOD 2
    IF i THEN SCREEN ScreenOne ELSE ScreenTwo

We create the screens above, then flip between them alternating like we used to do with multiple pages in the old days...  You certainly  don't want to add in a .2 second delay in those instances, now do you?

Sometimes, it's best to leave some things up to the programmer to sort out themselves.  ;D
Title: Re: How to remove title Bar from graphics screen?
Post by: bplus on October 30, 2021, 11:28:40 am
I remember Dav's Pipe program for which this:
Code: QB64: [Select]

did not work but a simple _Delay .25 did for _Screenmove _Middle
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 30, 2021, 12:36:45 pm
@bplus Yes, I've had to use a small delay before using _SCREENMOVE as well. From our discussion so far, it appears likely  the delay is needed for the screen to be rendered, before it can be moved. In Dav's "Pipes" game, I did not experience the failure to move the screen, as you did. In other words I ran the code both with and without that .25 delay, and it centered the screen both times. My question would be if you moved his Do: Loop Until _ScreenExists statement to the top of the program and removed your delay, would it work?

@SMcNeill I agree a method that provides the freedom to choose outweighs a one size that doesn't always fit all method. I'm also in favor of improvements, and if it is possible to make a _SCREENEXISTS statement identify with each screen statement and reset itself to zero when the screen is rendered, that would be an improvement. That would require dynamic arrays and using preserve in QB64. I'm not familiar with a different method for C/C++.

These situations make me more appreciative of code that runs as expected. With this, and statements like SCREENPRINT and SCREENCLICK, the benchmark seems to be a .2 delay. The question is will .2 always be enough? As I mentioned, I could run Dav's program without the delay Mark needed. So if a faster, slower, or different systems with some different run-time priorities are involved, what good is a delay that falls a millisecond short? Again, the only ironclad system is a feedback one. That's a tall order, I know, as more than just screen rendering would need to be included.

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: bplus on October 30, 2021, 02:43:00 pm
Quote
My question would be if you moved his Do: Loop Until _ScreenExists statement to the top of the program and removed your delay, would it work?

No, it didn't. @Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: Dav on October 30, 2021, 03:49:43 pm
Hmm, now I see what the original poster is referring to, still seeing the title bar.  There seems to be a difference between QB64 versions and removing the title bar.  When I run Pete's code, using a very long delay, in v1.5 and lower I get this on my Win7 laptop - no title bar and no borders at all.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

But when I run it in QB64 v2 I get this, a black title bar and border, no matter how long a delay I add.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

That's just for Petes code.  I can remove the title bar and border using other API code, like this one here which does work as expected in QB64 v2..

- Dav

Code: QB64: [Select]
  1. '================
  2. 'WindowRegion.bas v1.1
  3. '================
  4. 'Uses Windows API to create a non-standard looking window.
  5. 'Using this you could use an image as the entire window instead.
  6. 'Coded by Dav, JULY/2020
  7.  
  8. 'I used API information found on this page....
  9. 'http://allapi.mentalis.org/apilist/apilist.php
  10.  
  11.  
  12. TYPE POINTAPI
  13.     x AS LONG
  14.     y AS LONG
  15. DIM apixy AS POINTAPI 'mouse x/y for the GetCursorPos function
  16.  
  17.     'sets a created window region
  18.     'http://allapi.mentalis.org/apilist/SetWindowRgn.shtml
  19.     FUNCTION SetWindowRgn& (BYVAL hwnd&, BYVAL hrgn&, BYVAL bredraw%)
  20.     'get current mouse x/y position
  21.     'http://allapi.mentalis.org/apilist/GetCursorPos.shtml
  22.     FUNCTION GetCursorPos% (lpPoint AS POINTAPI)
  23.  
  24.  
  25.     'creates a rectangular region
  26.     'http://allapi.mentalis.org/apilist/CreateRectRgn.shtml
  27.     FUNCTION CreateRectRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&)
  28.     'creates an elliptical region
  29.     'http://allapi.mentalis.org/apilist/CreateEllipticRgn.shtml
  30.     FUNCTION CreateEllipticRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&)
  31.     'creates a rectangular region with rounded corners
  32.     'http://allapi.mentalis.org/apilist/CreateRoundRectRgn.shtml
  33.     FUNCTION CreateRoundRectRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&, BYVAL x3&, BYVAL y3&)
  34.  
  35. controls& = BASIMAGE1& 'Make Minimize & Exit controls image
  36. _ICON controls& 'might as well make it the program icon too...
  37.  
  38. hwnd& = _WINDOWHANDLE 'need the windows handle to play with it
  39.  
  40. 'Create a rounded rectangular region...
  41. rgn& = CreateRoundRectRgn(30, 30, 650, 650, 240, 240)
  42.  
  43. 'you can try these also...
  44. 'rgn& = CreateEllipticRgn(30, 30, 650, 650)
  45. 'rgn& = CreateRectRgn(30, 30, 650, 650)
  46.  
  47. 'Set the created region...
  48. try& = SetWindowRgn(hwnd&, rgn&, 0)
  49. 'Returns zero if failed...
  50. IF try& = 0 THEN
  51.     PRINT "Failed...": END
  52.  
  53. 'Setup screen....
  54. SCREEN _NEWIMAGE(680, 680, 32)
  55. FOR y = 1 TO 680
  56.     LINE (0, y)-(680, y), _RGB(c, c, 64), BF
  57.     c = c + 1: IF c > 32 THEN c = 0
  58.  
  59. 'Draw a top highlighted bar
  60. LINE (0, 0)-(680, 80), _RGB(64, 64, 196), BF
  61. 'draw minimize and exit image
  62. _PUTIMAGE (500, 30), controls&
  63.  
  64.  
  65.     p = _MOUSEINPUT
  66.     mx = _MOUSEX: my = _MOUSEY
  67.  
  68.     'LOCATE 12, 12: PRINT mx, my; _MOUSEBUTTON(1); 'testing info
  69.  
  70.     IF _MOUSEBUTTON(1) AND mx < 500 AND mx > 0 AND my < 80 AND mx > 0 THEN
  71.  
  72.         'get orig mouse x/y using api
  73.         tmp = GetCursorPos(apixy)
  74.         origx = apixy.x: origy = apixy.y
  75.  
  76.         DO
  77.             p = _MOUSEINPUT: IF _MOUSEBUTTON(1) = 0 THEN EXIT DO
  78.  
  79.             'poll mouse x/y
  80.             tmp = GetCursorPos(apixy)
  81.             mx = apixy.x: my = apixy.y
  82.  
  83.             _SCREENMOVE _SCREENX - (origx - mx), _SCREENY + (my - origy)
  84.  
  85.             origx = mx: origy = my
  86.  
  87.         LOOP
  88.  
  89.  
  90.     END IF
  91.  
  92.     'see if user clicked minimized area
  93.     IF _MOUSEBUTTON(1) AND mx > 500 AND mx < 540 AND my > 29 AND my < 66 THEN
  94.         'wait until button up to continue
  95.         DO: p = _MOUSEINPUT
  96.             IF _MOUSEBUTTON(1) = 0 THEN EXIT DO
  97.         LOOP
  98.         'minimize program
  99.         _SCREENICON
  100.     END IF
  101.  
  102.     'see if user clicked exit area
  103.     IF _MOUSEBUTTON(1) AND mx > 540 AND mx < 580 AND my > 29 AND my < 66 THEN
  104.         IF _MOUSEBUTTON(1) = -1 THEN
  105.             SYSTEM
  106.         END IF
  107.     END IF
  108.  
  109.  
  110.  
  111. 'This function creates the control image.
  112. 'It was made with my BASIMAGE.BAS program .
  113. FUNCTION BASIMAGE1& 'controls.png
  114.     v& = _NEWIMAGE(80, 40, 32)
  115.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  116.     A$ = ""
  117.     A$ = A$ + "haIkH_oCCM5007_l#P28JF6a`HbL3iIKY?hEO#aOHKJ04W^9ciLDX::aXbn1"
  118.     A$ = A$ + "U]iFfD7?4#4T7jLZK4#A5:<L;Z0^T]Q#L6aU\HbRVmO04PO081n]c>WcUc]g"
  119.     A$ = A$ + "KkmNJ[m2SOhfT?inXWk]GnN_]gFZ\b:1E:c_=a4C\ZbZaS9Q>6UkWde_7jhF"
  120.     A$ = A$ + ";K6]_KcJ\nkQW7=P3<Jm[S^nC#Gmn_[J8g?Y_OS?hmHmdQ^_X6Oh11oUGjY?"
  121.     A$ = A$ + "H8_6]nM^cokP6Jk5B\WcZ^Fn7<W[k5PVJML#c]lTUlH\jKL4<Qjg8>jU1lJT"
  122.     A$ = A$ + "7fW3`HoDo2Jd1hk9go^^Qki2JhNNQFoZj\o6XV6O^?[ZU9bmCjkg#Mn3l<LG"
  123.     A$ = A$ + "o8[1i0]l#G_3NN#gM2ne^_QXnSNkaYnjU5nlEo>`W_Xe__lD33nZ_mI2:_]F"
  124.     A$ = A$ + "6VVg<FgPFo9[jI<>mOc>?]aCfVR?d8RB^OBOoLdJCHmeFcH3LYFMjb]cj>Oo"
  125.     A$ = A$ + "5an5>^37olE^T7=P0Xe_SDAoPSNRa54i_MQNPFoF\F<6J\TiY=N4J]C\nMmj"
  126.     A$ = A$ + "ZQA3e2^Ame2^McWSE?GXAFT>c5Yi8>Jo2\j71fOG9di3Jm[db^9hPOjS5T5C"
  127.     A$ = A$ + "k5cC=Q<6JSS\_Tkg:Oo^fIn6\>Zn<HMMfZahfET^K\>\KeD32B\^;DkkUC_Y"
  128.     A$ = A$ + "e?Kf_9h07kADIfh79JK8mQfcI4^mNZKbmKi_OT6BjWKM4Rd#aJY_d#YZOLK8"
  129.     A$ = A$ + "]FiJg#<UUgg>ajGKOfaIenWO2`E?mGcS[GOBdI]EaX^Za`m^nJhQL];g[O9M"
  130.     A$ = A$ + "WdI?e_R?lX2ZTb7SW\Q]01eU5GLAAQ_V;cmPi;]C^O;?mcVY\LbRA#9iH2cF"
  131.     A$ = A$ + ">VaC;eZI6iV3`N^F0fgREFUo^_=?79_]QMhlg6XR]W??7]`l17K75h6Jm;^="
  132.     A$ = A$ + "o5PgBK7n4=Yad`iWONgPOO;liO3eGSQV[jLNXXC]5ZTkWdg_DEX0C=B0:0J2"
  133.     A$ = A$ + ":0FY5LPlXM=1aCJQ4<;MQ52;m:35H8l`0Y7QB<3[=LNB?Z805THlPMZ:IZmC"
  134.     A$ = A$ + "QRg3X8ZFm9a]Yg7gYiVK>gPFOLKJG`aeRh2Z1A9DoD_DkD1UbBCE]D;E50cD"
  135.     A$ = A$ + "Nc783JmEcBhfG^=6eGmAbdEjm[#PR`Jf[4C\5RQJd\c>[X#?ojOUg1SF[Tkg"
  136.     A$ = A$ + ":Co8_oUd=bba7IX2noZ`OT`jS4c0\QXgOSJXDd?Bg#VIVIl8bHme6:g?Y_OZ"
  137.     A$ = A$ + "hd>ETkS0i]OGNOi1ihf0WkahakOXllDAJgdC?]PldcQfNNkCoXOYjBoFHQ5T"
  138.     A$ = A$ + "DTnY3nIQYkEmKWRNOBdmAA#k_YVJ:g#N]8SQfh8k;5AdTLoFQk7K_LU7^?f;"
  139.     A$ = A$ + "3bO7I0kFFA6>8ce6Q7jg^015Mc2R\_VLb9M3ncJCX8<dHS?aR`X=NT0OEin]"
  140.     A$ = A$ + "Bg?]`FaU^PHT#D:UlkoJ=ihafj6S1\KE91n#=Y#]O[K3E0D^aV4DBYl1H2mj"
  141.     A$ = A$ + "PF?kHS]AWKCbkFha3G?BX`aj[m;k`F3F61706IIS:3Q_823c4lkLPH6nMOck"
  142.     A$ = A$ + "eSQWRP=1I?`^`e7[C=HOje`cWT^F#aIXSJoN]=OL#\jn>ob6Dg6?AcMN?lkM"
  143.     A$ = A$ + "mVOo[Lol_nI?3mHFP=97XmVJB<DW2HO#fdZ6[HMJhaVnd0UH#;;K`FDBVja8"
  144.     A$ = A$ + "kcBcb0?fc>MFU2]OCIB]OYJhTPD\NIOFRFJGdeWXi;b:NS]`KI?A^OBOo>XU"
  145.     A$ = A$ + "\UL70f5GGGIXYiH4k#8F=1:?GcDkGfF?5HkkoNnU2]OGNcSD`;9QjgZ9[6?V"
  146.     A$ = A$ + "4jHD^OBCoT9ko3o7Ml:S%%%0"
  147.     btemp$ = ""
  148.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  149.         IF INSTR(1, B$, "%") THEN
  150.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  151.                 IF F$ <> "%" THEN C$ = C$ + F$
  152.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  153.             IF MID$(B$, j, 1) = "#" THEN
  154.         MID$(B$, j) = "@": END IF: NEXT
  155.         FOR t% = LEN(B$) TO 1 STEP -1
  156.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  157.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  158.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  159.     NEXT: btemp$ = btemp$ + X$: NEXT
  160.     btemp$ = _INFLATE$(btemp$)
  161.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  162.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  163.  
  164.  


Title: Re: How to remove title Bar from graphics screen?
Post by: Richard on October 30, 2021, 09:05:44 pm
@Dav

Using your code from reply just above - I tried to have a window 640 x 320 without Title Bar or borders/sliders but it did not work for me.

I essentially removed any code referring to MOUSE or CONTROL Buttons to have a plain 640 x 320 graphics box with a diagonal line between screen corners.



Code: QB64: [Select]
  1. 'WindowRegion.bas v1.1      ' ### MODIFIED program written by Dav
  2.  
  3.     FUNCTION SetWindowRgn& (BYVAL hwnd&, BYVAL hrgn&, BYVAL bredraw%)
  4.     FUNCTION CreateRectRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&)
  5. hwnd& = _WINDOWHANDLE 'need the windows handle to play with it
  6. rgn& = CreateRectRgn( 0, 0, 640, 320)'Create a rectangular region...
  7. try& = SetWindowRgn(hwnd&, rgn&, 0)  'Set the created region...
  8. IF try& = 0 THEN PRINT "Failed...": system 'Returns zero if failed...
  9.  
  10. SCREEN _NEWIMAGE(640, 320, 32)  'Setup screen.... 640x320 BLACK background
  11. line(0,0)-(639,319),&Hff00ff00~&& 'TESTING display GREEN LINE (0,0)-(bottom RH corner)
  12.  
  13. _delay 30:system    ' ### TERMINATE program after 30 seconds
  14.  


  [ This attachment cannot be displayed inline in 'Print Page' view ]  




Using Windows 10 x64 Pro Build 21H1 (oct updated)  with  QB64 v2.1 dev c48bf67






Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 30, 2021, 11:04:51 pm
@Dav

Using your code from reply just above - I tried to have a window 640 x 320 without Title Bar or borders/sliders but it did not work for me.

I essentially removed any code referring to MOUSE or CONTROL Buttons to have a plain 640 x 320 graphics box with a diagonal line between screen corners.

Okay, it didn't remove the title bar for me, either. Also, I had to add the delay indicated in the code below, between the two declare library statements, or the handle for SetWindowRgn would fail to register.

Code: QB64: [Select]
  1. 'WindowRegion.bas v1.1      ' ### MODIFIED program written by Dav
  2.  
  3.     FUNCTION SetWindowRgn& (BYVAL hwnd&, BYVAL hrgn&, BYVAL bredraw%)
  4. _DELAY .2 ' <---------------On my system, this delay is needed or it will fail.
  5.     FUNCTION CreateRectRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&)
  6. hwnd& = _WINDOWHANDLE 'need the windows handle to play with it
  7. rgn& = CreateRectRgn(0, 0, 640, 320) 'Create a rectangular region...
  8. try& = SetWindowRgn(hwnd&, rgn&, 0) 'Set the created region...
  9. IF try& = 0 THEN PRINT "Failed...": SLEEP: SYSTEM 'Returns zero if failed...
  10.  
  11. SCREEN _NEWIMAGE(640, 320, 32) 'Setup screen.... 640x320 BLACK background
  12. LINE (0, 0)-(639, 319), &HFF00FF00~&& 'TESTING display GREEN LINE (0,0)-(bottom RH corner)
  13.  
  14. _DELAY 30: SYSTEM ' ### TERMINATE program after 30 seconds
  15.  

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: Dav on October 31, 2021, 09:25:14 am
@Richard. That's because of the CreateRectRgn(0, 0, 640, 320) settings.  In your code the x1 and y1 is set to 0 which puts it inside the title bar area, so the title bar is drawn now. I really don't know well how it works, but I noticed I had to increase those numbers to keep title bar from popping back up, which is why in my code I had it set higher.  If you change your code to CreateRectRgn(10, 30, 640, 320) it should stay gone, but of course this puts x/y out of wack when drawing stuff because part of the screen is hidden.  I need to learn more about using these API's.  Maybe @SpriggsySpriggs can shed more light on this for us.   @Pete, the _DELAY was needed in it again because the _ICON call was removed.  With _ICON in play the _DELAY doesn't seem to be needed. 

- Dav
Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on October 31, 2021, 09:49:11 am
Part of the issue may be command depreciation.  Windows documentation now tells us that GetWindowLong and SetWindowLong has now been depreciated, and GetWindowLongPtr and SetWindowLongPtr should now be used instead.  (Particularly on 64-bit systems.)

You guys might try swapping to those calls and see what it changes.  (You might need to check to make certain SetWindowPos hasn't changed as well.  I'm not at home atm, so didn't bother to keep digging since I can't actually test anything at the moment anyway.)


May also want to try the SetWindowPos with the last value being 38 rather than 39.

SWP_DRAWFRAME -- 0x0020 -- Draws a frame (defined in the window's class description) around the window.
SWP_NOMOVE -- 0x0002 -- Retains the current position (ignores the x and y members).
SWP_NOSIZE -- 0x0001 -- Retains the current size (ignores the cx and cy members).
SWP_NOZORDER  -- 0x0004 -- Retains the current Z order (ignores the hwndInsertAfter member).

That 39 is basically made up of all the flags above, but it seems to me that the NOSIZE right be an issue if windows counts the title bar height as being inclusive to the overall window size.  It wouldn't hurt to test it once without it.  :P
Title: Re: How to remove title Bar from graphics screen?
Post by: Pete on October 31, 2021, 09:51:33 am
@Dav I'll speculate it's the process of getting the icon, the time it takes, provides the necessary delay for the race condition to catch up, but how would I know, as I graduated top of my class of zero. You ask, "how can you have a class of zero?" Simple, I was the only one in the class, and I never showed up.

Your "trick" of hiding the title bar reminded me of my trick of making the screen size the desktop size plus the height of the title bar and using _SCREENMOVE with a negative second parameter to move the screen up just far enough to hide the title bar.

Pete
Title: Re: How to remove title Bar from graphics screen?
Post by: mpgcan on November 01, 2021, 04:50:13 am
I have looked at removing borders and I offer my solution on this problem the following works on Windows 8.1

Code: QB64: [Select]
  1. Do: Loop Until _ScreenExists 'run before using _WindowHandle or _title
  2. '####################################################
  3. '# Name:     no_border_no_caption.bas
  4. '# Author:   MPG
  5. '# Purpose:  Remove border and caption. Remaing area
  6. '#           is all client.
  7. '#           Items commented out may be required.
  8. '#           Do: Loop Until _ScreenExists required
  9. '#           on Windows 8.1
  10. '# Revision: November 1 2021 - initial version
  11. '####################################################
  12.  
  13.     Function FindWindow& (ByVal ClassName As _Offset, WindowName$)
  14.  
  15.     Function GetWindowLongA& (ByVal hWnd As _Offset, Byval nIndex As Long)
  16.     Function SetWindowLongA& (ByVal hWnd As _Offset, Byval nIndex As Long, Byval dwNewLong As Long)
  17.     Function SetWindowPos& (ByVal hWnd As _Offset, Byval hWndInsertAfter As Long, Byval x As Long, Byval y As Long, Byval cx As Long, Byval cy As Long, Byval wFlags As Long)
  18.     '    Function ShowScrollBar& (ByVal hWnd As _Offset, Byval wBar As Long, Byval bShow As Long)
  19.  
  20. Const GWL_STYLE = -16
  21. Const WS_BORDER = &H800000
  22. Const WS_CAPTION = &H00C00000
  23. Const WS_THICKFRAME = &H00040000
  24. Const WS_MINIMIZEBOX = &H00020000
  25. Const WS_MAXIMIZEBOX = &H00010000
  26. Const WS_SYSMENU = &H00080000
  27. 'Const SB_BOTH = 3
  28.  
  29. Dim As Long winstyle, Style, a
  30.  
  31. winstyle = GetWindowLongA(hwnd, GWL_STYLE)
  32. Style = (WS_CAPTION Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU)
  33. a = SetWindowLongA&(hwnd, GWL_STYLE, winstyle And Not Style)
  34. 'a = ShowScrollBar(hwnd, SB_BOTH, false)
  35.  
  36.  
  37. Screen _NewImage(640, 320, 32)
  38. 'Cls
  39. Line (0, 0)-(639, 319), &HFF00FF00~&&
  40. Line (300, 0)-(300, 320), &HFF00FF00~&&
  41. Line (0, 150)-(640, 150), &HFF00FF00~&&
  42.  
  43. Line (639, 0)-(639, 100), &HFF00FF00~&&
  44. Line (0, 0)-(0, 100), &HFF00FF00~&&
  45.  
  46. Line (400, 0)-(500, 0), &HFF00FF00~&&
  47. Line (400, 319)-(500, 319), &HFF00FF00~&&
  48.  
  49.  
  50. _PrintString (100, 100), "Press any key to end...": Sleep
  51. Print "The end Note:Location"
  52.  

With the do-loop enabled. Shows borders and caption removed .
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

All the best.


Title: Re: How to remove title Bar from graphics screen?
Post by: Richard on November 01, 2021, 05:18:28 am
@mpgcan 

Thanks




  [ This attachment cannot be displayed inline in 'Print Page' view ]  





Windows 10 x64 Pro  21H1 (OCT updated)   with v2.1 dev build c48bf67






Many thanks again





Title: Re: How to remove title Bar from graphics screen?
Post by: SMcNeill on November 01, 2021, 08:19:31 am
Good catch with the WS_SYSMENU flag.   To completely remove the window, you need to remove both it and the WS_CAPTION flag from the options.

Code: QB64: [Select]
  1. Do: Loop Until _ScreenExists 'run before using _WindowHandle or _title
  2. '####################################################
  3. '# Name:     no_border_no_caption.bas
  4. '# Author:   MPG
  5. '# Purpose:  Remove border and caption. Remaing area
  6. '#           is all client.
  7. '#           Items commented out may be required.
  8. '#           Do: Loop Until _ScreenExists required
  9. '#           on Windows 8.1
  10. '# Revision: November 1 2021 - initial version
  11. '####################################################
  12.  
  13.     Function FindWindow& (ByVal ClassName As _Offset, WindowName$)
  14.  
  15.     Function GetWindowLongA& (ByVal hWnd As _Offset, Byval nIndex As Long)
  16.     Function SetWindowLongA& (ByVal hWnd As _Offset, Byval nIndex As Long, Byval dwNewLong As Long)
  17.     Function SetWindowPos& (ByVal hWnd As _Offset, Byval hWndInsertAfter As Long, Byval x As Long, Byval y As Long, Byval cx As Long, Byval cy As Long, Byval wFlags As Long)
  18.     '    Function ShowScrollBar& (ByVal hWnd As _Offset, Byval wBar As Long, Byval bShow As Long)
  19.  
  20. Const GWL_STYLE = -16
  21. Const WS_BORDER = &H800000
  22. Const WS_CAPTION = &H00C00000
  23. Const WS_THICKFRAME = &H00040000
  24. Const WS_MINIMIZEBOX = &H00020000
  25. Const WS_MAXIMIZEBOX = &H00010000
  26. Const WS_SYSMENU = &H00080000
  27. 'Const SB_BOTH = 3
  28.  
  29. Dim As Long winstyle, Style, a
  30.  
  31. winstyle = GetWindowLongA(hwnd, GWL_STYLE)
  32. Style = (WS_CAPTION Or WS_SYSMENU)
  33. a = SetWindowLongA&(hwnd, GWL_STYLE, winstyle And Not Style)
  34. 'a = ShowScrollBar(hwnd, SB_BOTH, false)
  35.  
  36.  
  37. Screen _NewImage(640, 320, 32)
  38. 'Cls
  39. Line (0, 0)-(639, 319), &HFF00FF00~&&
  40. Line (300, 0)-(300, 320), &HFF00FF00~&&
  41. Line (0, 150)-(640, 150), &HFF00FF00~&&
  42.  
  43. Line (639, 0)-(639, 100), &HFF00FF00~&&
  44. Line (0, 0)-(0, 100), &HFF00FF00~&&
  45.  
  46. Line (400, 0)-(500, 0), &HFF00FF00~&&
  47. Line (400, 319)-(500, 319), &HFF00FF00~&&
  48.  
  49.  
  50. _PrintString (100, 100), "Press any key to end...": Sleep
  51. Print "The end Note:Location"
  52.  
  53.  

Style = (WS_CAPTION Or WS_SYSMENU)

What the wiki has is the simple WS_CAPTION being removed, but that doesn't also remove the WS_SYSMENU, which is what's reserving that blank space up top for the titlebar that we're no longer making use of.  Getting rid of both fixes the issue for good.  ;)
Title: Re: How to remove title Bar from graphics screen?
Post by: Dav on November 01, 2021, 08:37:12 am
That works good here!

- Dav