Author Topic: child windows into window of the program: a demonstration  (Read 10071 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
child windows into window of the program: a demonstration
« on: January 26, 2020, 10:38:22 am »
Hy guys

programming is like to go on bike, you never forget it but you must empower your coding muscles to travel far...

so I have done a demo for  this thread https://www.qb64.org/forum/index.php?topic=2115.msg113538#msg113538
but when I wanted to empower the demo with multiple windows (yes there are only 3 but code works for more than 3 windows) I loose myself in the hood of my imagination! So for a little but essential change in the order of the operations of the code I have had an hard session of debugging of 4-6 h  ... so it is clear that my Debugging muscles are very weak!

At the end this is the result, what is the content of each window is specific and I leave at your fantasy what put into it.
Originally I wanted to do a monitor of health with BMI and weight. But after all these hours of debugging for now I stop here.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 01 25  A program with child windows into it
  10. ' we need a system to manage multiple windows
  11. ' and a system to manage input/output
  12. ' and a system to make graphic report
  13.  
  14. ' settings-------------------------------------------------------
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16. _TITLE "Child windows"
  17. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  18. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  19. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  20. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 3, aNull = 0, aQuit = 9999
  21. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  22. CONST Dragging = 300, Focusing = 200
  23.  
  24.  
  25.  
  26. 'dataset  -----------------------------------------------
  27. TYPE person
  28.     name AS STRING * 10
  29.     age AS INTEGER
  30.     weight AS INTEGER
  31.     height AS INTEGER
  32.     BMI AS INTEGER
  33.  
  34. TYPE wChild
  35.     X AS INTEGER
  36.     Y AS INTEGER
  37.     Height AS INTEGER
  38.     Zorder AS INTEGER
  39.     Status AS INTEGER
  40.  
  41. REDIM Windows(0 TO wMin) AS wChild
  42. wMax = UBOUND(windows)
  43.  
  44. ' windows(0) is for Dragging
  45.  
  46. Windows(1).X = 1
  47. Windows(1).Y = 1
  48. Windows(1).Width = 300
  49. Windows(1).Height = 400
  50. Windows(1).Zorder = 1
  51. Windows(1).Status = Minim
  52. Windows(1).Color = Blu
  53.  
  54. Windows(2).X = 100
  55. Windows(2).Y = 1
  56. Windows(2).Width = 300
  57. Windows(2).Height = 400
  58. Windows(2).Zorder = 2
  59. Windows(2).Status = Minim
  60. Windows(2).Color = Yellow
  61.  
  62. Windows(3).X = 200
  63. Windows(3).Y = 1
  64. Windows(3).Width = 300
  65. Windows(3).Height = 400
  66. Windows(3).Zorder = 3
  67. Windows(3).Status = Minim
  68. Windows(3).Color = Green
  69.  
  70. DIM Action AS INTEGER
  71.  
  72.  
  73. ' main loop -----------------------------------------------
  74.     ' set the main window
  75.     Action = aNull
  76.     CLS , Orange
  77.     DrawAllWin
  78.  
  79.     GetInput Action
  80.  
  81.     DoAction Action
  82.     _LIMIT 20
  83.  
  84. ' SUBs and FUNCTIONs --------------------------------------
  85. SUB DrawAllWin
  86.     SHARED Windows() AS wChild
  87.     DIM Finished AS INTEGER
  88.     Finished = wMax
  89.     DO
  90.         FOR a = 1 TO wMax
  91.             IF Windows(a).Zorder = Finished THEN
  92.                 DrawWindow Windows(a)
  93.                 Finished = Finished - 1
  94.                 EXIT FOR
  95.             END IF
  96.         NEXT a
  97.     LOOP UNTIL Finished = 0
  98.  
  99. SUB Focus (Index AS INTEGER)
  100.     SHARED Windows() AS wChild
  101.     DIM b AS INTEGER
  102.     FOR b = 1 TO wMax
  103.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  104.     NEXT b
  105.     SWAP Windows(Index).Zorder, Windows(b).Zorder
  106.     DrawAllWin
  107.  
  108. SUB DoAction (Act AS INTEGER)
  109.     SHARED Windows() AS wChild
  110.     DIM a AS INTEGER
  111.  
  112.     SELECT CASE Act
  113.         CASE aQuit
  114.             END
  115.  
  116.         CASE Maxim
  117.             _FULLSCREEN
  118.  
  119.         CASE Minim
  120.             _FULLSCREEN _OFF
  121.  
  122.         CASE mLeft
  123.             DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER, Actio AS INTEGER
  124.             mX = _MOUSEX
  125.             mY = _MOUSEY
  126.             ' search where and what mouse has touched by leftclick
  127.             FOR a = 1 TO wMax ' windows(0) is out of action
  128.                 Actio = IsInWindow(mX, mY, Windows(a))
  129.                 IF Actio THEN EXIT FOR ' if windows(a) is on the stack it gets the click of mouse
  130.             NEXT a
  131.  
  132.             SELECT CASE Actio
  133.                 CASE Dragging
  134.                     Focus a
  135.                     Windows(0).X = Windows(a).X
  136.                     Windows(0).Y = Windows(a).Y
  137.                     Windows(0).Width = Windows(a).Width
  138.                     Windows(0).Height = Windows(a).Height
  139.                     Windows(0).Status = Windows(a).Status
  140.                     Windows(0).Color = Windows(a).Color
  141.                     OmX = _MOUSEX - Windows(0).X
  142.                     OmY = _MOUSEY - Windows(0).Y
  143.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  144.                     DO WHILE _MOUSEBUTTON(1)
  145.                         IF _MOUSEINPUT THEN
  146.                             CLS , Orange
  147.                             DrawAllWin
  148.                             Windows(0).X = (_MOUSEX - OmX)
  149.                             Windows(0).Y = (_MOUSEY - OmY)
  150.                             dragWindow Windows(0)
  151.                         END IF
  152.                     LOOP
  153.                     ' new position of window
  154.                     Windows(a).X = Windows(0).X
  155.                     Windows(a).Y = Windows(0).Y
  156.                     Windows(a).Width = Windows(0).Width
  157.                     Windows(a).Height = Windows(0).Height
  158.                     Windows(a).Status = Windows(0).Status
  159.                     Windows(a).Color = Windows(0).Color
  160.                     Windows(a).Zorder = 1
  161.  
  162.                 CASE Focusing
  163.                     Focus a
  164.             END SELECT
  165.         CASE ELSE
  166.     END SELECT
  167.  
  168. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  169.     IsInWindow = mFalse
  170.     IF IsInTheRange%(X, Win.X, Win.X + Win.Width) THEN
  171.         IF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  172.             IsInWindow = Dragging
  173.         ELSEIF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  174.             IsInWindow = Focusing
  175.         END IF
  176.     END IF
  177.  
  178. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  179.     IF Min > Max THEN SWAP Min, Max
  180.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  181.  
  182. SUB dragWindow (Win AS wChild)
  183.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  184.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  185.  
  186.  
  187. SUB DrawWindow (Win AS wChild)
  188.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  189.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Red, BF 'title bar for dragging window
  190.  
  191. SUB GetInput (Act AS INTEGER)
  192.     DIM mInput AS INTEGER
  193.  
  194.  
  195.     ' keyboard input
  196.     a$ = INKEY$
  197.     IF a$ = CHR$(27) THEN Act = aQuit
  198.  
  199.     'mouse input
  200.     mInput = mFalse
  201.     IF _MOUSEINPUT THEN mInput = mTrue
  202.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  203.     LOOP
  204.     IF mInput THEN
  205.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  206.             mInput = mLR
  207.         ELSEIF _MOUSEBUTTON(1) THEN
  208.             mInput = mLeft
  209.         ELSEIF _MOUSEBUTTON(2) THEN
  210.             mInput = mRight
  211.         ELSEIF _MOUSEBUTTON(3) THEN
  212.             mInput = mMiddle
  213.         END IF
  214.     END IF
  215.  
  216.     IF mInput = mLR THEN
  217.         Act = aQuit
  218.     ELSEIF mInput = mMiddle THEN
  219.         Act = Minim
  220.     ELSEIF mInput = mRight THEN
  221.         Act = Maxim
  222.     ELSEIF mInput = mLeft THEN
  223.         Act = mInput
  224.     END IF

Instruction:
Click by right mouse button to _Fullscreen
Click by Middle mouse button to _Minimize to normal window
Click by left mouse button into a child window  to choose a child window (there are 3 windows Blu, Green and Yellow)
click by left mouse button on Red top bar of a child window to move it by dragging in the main window of the program

Thanks to take a look!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #1 on: January 26, 2020, 11:18:57 am »
Looks like a start, you know that _DISPLAY will stop the annoying blinking.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #2 on: January 26, 2020, 11:23:35 am »
Yes but I must remember it! :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #3 on: January 26, 2020, 11:42:40 am »
Yes but I must remember it! :-)

Then remember also, once you start using it, you have to use it ever where OR switch it OFF with _AUTODISPLAY, otherwise you will wonder why nothing seems to be working. ;-)) (like when you want to drag the window)

I say this not to you particularly TempodiBasic but to all the poor souls who could get fouled up and lost by this one little problem. Oh the frustration... ;-(

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #4 on: January 27, 2020, 10:22:49 am »
Yes  one of the black beasts is _DISPLAY  vs  _AUTODISPLAY,  followed by  settings of color when you pass from a program written for ASCII screen or Qb45's legacy SCREEN to _NEWIMAGE (Width,Height,32)... remembering the exact sinthax and extension of each color command _RGB _RGBA  _RGB32 _RGBA32  for this case is a good advance the $COLOR of version 1.4 to use HTML code scheme.


Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: child windows into window of the program: a demonstration
« Reply #5 on: January 27, 2020, 10:54:53 am »
Here's a quick and simple demo of how I'd do multiple windows like this:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) 'the main screen
  2. DIM Windows(3) AS _UNSIGNED LONG 'handles to hold extra windows
  3. FOR i = 0 TO 3: Windows(i) = _NEWIMAGE(640, 480, 32): NEXT 'make some extra windows
  4.  
  5. _DEST Windows(0) 'window 0
  6. CLS , Blue
  7. COLOR Red, 0
  8. PRINT "This is just some text on the first window, which I'm writing as an illustration.  It doesn't really mean anything, and doesn't do anything, except show that this is an independent screen, unaffected by any others."
  9.  
  10. _DEST Windows(1) 'window 1
  11. CLS , Silver
  12. LINE (100, 100)-(540, 380), Purple, BF
  13. CIRCLE (300, 300), 100, Green
  14. PAINT (300, 300), Green
  15.  
  16. _DEST Windows(2) 'window 2
  17. CLS , Yellow
  18. COLOR Red
  19. PRINT "Once upon a time, long ago and far away, Steve wrote a program in QB64!"
  20.  
  21. COLOR Black, 0
  22.     _DEST 0
  23.     CLS , 0
  24.     FOR i = 0 TO 3
  25.         LINE (100 + 163 * i, 70)-STEP(150, 20), Silver, BF
  26.         _PRINTSTRING (100 + 163 * i, 72), "      Window" + STR$(i)
  27.     NEXT
  28.     LINE (100, 100)-(740, 580), Silver, B
  29.  
  30.     _DEST Windows(3)
  31.     CLS , 0
  32.     LINE (x, 150)-STEP(100, 100), _RGB32(RND * 256, RND * 256, RND * 256), BF
  33.     x = (x + 5) MOD 640
  34.  
  35.     k = _KEYHIT
  36.     SELECT CASE k
  37.         CASE 48, 49, 50, 51: W = k - 48
  38.         CASE 27: SYSTEM
  39.     END SELECT
  40.     _PUTIMAGE (100, 100), Windows(W), 0
  41.     _LIMIT 30
  42.     _DISPLAY

I didn't bother to code in any mouse handling routine, though they'd be simple enough to add if someone wants them.  For this, just use the number keys for 0, 1, 2, 3 to swap between the 4 different window displays.

Window 0 is just a simple text window which I typed some junk on.
Window 1 is a graphical image, which could represent whatever my program needs.
Window 2 is another independent text window. 
Window 3 is an animated window where there's a simple box which scrolls from one side of the screen to the other.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #6 on: January 27, 2020, 04:10:08 pm »
Hi Steve

Your alternative way to build child windows as panel/Layer on which build output and to show on the main window is very cool. So I have decided to give another perspective to your idea, instead to use alternatively panels here the panels have different size among them and are on stack and user pressing 0123 can choose how the stack is build up. The program shows all the active panels together following the order of stack.
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) 'the main screen
  2. DIM Windows(3) AS _UNSIGNED LONG 'handles to hold extra windows
  3. FOR i = 0 TO 3: Windows(i) = _NEWIMAGE(200 + (i * 100), 400, 32): NEXT 'make some extra windows
  4.  
  5. _DEST Windows(0) 'window 0
  6. CLS , Blue
  7. COLOR Red, 0
  8. PRINT "This is just some text on the first window, which I'm writing as an illustration.  It doesn't really mean anything, and doesn't do anything, except show that this is an independent screen, unaffected by any others."
  9.  
  10. _DEST Windows(1) 'window 1
  11. CLS , Silver
  12. LINE (100, 100)-(540, 380), Purple, BF
  13. CIRCLE (300, 300), 100, Green
  14. PAINT (300, 300), Green
  15.  
  16. _DEST Windows(2) 'window 2
  17. CLS , Yellow
  18. COLOR Red
  19. PRINT "Once upon a time, long ago and far away, Steve wrote a program in QB64!"
  20.  
  21. COLOR Black, 0
  22.  
  23. DIM Zorder AS STRING
  24. Zorder = "0123"
  25.  
  26.     _DEST 0
  27.     CLS , Pink
  28.     LOCATE 10, 2: PRINT Zorder
  29.     FOR i = 0 TO 3
  30.         LINE (100 + 163 * i, 70)-STEP(150, 20), Silver, BF
  31.         _PRINTSTRING (100 + 163 * i, 72), "      Window" + STR$(i)
  32.     NEXT
  33.     LINE (100, 100)-(740, 580), Silver, B
  34.  
  35.     _DEST Windows(3)
  36.     CLS , 0
  37.     LINE (x, 150)-STEP(100, 100), _RGB32(RND * 256, RND * 256, RND * 256), BF
  38.     x = (x + 5) MOD 640
  39.  
  40.     k = _KEYHIT
  41.     SELECT CASE k
  42.         CASE 48, 49, 50, 51: W = k - 48
  43.  
  44.             z = INSTR(Zorder, LTRIM$(STR$(W)))
  45.             Zorder = LTRIM$(STR$(W)) + LEFT$(Zorder, z - 1) + RIGHT$(Zorder, 4 - z)
  46.  
  47.         CASE 27: SYSTEM
  48.     END SELECT
  49.     FOR z = 0 TO 3
  50.         W = VAL(MID$(Zorder, z, 1))
  51.         _PUTIMAGE (100, 100), Windows(W), 0
  52.     NEXT z
  53.     _LIMIT 30
  54.     _DISPLAY
  55.  
  56.  

 
ChildWinsow Steve MOD.jpg
« Last Edit: January 27, 2020, 04:12:30 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #7 on: January 28, 2020, 07:27:26 pm »
@Bplus
Here a no flickering version...
only for your eyes ... also a more smooth aspect of child windows
Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 01 25  A program with child windows into it
  10. ' we need a system to manage multiple windows
  11. ' and a system to manage input/output
  12. ' and a system to make graphic report
  13.  
  14. ' settings-------------------------------------------------------
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16. _TITLE "Child windows"
  17. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  18. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  19. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  20. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 3, aNull = 0, aQuit = 9999
  21. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  22. CONST Dragging = 300, Focusing = 200
  23.  
  24.  
  25.  
  26. 'dataset  -----------------------------------------------
  27. TYPE person
  28.     name AS STRING * 10
  29.     age AS INTEGER
  30.     weight AS INTEGER
  31.     height AS INTEGER
  32.     BMI AS INTEGER
  33.  
  34. TYPE wChild
  35.     X AS INTEGER
  36.     Y AS INTEGER
  37.     Height AS INTEGER
  38.     Zorder AS INTEGER
  39.     Status AS INTEGER
  40.  
  41. REDIM Windows(0 TO wMin) AS wChild
  42. wMax = UBOUND(windows)
  43.  
  44.  
  45. ' windows(0) is for Dragging
  46.  
  47. Windows(1).X = 1
  48. Windows(1).Y = 1
  49. Windows(1).Width = 300
  50. Windows(1).Height = 400
  51. Windows(1).Zorder = 1
  52. Windows(1).Status = Minim
  53. Windows(1).Color = Blu
  54.  
  55. Windows(2).X = 100
  56. Windows(2).Y = 1
  57. Windows(2).Width = 300
  58. Windows(2).Height = 400
  59. Windows(2).Zorder = 2
  60. Windows(2).Status = Minim
  61. Windows(2).Color = Yellow
  62.  
  63. Windows(3).X = 200
  64. Windows(3).Y = 1
  65. Windows(3).Width = 300
  66. Windows(3).Height = 400
  67. Windows(3).Zorder = 3
  68. Windows(3).Status = Minim
  69. Windows(3).Color = Green
  70.  
  71. DIM Action AS INTEGER
  72.  
  73.  
  74. ' main loop -----------------------------------------------
  75.  
  76.     ' set the main window
  77.     Action = aNull
  78.     CLS , Orange
  79.     DrawAllWin
  80.     GetInput Action
  81.     DoAction Action
  82.     _LIMIT 30
  83.  
  84. ' SUBs and FUNCTIONs --------------------------------------
  85. SUB DrawAllWin
  86.     SHARED Windows() AS wChild
  87.     DIM Finished AS INTEGER
  88.     Finished = wMax
  89.     DO
  90.         FOR a = 1 TO wMax
  91.             IF Windows(a).Zorder = Finished THEN
  92.                 DrawWindow Windows(a)
  93.                 Finished = Finished - 1
  94.                 EXIT FOR
  95.             END IF
  96.         NEXT a
  97.     LOOP UNTIL Finished = 0
  98.     _DISPLAY
  99.  
  100. SUB Focus (Index AS INTEGER)
  101.     SHARED Windows() AS wChild
  102.     DIM b AS INTEGER
  103.     FOR b = 1 TO wMax
  104.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  105.     NEXT b
  106.     SWAP Windows(Index).Zorder, Windows(b).Zorder
  107.     DrawAllWin
  108.  
  109. SUB DoAction (Act AS INTEGER)
  110.     SHARED Windows() AS wChild
  111.     DIM a AS INTEGER
  112.  
  113.     SELECT CASE Act
  114.         CASE aQuit
  115.             END
  116.  
  117.         CASE Maxim
  118.             _FULLSCREEN
  119.  
  120.         CASE Minim
  121.             _FULLSCREEN _OFF
  122.  
  123.         CASE mLeft
  124.             DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER, Actio AS INTEGER
  125.             mX = _MOUSEX
  126.             mY = _MOUSEY
  127.             ' search where and what mouse has touched by leftclick
  128.             FOR a = 1 TO wMax ' windows(0) is out of action
  129.                 Actio = IsInWindow(mX, mY, Windows(a))
  130.                 IF Actio THEN EXIT FOR ' if windows(a) is on the stack it gets the click of mouse
  131.             NEXT a
  132.             SELECT CASE Actio
  133.                 CASE Dragging
  134.                     Focus a
  135.                     Windows(0).X = Windows(a).X
  136.                     Windows(0).Y = Windows(a).Y
  137.                     Windows(0).Width = Windows(a).Width
  138.                     Windows(0).Height = Windows(a).Height
  139.                     Windows(0).Status = Windows(a).Status
  140.                     Windows(0).Color = Windows(a).Color
  141.                     OmX = _MOUSEX - Windows(0).X
  142.                     OmY = _MOUSEY - Windows(0).Y
  143.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  144.                     DO WHILE _MOUSEBUTTON(1)
  145.                         IF _MOUSEINPUT THEN
  146.                             CLS , Orange
  147.                             DrawAllWin
  148.                             Windows(0).X = (_MOUSEX - OmX)
  149.                             Windows(0).Y = (_MOUSEY - OmY)
  150.                             dragWindow Windows(0)
  151.                         END IF
  152.                     LOOP
  153.                     ' new position of window
  154.                     Windows(a).X = Windows(0).X
  155.                     Windows(a).Y = Windows(0).Y
  156.                     Windows(a).Width = Windows(0).Width
  157.                     Windows(a).Height = Windows(0).Height
  158.                     Windows(a).Status = Windows(0).Status
  159.                     Windows(a).Color = Windows(0).Color
  160.                     Windows(a).Zorder = 1
  161.                 CASE Focusing
  162.                     Focus a
  163.             END SELECT
  164.  
  165.         CASE ELSE
  166.     END SELECT
  167.  
  168. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  169.     IsInWindow = mFalse
  170.     IF IsInTheRange%(X, Win.X, Win.X + Win.Width) THEN
  171.         IF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  172.             IsInWindow = Dragging
  173.         ELSEIF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  174.             IsInWindow = Focusing
  175.         END IF
  176.     END IF
  177.  
  178. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  179.     IF Min > Max THEN SWAP Min, Max
  180.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  181.  
  182. SUB dragWindow (Win AS wChild)
  183.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  184.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  185.     _DISPLAY
  186.  
  187.  
  188. SUB DrawWindow (Win AS wChild)
  189.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  190.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  191.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  192.     LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  193.     LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  194.  
  195. SUB GetInput (Act AS INTEGER)
  196.     DIM mInput AS INTEGER
  197.  
  198.  
  199.     ' keyboard input
  200.     a$ = INKEY$
  201.     IF a$ = CHR$(27) THEN Act = aQuit
  202.  
  203.     'mouse input
  204.     mInput = mFalse
  205.     IF _MOUSEINPUT THEN mInput = mTrue
  206.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  207.     LOOP
  208.     IF mInput THEN
  209.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  210.             mInput = mLR
  211.         ELSEIF _MOUSEBUTTON(1) THEN
  212.             mInput = mLeft
  213.         ELSEIF _MOUSEBUTTON(2) THEN
  214.             mInput = mRight
  215.         ELSEIF _MOUSEBUTTON(3) THEN
  216.             mInput = mMiddle
  217.         END IF
  218.     END IF
  219.  
  220.     IF mInput = mLR THEN
  221.         Act = aQuit
  222.     ELSEIF mInput = mMiddle THEN
  223.         Act = Minim
  224.     ELSEIF mInput = mRight THEN
  225.         Act = Maxim
  226.     ELSEIF mInput = mLeft THEN
  227.         Act = mInput
  228.     END IF

 
ChildWindows_No_Flickering.jpg
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #8 on: January 28, 2020, 10:28:58 pm »
Very nice start TempodiBasic they drag nicely alright and fetching colors too :)

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #9 on: January 28, 2020, 10:40:45 pm »
looks like something I've been trying to accomplish for a long time.

Well, here's my attempt:
http://keybone.epizy.com/files/234178487/winsys.bas

The windows can be moved, resized, maximized, and restored from maximized (if the functionality is enabled on a per-window basis).
Minimize/iconify functionality is not implemented yet.

And I havent figured out how im going to have events handled within the windows yet.
Still a work in progress...
« Last Edit: January 28, 2020, 11:37:14 pm by keybone »
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #10 on: January 29, 2020, 09:22:53 am »
Fine Keybone!

... I have seen that also rightclick menu is work in progress. Good one!


about
Quote
And I havent figured out how im going to have events handled within the windows yet.
Still a work in progress...
I think that there are so many ways to do this....

for interaction among objects of the same window or objects of different windows  I can imagine a timer control that activates a short loop or a message system like windows OS...
for events triggered by I/O of user  I imagine a defauld univocal keypress (keyboard or joystick) or area of screen sensible to mouse events or /and a focus system to address and to react in the right manner to the Input (you get the input and pass it to the focused object)
... well , after lunch these are the results of my imagination...
Good work and Good Imagination!
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #11 on: February 05, 2020, 07:39:57 pm »
Hi
I go on with child windows...
now there are 3 button on the bar of the window to Maximize to the application window or to Restore default dimension or to reduce to the bar of the child window.
Here the code.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 05 fixed a minor bug on mouse click events
  9. '            activated events Maxim Minim and Closed
  10.  
  11.  
  12. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  13. '            removed vMax SHARED variable
  14. '            added 3 buttons on the rightest site of the bar of the child window
  15. '            SUB wClosed, wMaxim, wMinim
  16. '            In this version the user can maximize one child window to the application window
  17. '            In the status of Maxim the child window has the focus and can be only
  18. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  19.  
  20.  
  21. ' 2020 01 30 fixed bug on focusing a child window
  22. '
  23.  
  24. ' 2020 01 25  A program with child windows into it
  25. ' we need a system to manage multiple windows
  26. ' and a system to manage input/output
  27. ' and a system to make graphic report
  28.  
  29. ' settings-------------------------------------------------------
  30. SCREEN _NEWIMAGE(800, 600, 32)
  31. _TITLE "Child windows"
  32. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  33. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  34. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  35. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 5, aNull = 0, aQuit = 9999
  36. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  37. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  38.  
  39.  
  40.  
  41. 'dataset  -----------------------------------------------
  42. TYPE person
  43.     name AS STRING * 10
  44.     age AS INTEGER
  45.     weight AS INTEGER
  46.     height AS INTEGER
  47.     BMI AS INTEGER
  48.  
  49. TYPE wChild
  50.     X AS INTEGER
  51.     Y AS INTEGER
  52.     Height AS INTEGER
  53.     Zorder AS INTEGER
  54.     Status AS INTEGER
  55.  
  56. REDIM Windows(0 TO wMin) AS wChild
  57.  
  58. InitWin
  59.  
  60. DIM Action AS INTEGER
  61.  
  62.  
  63. ' main loop -----------------------------------------------
  64.  
  65.     ' set the main window
  66.     Action = aNull
  67.     CLS , Orange
  68.     DrawAllWin
  69.     GetInput Action
  70.     DoAction Action
  71.     _LIMIT 30
  72.  
  73. ' SUBs and FUNCTIONs --------------------------------------
  74. SUB InitWin
  75.     SHARED Windows() AS wChild
  76.     ' windows(0) is for Dragging or Maximize
  77.     Windows(0).X = 0
  78.     Windows(0).Y = 0
  79.     Windows(0).Width = 0
  80.     Windows(0).Height = 0
  81.     Windows(0).Zorder = 0
  82.     Windows(0).Status = 0
  83.     Windows(0).Color = 0
  84.  
  85.     Windows(1).X = 1
  86.     Windows(1).Y = 1
  87.     Windows(1).Width = 300
  88.     Windows(1).Height = 400
  89.     Windows(1).Zorder = 1
  90.     Windows(1).Status = Minim
  91.     Windows(1).Color = Blu
  92.  
  93.     Windows(2).X = 100
  94.     Windows(2).Y = 1
  95.     Windows(2).Width = 300
  96.     Windows(2).Height = 400
  97.     Windows(2).Zorder = 2
  98.     Windows(2).Status = Minim
  99.     Windows(2).Color = Yellow
  100.  
  101.     Windows(3).X = 200
  102.     Windows(3).Y = 1
  103.     Windows(3).Width = 300
  104.     Windows(3).Height = 400
  105.     Windows(3).Zorder = 3
  106.     Windows(3).Status = Minim
  107.     Windows(3).Color = Green
  108.  
  109.     Windows(4).X = 300
  110.     Windows(4).Y = 1
  111.     Windows(4).Width = 300
  112.     Windows(4).Height = 400
  113.     Windows(4).Zorder = 4
  114.     Windows(4).Status = Minim
  115.     Windows(4).Color = Red
  116.  
  117.     Windows(5).X = 400
  118.     Windows(5).Y = 1
  119.     Windows(5).Width = 300
  120.     Windows(5).Height = 400
  121.     Windows(5).Zorder = 5
  122.     Windows(5).Status = Minim
  123.     Windows(5).Color = Cyan
  124.  
  125. SUB DrawAllWin
  126.     SHARED Windows() AS wChild
  127.     DIM Finished AS INTEGER
  128.     Finished = wMin
  129.     DO
  130.         FOR a = 1 TO wMin
  131.             IF Windows(a).Zorder = Finished THEN
  132.                 DrawWindow Windows(a)
  133.                 Finished = Finished - 1
  134.                 EXIT FOR
  135.             END IF
  136.         NEXT a
  137.     LOOP UNTIL Finished = 0
  138.     _DISPLAY
  139.  
  140. SUB Focus (Index AS INTEGER)
  141.     SHARED Windows() AS wChild
  142.     DIM b AS INTEGER
  143.     FOR b = 1 TO wMin
  144.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  145.     NEXT b
  146.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  147.     DrawAllWin
  148.  
  149.  
  150. SUB DoAction (Act AS INTEGER)
  151.     SHARED Windows() AS wChild
  152.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  153.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  154.  
  155.     SELECT CASE Act
  156.         CASE aQuit
  157.             END
  158.  
  159.         CASE Maxim
  160.             _FULLSCREEN
  161.  
  162.         CASE Minim
  163.             _FULLSCREEN _OFF
  164.  
  165.         CASE mLeft
  166.             mX = _MOUSEX
  167.             mY = _MOUSEY
  168.  
  169.             ' search where and what mouse has touched by leftclick
  170.             OldA = 0
  171.             OldActio = 0
  172.             FOR a = 1 TO wMin ' windows(0) is out of action
  173.                 Actio = IsInWindow(mX, mY, Windows(a))
  174.                 IF Actio THEN
  175.                     IF OldA <= 0 THEN
  176.                         OldA = a
  177.                         OldActio = Actio
  178.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  179.                         OldA = a
  180.                         OldActio = Actio
  181.                     END IF
  182.                 END IF
  183.             NEXT a
  184.             IF a > OldA THEN
  185.                 a = OldA ' restore the last windows interacting
  186.                 Actio = OldActio
  187.             END IF
  188.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  189.  
  190.  
  191.             Focus a 'set zorder on the (a) window that gets the input
  192.  
  193.  
  194.             SELECT CASE Actio
  195.                 CASE cMinim
  196.                     ' here restore to  standard status of child window
  197.                     IF NOT Windows(a).Status = Minim THEN
  198.                         Windows(a).X = Windows(0).X
  199.                         Windows(a).Y = Windows(0).Y
  200.                         Windows(a).Width = Windows(0).Width
  201.                         Windows(a).Height = Windows(0).Height
  202.                         Windows(a).Status = Minim
  203.                         Windows(a).Zorder = 1
  204.                     END IF
  205.  
  206.                 CASE cMaxim
  207.                     ' here convert the window to full size of main window of the program
  208.                     IF NOT Windows(a).Status = Maxim THEN
  209.                         ' memorize window's data
  210.                         Windows(0).X = Windows(a).X
  211.                         Windows(0).Y = Windows(a).Y
  212.                         Windows(0).Width = Windows(a).Width
  213.                         Windows(0).Height = Windows(a).Height
  214.                         ' change status
  215.                         Windows(a).Status = Maxim
  216.                         Windows(a).Width = _WIDTH
  217.                         Windows(a).Height = _HEIGHT
  218.                         Windows(a).X = 1
  219.                         Windows(a).Y = 1
  220.                     END IF
  221.                 CASE cClosed
  222.                     ' here minimize the child window to its window bar
  223.                     IF Windows(a).Status = Minim THEN
  224.                         ' memorize window's data
  225.                         Windows(0).X = Windows(a).X
  226.                         Windows(0).Y = Windows(a).Y
  227.                         Windows(0).Width = Windows(a).Width
  228.                         Windows(0).Height = Windows(a).Height
  229.                         ' change status
  230.                         Windows(a).Status = Closed
  231.                     END IF
  232.                 CASE Dragging
  233.                     ' dragging is not possible for maximized window
  234.                     ' but it is possible for status Minim child window and
  235.                     ' for status Closed that shows only Bar window
  236.                     IF NOT Windows(a).Status = Maxim THEN
  237.                         Windows(0).X = Windows(a).X
  238.                         Windows(0).Y = Windows(a).Y
  239.                         Windows(0).Width = Windows(a).Width
  240.                         Windows(0).Height = Windows(a).Height
  241.                         Windows(0).Status = Windows(a).Status
  242.                         Windows(0).Color = Windows(a).Color
  243.                         OmX = _MOUSEX - Windows(0).X
  244.                         OmY = _MOUSEY - Windows(0).Y
  245.                         DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  246.                         DO WHILE _MOUSEBUTTON(1)
  247.                             IF _MOUSEINPUT THEN
  248.                                 CLS , Orange
  249.                                 DrawAllWin
  250.                                 Windows(0).X = (_MOUSEX - OmX)
  251.                                 Windows(0).Y = (_MOUSEY - OmY)
  252.                                 dragWindow Windows(0)
  253.                             END IF
  254.                         LOOP
  255.                         ' new position of window
  256.                         Windows(a).X = Windows(0).X
  257.                         Windows(a).Y = Windows(0).Y
  258.                         Windows(a).Width = Windows(0).Width
  259.                         Windows(a).Height = Windows(0).Height
  260.                         Windows(a).Status = Windows(0).Status
  261.                         Windows(a).Color = Windows(0).Color
  262.                         Windows(a).Zorder = 1
  263.                     END IF
  264.                 CASE Focusing
  265.                     Focus a
  266.             END SELECT
  267.  
  268.         CASE ELSE
  269.     END SELECT
  270.  
  271. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  272.     IsInWindow = mFalse
  273.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  274.         ' if window is closed to its bar it cannot get focus on the window area
  275.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status <> Closed) THEN IsInWindow = Focusing
  276.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  277.         ' if is the window bar area
  278.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  279.             ' if it is to the left of buttons on the bar
  280.             ' maximized window cannot be dragged
  281.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = Dragging
  282.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  283.             ' if it is on the leftest button on the bar
  284.             IsInWindow = cMinim ' icon minimize--> restore to child default
  285.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  286.             ' if it is on the middle button on the bar
  287.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  288.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  289.             ' if is on the rightest button on the bar
  290.             ' maximized child window cannot become minimized to bar of child window
  291.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  292.         END IF
  293.     END IF
  294.  
  295. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  296.     IF Min > Max THEN SWAP Min, Max
  297.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  298.  
  299. SUB dragWindow (Win AS wChild)
  300.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  301.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  302.     _DISPLAY
  303.  
  304. SUB wClosed (Win AS wChild)
  305.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  306.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  307.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  308.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  309.  
  310. SUB wMaxim (win AS wChild)
  311.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  312.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  313.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  314.  
  315. SUB wMinim (Win AS wChild)
  316.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  317.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  318.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  319.  
  320.  
  321. SUB DrawWindow (Win AS wChild)
  322.     ' the window
  323.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  324.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  325.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  326.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  327.     END IF
  328.     ' the status bar
  329.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  330.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  331.     wMinim Win
  332.     wMaxim Win
  333.     wClosed Win
  334.  
  335. SUB GetInput (Act AS INTEGER)
  336.     DIM mInput AS INTEGER
  337.  
  338.  
  339.     ' keyboard input
  340.     a$ = INKEY$
  341.     IF a$ = CHR$(27) THEN Act = aQuit
  342.  
  343.     'mouse input
  344.     mInput = mFalse
  345.     IF _MOUSEINPUT THEN mInput = mTrue
  346.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  347.     LOOP
  348.     IF mInput THEN
  349.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  350.             mInput = mLR
  351.         ELSEIF _MOUSEBUTTON(1) THEN
  352.             mInput = mLeft
  353.         ELSEIF _MOUSEBUTTON(2) THEN
  354.             mInput = mRight
  355.         ELSEIF _MOUSEBUTTON(3) THEN
  356.             mInput = mMiddle
  357.         END IF
  358.     END IF
  359.  
  360.     IF mInput = mLR THEN
  361.         Act = aQuit
  362.     ELSEIF mInput = mMiddle THEN
  363.         Act = Minim
  364.     ELSEIF mInput = mRight THEN
  365.         Act = Maxim
  366.     ELSEIF mInput = mLeft THEN
  367.         Act = mInput
  368.     END IF
  369.  

Thanks to try
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #12 on: February 09, 2020, 04:44:17 am »
another step forward, for each window a shadow of info
it fixs a bug of the previous version that stack the chil windows on the same position if you close more windows at different positions and then you click on restore/minimize button (the first from the left) on the windows bar.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 02 08  using a second array we store windows information indipendently so
  10. '             now each window can be modified and restored
  11.  
  12.  
  13. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  14. '             to it the last value used in windows(0) so the info of the last
  15. '             window that is dragged or maximize when we use Minimize button on
  16. '             another child window
  17. '             the fix can be got using a shadow array that stores windows informations
  18. '             or windows(0) as the child window that takes the information of the
  19. '             child window that must be acted (Minimize, Maximize and Closed)
  20. '             and we use it as template to make graphic output
  21.  
  22. ' 2020 02 05 fixed a minor bug on mouse click events
  23. '            activated events Maxim Minim and Closed
  24.  
  25.  
  26. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  27. '            removed vMax SHARED variable
  28. '            added 3 buttons on the rightest site of the bar of the child window
  29. '            SUB wClosed, wMaxim, wMinim
  30. '            In this version the user can maximize one child window to the application window
  31. '            In the status of Maxim the child window has the focus and can be only
  32. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  33.  
  34.  
  35. ' 2020 01 30 fixed bug on focusing a child window
  36. '
  37.  
  38. ' 2020 01 25  A program with child windows into it
  39. ' we need a system to manage multiple windows
  40. ' and a system to manage input/output
  41. ' and a system to make graphic report
  42.  
  43. ' settings-------------------------------------------------------
  44. SCREEN _NEWIMAGE(800, 600, 32)
  45. _TITLE "Child windows"
  46. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  47. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  48. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  49. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 5, aNull = 0, aQuit = 9999
  50. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  51. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  52.  
  53.  
  54.  
  55. 'dataset  -----------------------------------------------
  56. TYPE person
  57.     name AS STRING * 10
  58.     age AS INTEGER
  59.     weight AS INTEGER
  60.     height AS INTEGER
  61.     BMI AS INTEGER
  62.  
  63. TYPE wChild
  64.     X AS INTEGER
  65.     Y AS INTEGER
  66.     Height AS INTEGER
  67.     Zorder AS INTEGER
  68.     Status AS INTEGER
  69.  
  70. REDIM Windows(1 TO wMin) AS wChild, OldW(1 TO wMin) AS wChild
  71.  
  72. InitWin
  73.  
  74. DIM Action AS INTEGER
  75.  
  76.  
  77. ' main loop -----------------------------------------------
  78.  
  79.     ' set the main window
  80.     Action = aNull
  81.     CLS , Orange
  82.     DrawAllWin
  83.     GetInput Action
  84.     DoAction Action
  85.     _DISPLAY
  86.     _LIMIT 30
  87.  
  88. ' SUBs and FUNCTIONs --------------------------------------
  89. SUB InitWin
  90.     SHARED Windows() AS wChild, OldW() AS wChild
  91.     DIM a AS INTEGER
  92.  
  93.     Windows(1).X = 1
  94.     Windows(1).Y = 1
  95.     Windows(1).Width = 300
  96.     Windows(1).Height = 400
  97.     Windows(1).Zorder = 1
  98.     Windows(1).Status = Minim
  99.     Windows(1).Color = Blu
  100.  
  101.     Windows(2).X = 100
  102.     Windows(2).Y = 1
  103.     Windows(2).Width = 300
  104.     Windows(2).Height = 400
  105.     Windows(2).Zorder = 2
  106.     Windows(2).Status = Minim
  107.     Windows(2).Color = Yellow
  108.  
  109.     Windows(3).X = 200
  110.     Windows(3).Y = 1
  111.     Windows(3).Width = 300
  112.     Windows(3).Height = 400
  113.     Windows(3).Zorder = 3
  114.     Windows(3).Status = Minim
  115.     Windows(3).Color = Green
  116.  
  117.     Windows(4).X = 300
  118.     Windows(4).Y = 1
  119.     Windows(4).Width = 300
  120.     Windows(4).Height = 400
  121.     Windows(4).Zorder = 4
  122.     Windows(4).Status = Minim
  123.     Windows(4).Color = Red
  124.  
  125.     Windows(5).X = 400
  126.     Windows(5).Y = 1
  127.     Windows(5).Width = 300
  128.     Windows(5).Height = 400
  129.     Windows(5).Zorder = 5
  130.     Windows(5).Status = Minim
  131.     Windows(5).Color = Cyan
  132.  
  133.     FOR a = 1 TO wMin STEP 1
  134.         AdjournWin a
  135.     NEXT a
  136.  
  137. SUB RestoreWin (a AS INTEGER)
  138.     SHARED Windows() AS wChild, OldW() AS wChild
  139.  
  140.     Windows(a).X = OldW(a).X
  141.     Windows(a).Y = OldW(a).Y
  142.     Windows(a).Width = OldW(a).Width
  143.     Windows(a).Height = OldW(a).Height
  144.     Windows(a).Zorder = OldW(a).Zorder
  145.     Windows(a).Color = OldW(a).Color
  146.  
  147. SUB AdjournWin (a AS INTEGER)
  148.     SHARED Windows() AS wChild, OldW() AS wChild
  149.  
  150.     OldW(a).X = Windows(a).X
  151.     OldW(a).Y = Windows(a).Y
  152.     OldW(a).Width = Windows(a).Width
  153.     OldW(a).Height = Windows(a).Height
  154.     OldW(a).Zorder = Windows(a).Zorder
  155.     OldW(a).Color = Windows(a).Color
  156.  
  157. SUB DrawAllWin
  158.     SHARED Windows() AS wChild
  159.     DIM Finished AS INTEGER
  160.     Finished = wMin
  161.     DO
  162.         FOR a = 1 TO wMin
  163.             IF Windows(a).Zorder = Finished THEN
  164.                 DrawWindow Windows(a)
  165.                 Finished = Finished - 1
  166.                 EXIT FOR
  167.             END IF
  168.         NEXT a
  169.     LOOP UNTIL Finished = 0
  170.  
  171. SUB Focus (Index AS INTEGER)
  172.     SHARED Windows() AS wChild
  173.     DIM b AS INTEGER
  174.     FOR b = 1 TO wMin
  175.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  176.     NEXT b
  177.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  178.     DrawAllWin
  179.  
  180.  
  181. SUB DoAction (Act AS INTEGER)
  182.     SHARED Windows() AS wChild, OldW() AS wChild
  183.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  184.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  185.  
  186.     SELECT CASE Act
  187.         CASE aQuit
  188.             END
  189.  
  190.         CASE Maxim
  191.             _FULLSCREEN
  192.  
  193.         CASE Minim
  194.             _FULLSCREEN _OFF
  195.  
  196.         CASE mLeft
  197.             mX = _MOUSEX
  198.             mY = _MOUSEY
  199.  
  200.             ' search where and what mouse has touched by leftclick
  201.             OldA = 0
  202.             OldActio = 0
  203.             FOR a = 1 TO wMin ' windows(0) is out of action
  204.                 Actio = IsInWindow(mX, mY, Windows(a))
  205.                 IF Actio THEN
  206.                     IF OldA <= 0 THEN
  207.                         OldA = a
  208.                         OldActio = Actio
  209.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  210.                         OldA = a
  211.                         OldActio = Actio
  212.                     END IF
  213.                 END IF
  214.             NEXT a
  215.             IF a > OldA THEN
  216.                 a = OldA ' restore the last windows interacting
  217.                 Actio = OldActio
  218.             END IF
  219.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  220.  
  221.  
  222.             Focus a 'set zorder on the (a) window that gets the input
  223.  
  224.  
  225.             SELECT CASE Actio
  226.                 CASE cMinim
  227.                     ' here restore to  standard status of child window
  228.                     IF NOT Windows(a).Status = Minim THEN
  229.                         RestoreWin a
  230.                         Windows(a).Status = Minim
  231.                     END IF
  232.  
  233.                 CASE cMaxim
  234.                     ' here convert the window to full size of main window of the program
  235.                     IF NOT Windows(a).Status = Maxim THEN
  236.                         ' memorize window's data
  237.                         AdjournWin a
  238.                         ' change status
  239.                         Windows(a).Status = Maxim
  240.                         Windows(a).Width = _WIDTH
  241.                         Windows(a).Height = _HEIGHT
  242.                         Windows(a).X = 1
  243.                         Windows(a).Y = 1
  244.                     END IF
  245.                 CASE cClosed
  246.                     ' here minimize the child window to its window bar
  247.                     IF Windows(a).Status = Minim THEN
  248.                         'save data of window
  249.                         AdjournWin a
  250.                         ' change status
  251.                         Windows(a).Status = Closed
  252.                     END IF
  253.                 CASE Dragging
  254.                     ' dragging is not possible for maximized window
  255.                     ' but it is possible for status Minim child window and
  256.                     ' for status Closed that shows only Bar window
  257.                     IF NOT Windows(a).Status = Maxim THEN
  258.                         AdjournWin a
  259.                         OmX = _MOUSEX - OldW(a).X
  260.                         OmY = _MOUSEY - OldW(a).Y
  261.                         DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  262.                         DO WHILE _MOUSEBUTTON(1)
  263.                             IF _MOUSEINPUT THEN
  264.                                 CLS , Orange
  265.  
  266.                                 OldW(a).X = (_MOUSEX - OmX)
  267.                                 OldW(a).Y = (_MOUSEY - OmY)
  268.                                 DrawAllWin
  269.                                 dragWindow OldW(a)
  270.                             END IF
  271.                         LOOP
  272.                         ' new position of window
  273.                         RestoreWin a
  274.                     END IF
  275.                 CASE Focusing
  276.                     Focus a
  277.             END SELECT
  278.  
  279.         CASE ELSE
  280.     END SELECT
  281.  
  282. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  283.     IsInWindow = mFalse
  284.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  285.         ' if window is closed to its bar it cannot get focus on the window area
  286.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status <> Closed) THEN IsInWindow = Focusing
  287.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  288.         ' if is the window bar area
  289.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  290.             ' if it is to the left of buttons on the bar
  291.             ' maximized window cannot be dragged
  292.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = Dragging
  293.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  294.             ' if it is on the leftest button on the bar
  295.             IsInWindow = cMinim ' icon minimize--> restore to child default
  296.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  297.             ' if it is on the middle button on the bar
  298.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  299.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  300.             ' if is on the rightest button on the bar
  301.             ' maximized child window cannot become minimized to bar of child window
  302.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  303.         END IF
  304.     END IF
  305.  
  306. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  307.     IF Min > Max THEN SWAP Min, Max
  308.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  309.  
  310. SUB dragWindow (Win AS wChild)
  311.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  312.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  313.     _DISPLAY
  314.  
  315. SUB wClosed (Win AS wChild)
  316.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  317.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  318.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  319.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  320.  
  321. SUB wMaxim (win AS wChild)
  322.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  323.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  324.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  325.  
  326. SUB wMinim (Win AS wChild)
  327.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  328.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  329.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  330.  
  331.  
  332. SUB DrawWindow (Win AS wChild)
  333.     ' the window
  334.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  335.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  336.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  337.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  338.     END IF
  339.     ' the status bar
  340.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  341.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  342.     wMinim Win
  343.     wMaxim Win
  344.     wClosed Win
  345.  
  346. SUB GetInput (Act AS INTEGER)
  347.     DIM mInput AS INTEGER
  348.  
  349.  
  350.     ' keyboard input
  351.     a$ = INKEY$
  352.     IF a$ = CHR$(27) THEN Act = aQuit
  353.  
  354.     'mouse input
  355.     mInput = mFalse
  356.     IF _MOUSEINPUT THEN mInput = mTrue
  357.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  358.     LOOP
  359.     IF mInput THEN
  360.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  361.             mInput = mLR
  362.         ELSEIF _MOUSEBUTTON(1) THEN
  363.             mInput = mLeft
  364.         ELSEIF _MOUSEBUTTON(2) THEN
  365.             mInput = mRight
  366.         ELSEIF _MOUSEBUTTON(3) THEN
  367.             mInput = mMiddle
  368.         END IF
  369.     END IF
  370.  
  371.     IF mInput = mLR THEN
  372.         Act = aQuit
  373.     ELSEIF mInput = mMiddle THEN
  374.         Act = Minim
  375.     ELSEIF mInput = mRight THEN
  376.         Act = Maxim
  377.     ELSEIF mInput = mLeft THEN
  378.         Act = mInput
  379.     END IF
wchild3 demo.jpg
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #13 on: February 09, 2020, 06:17:39 pm »
Hi
here a more complex but versatle system of windowing child windows

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 09  with the power of the second array we implement a different
  9. '             child windows' system:
  10. '             all child windows can be Closed to window's bar
  11. '             all child windows can be dragged on the screen
  12.  
  13. ' 2020 02 08  using a second array we store windows information indipendently so
  14. '             now each window can be modified and restored
  15.  
  16.  
  17. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  18. '             to it the last value used in windows(0) so the info of the last
  19. '             window that is dragged or maximize when we use Minimize button on
  20. '             another child window
  21. '             the fix can be got using a shadow array that stores windows informations
  22. '             or windows(0) as the child window that takes the information of the
  23. '             child window that must be acted (Minimize, Maximize and Closed)
  24. '             and we use it as template to make graphic output
  25.  
  26. ' 2020 02 05 fixed a minor bug on mouse click events
  27. '            activated events Maxim Minim and Closed
  28.  
  29.  
  30. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  31. '            removed vMax SHARED variable
  32. '            added 3 buttons on the rightest site of the bar of the child window
  33. '            SUB wClosed, wMaxim, wMinim
  34. '            In this version the user can maximize one child window to the application window
  35. '            In the status of Maxim the child window has the focus and can be only
  36. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  37.  
  38.  
  39. ' 2020 01 30 fixed bug on focusing a child window
  40. '
  41.  
  42. ' 2020 01 25  A program with child windows into it
  43. ' we need a system to manage multiple windows
  44. ' and a system to manage input/output
  45. ' and a system to make graphic report
  46.  
  47. ' settings-------------------------------------------------------
  48. SCREEN _NEWIMAGE(800, 600, 32)
  49. _TITLE "Child windows"
  50. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  51. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  52. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  53. CONST Minim = 10, Maxim = 20, Closed = 100
  54. CONST wMin = 5, aNull = 0, aQuit = 9999
  55. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  56. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  57.  
  58.  
  59.  
  60. 'dataset  -----------------------------------------------
  61. TYPE person
  62.     name AS STRING * 10
  63.     age AS INTEGER
  64.     weight AS INTEGER
  65.     height AS INTEGER
  66.     BMI AS INTEGER
  67.  
  68. TYPE wChild
  69.     X AS INTEGER
  70.     Y AS INTEGER
  71.     Height AS INTEGER
  72.     Zorder AS INTEGER
  73.     Status AS INTEGER
  74.  
  75. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  76.  
  77. InitWin
  78.  
  79. DIM Action AS INTEGER
  80.  
  81.  
  82. ' main loop -----------------------------------------------
  83.  
  84.     ' set the main window
  85.     Action = aNull
  86.     CLS , Orange
  87.     DrawAllWin
  88.     GetInput Action
  89.     DoAction Action
  90.     _DISPLAY
  91.     _LIMIT 30
  92.  
  93. ' SUBs and FUNCTIONs --------------------------------------
  94. SUB InitWin
  95.     SHARED Windows() AS wChild, OldW() AS wChild
  96.     DIM a AS INTEGER
  97.  
  98.     Windows(1).X = 1
  99.     Windows(1).Y = 1
  100.     Windows(1).Width = 300
  101.     Windows(1).Height = 400
  102.     Windows(1).Zorder = 1
  103.     Windows(1).Status = Minim
  104.     Windows(1).Color = Blu
  105.  
  106.     Windows(2).X = 100
  107.     Windows(2).Y = 1
  108.     Windows(2).Width = 300
  109.     Windows(2).Height = 400
  110.     Windows(2).Zorder = 2
  111.     Windows(2).Status = Minim
  112.     Windows(2).Color = Yellow
  113.  
  114.     Windows(3).X = 200
  115.     Windows(3).Y = 1
  116.     Windows(3).Width = 300
  117.     Windows(3).Height = 400
  118.     Windows(3).Zorder = 3
  119.     Windows(3).Status = Minim
  120.     Windows(3).Color = Green
  121.  
  122.     Windows(4).X = 300
  123.     Windows(4).Y = 1
  124.     Windows(4).Width = 300
  125.     Windows(4).Height = 400
  126.     Windows(4).Zorder = 4
  127.     Windows(4).Status = Minim
  128.     Windows(4).Color = Red
  129.  
  130.     Windows(5).X = 400
  131.     Windows(5).Y = 1
  132.     Windows(5).Width = 300
  133.     Windows(5).Height = 400
  134.     Windows(5).Zorder = 5
  135.     Windows(5).Status = Minim
  136.     Windows(5).Color = Cyan
  137.  
  138.     FOR a = 1 TO wMin STEP 1
  139.         AdjournWin a
  140.     NEXT a
  141.  
  142. SUB RestoreWin (a AS INTEGER)
  143.     SHARED Windows() AS wChild, OldW() AS wChild
  144.  
  145.     Windows(a).X = OldW(a).X
  146.     Windows(a).Y = OldW(a).Y
  147.     Windows(a).Width = OldW(a).Width
  148.     Windows(a).Height = OldW(a).Height
  149.     Windows(a).Zorder = OldW(a).Zorder
  150.     Windows(a).Color = OldW(a).Color
  151.  
  152. SUB AdjournWin (a AS INTEGER)
  153.     SHARED Windows() AS wChild, OldW() AS wChild
  154.  
  155.     OldW(a).X = Windows(a).X
  156.     OldW(a).Y = Windows(a).Y
  157.     OldW(a).Width = Windows(a).Width
  158.     OldW(a).Height = Windows(a).Height
  159.     OldW(a).Zorder = Windows(a).Zorder
  160.     OldW(a).Color = Windows(a).Color
  161.  
  162. SUB DrawAllWin
  163.     SHARED Windows() AS wChild
  164.     DIM Finished AS INTEGER
  165.     Finished = wMin
  166.     DO
  167.         FOR a = 1 TO wMin
  168.             IF Windows(a).Zorder = Finished THEN
  169.                 DrawWindow Windows(a)
  170.                 Finished = Finished - 1
  171.                 EXIT FOR
  172.             END IF
  173.         NEXT a
  174.     LOOP UNTIL Finished = 0
  175.  
  176. SUB Focus (Index AS INTEGER)
  177.     SHARED Windows() AS wChild
  178.     DIM b AS INTEGER
  179.     FOR b = 1 TO wMin
  180.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  181.     NEXT b
  182.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  183.     DrawAllWin
  184.  
  185.  
  186. SUB DoAction (Act AS INTEGER)
  187.     SHARED Windows() AS wChild, OldW() AS wChild
  188.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  189.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  190.  
  191.     SELECT CASE Act
  192.         CASE aQuit
  193.             END
  194.  
  195.         CASE Maxim
  196.             _FULLSCREEN
  197.  
  198.         CASE Minim
  199.             _FULLSCREEN _OFF
  200.  
  201.         CASE mLeft
  202.             mX = _MOUSEX
  203.             mY = _MOUSEY
  204.  
  205.             ' search where and what mouse has touched by leftclick
  206.             OldA = 0
  207.             OldActio = 0
  208.             FOR a = 1 TO wMin ' windows(0) is out of action
  209.                 Actio = IsInWindow(mX, mY, Windows(a))
  210.                 IF Actio THEN
  211.                     IF OldA <= 0 THEN
  212.                         OldA = a
  213.                         OldActio = Actio
  214.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  215.                         OldA = a
  216.                         OldActio = Actio
  217.                     END IF
  218.                 END IF
  219.             NEXT a
  220.             IF a > OldA THEN
  221.                 a = OldA ' restore the last windows interacting
  222.                 Actio = OldActio
  223.             END IF
  224.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  225.  
  226.  
  227.             Focus a 'set zorder on the (a) window that gets the input
  228.  
  229.  
  230.             SELECT CASE Actio
  231.                 CASE cMinim
  232.                     ' here restore to  standard (bar + area of window) status of child window
  233.                     IF Windows(a).Status = Closed + Maxim THEN
  234.                         ' if windows is a closed maximized window
  235.                         ' we restore its status of maximized
  236.                         Windows(a).Status = Maxim
  237.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  238.                         ' if windows is a closed minimized window
  239.                         ' we restore its status of minimized
  240.                         Windows(a).Status = Minim
  241.                     ELSEIF Windows(a).Status = Maxim THEN
  242.                         ' if is a window maximized it gets back all info setting
  243.                         ' we restore its status of minimized
  244.                         RestoreWin a
  245.                         Windows(a).Status = Minim
  246.                     END IF
  247.  
  248.  
  249.                 CASE cMaxim
  250.                     ' here convert the window to full size of main window of the program
  251.                     ' OR gives 1 if both parameter are true or al last one is true
  252.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  253.                         ' it acts if windows if not still maximized
  254.                         ' it is minimized window opened or closed
  255.                         ' memorize window's data when it is not maximized
  256.                         '                        IF Windows(a).Width < _WIDTH THEN
  257.                         AdjournWin a
  258.                         ' it sets maximized status
  259.                         Windows(a).Width = _WIDTH
  260.                         Windows(a).Height = _HEIGHT
  261.                         Windows(a).X = 1
  262.                         Windows(a).Y = 1
  263.                         ' change status
  264.                         Windows(a).Status = Maxim
  265.                     END IF
  266.  
  267.                 CASE cClosed
  268.                     ' here minimize the child window to its window bar
  269.                     IF NOT Windows(a).Status > Closed THEN
  270.                         Windows(a).Status = Windows(a).Status + Closed
  271.                     END IF
  272.  
  273.                 CASE Dragging
  274.                     ' dragging is possible for all status of windows
  275.                     '
  276.                     ' if minimized or Closed and minimized window we save data info
  277.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  278.                     ' it sets variables for dragging
  279.                     OldW(0).X = Windows(a).X
  280.                     OldW(0).Y = Windows(a).Y
  281.                     OldW(0).Width = Windows(a).Width
  282.                     OldW(0).Height = Windows(a).Height
  283.  
  284.                     OmX = _MOUSEX - OldW(0).X
  285.                     OmY = _MOUSEY - OldW(0).Y
  286.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  287.                     DO WHILE _MOUSEBUTTON(1)
  288.                         IF _MOUSEINPUT THEN
  289.                             CLS , Orange
  290.  
  291.                             OldW(0).X = (_MOUSEX - OmX)
  292.                             OldW(0).Y = (_MOUSEY - OmY)
  293.                             DrawAllWin
  294.                             dragWindow OldW(0)
  295.                         END IF
  296.                     LOOP
  297.                     ' new position of window
  298.                     Windows(a).X = OldW(0).X
  299.                     Windows(a).Y = OldW(0).Y
  300.                     OldW(a).X = Windows(a).X
  301.                     OldW(a).Y = Windows(a).Y
  302.  
  303.                 CASE Focusing
  304.                     Focus a
  305.             END SELECT
  306.  
  307.         CASE ELSE
  308.     END SELECT
  309.  
  310. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  311.     IsInWindow = mFalse
  312.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  313.         ' if window is closed to its bar it cannot get focus on the window area
  314.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  315.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  316.         ' if is the window bar area
  317.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  318.             ' if it is to the left of buttons on the bar
  319.             IsInWindow = Dragging
  320.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  321.             ' if it is on the leftest button on the bar
  322.             IsInWindow = cMinim ' icon minimize--> restore to child default
  323.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  324.             ' if it is on the middle button on the bar
  325.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  326.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  327.             ' if is on the rightest button on the bar
  328.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  329.         END IF
  330.     END IF
  331.  
  332. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  333.     IF Min > Max THEN SWAP Min, Max
  334.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  335.  
  336. SUB dragWindow (Win AS wChild)
  337.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B ' windows size
  338.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  339.     _DISPLAY
  340.  
  341. SUB wClosed (Win AS wChild)
  342.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  343.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  344.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  345.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  346.  
  347. SUB wMaxim (win AS wChild)
  348.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  349.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  350.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  351.  
  352. SUB wMinim (Win AS wChild)
  353.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  354.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  355.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  356.  
  357.  
  358. SUB DrawWindow (Win AS wChild)
  359.     ' the window
  360.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  361.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  362.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  363.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  364.     END IF
  365.     ' the status bar
  366.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  367.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  368.     wMinim Win
  369.     wMaxim Win
  370.     wClosed Win
  371.  
  372. SUB GetInput (Act AS INTEGER)
  373.     DIM mInput AS INTEGER
  374.  
  375.  
  376.     ' keyboard input
  377.     a$ = INKEY$
  378.     IF a$ = CHR$(27) THEN Act = aQuit
  379.  
  380.     'mouse input
  381.     mInput = mFalse
  382.     IF _MOUSEINPUT THEN mInput = mTrue
  383.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  384.     LOOP
  385.     IF mInput THEN
  386.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  387.             mInput = mLR
  388.         ELSEIF _MOUSEBUTTON(1) THEN
  389.             mInput = mLeft
  390.         ELSEIF _MOUSEBUTTON(2) THEN
  391.             mInput = mRight
  392.         ELSEIF _MOUSEBUTTON(3) THEN
  393.             mInput = mMiddle
  394.         END IF
  395.     END IF
  396.  
  397.     IF mInput = mLR THEN
  398.         Act = aQuit
  399.     ELSEIF mInput = mMiddle THEN
  400.         Act = Minim
  401.     ELSEIF mInput = mRight THEN
  402.         Act = Maxim
  403.     ELSEIF mInput = mLeft THEN
  404.         Act = mInput
  405.     END IF

Thanks to take a look!
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #14 on: February 13, 2020, 04:14:38 pm »
another little step:
resizing wchild into main program's window

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 12  with the power of the second array we implement the feature
  9. '             of resizable of child window
  10.  
  11. ' 2020 02 09  with the power of the second array we implement a different
  12. '             child windows' system:
  13. '             all child windows can be Closed to window's bar
  14. '             all child windows can be dragged on the screen
  15.  
  16. ' 2020 02 08  using a second array we store windows information indipendently so
  17. '             now each window can be modified and restored
  18.  
  19.  
  20. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  21. '             to it the last value used in windows(0) so the info of the last
  22. '             window that is dragged or maximize when we use Minimize button on
  23. '             another child window
  24. '             the fix can be got using a shadow array that stores windows informations
  25. '             or windows(0) as the child window that takes the information of the
  26. '             child window that must be acted (Minimize, Maximize and Closed)
  27. '             and we use it as template to make graphic output
  28.  
  29. ' 2020 02 05 fixed a minor bug on mouse click events
  30. '            activated events Maxim Minim and Closed
  31.  
  32.  
  33. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  34. '            removed vMax SHARED variable
  35. '            added 3 buttons on the rightest site of the bar of the child window
  36. '            SUB wClosed, wMaxim, wMinim
  37. '            In this version the user can maximize one child window to the application window
  38. '            In the status of Maxim the child window has the focus and can be only
  39. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  40.  
  41.  
  42. ' 2020 01 30 fixed bug on focusing a child window
  43. '
  44.  
  45. ' 2020 01 25  A program with child windows into it
  46. ' we need a system to manage multiple windows
  47. ' and a system to manage input/output
  48. ' and a system to make graphic report
  49.  
  50. ' settings-------------------------------------------------------
  51. SCREEN _NEWIMAGE(800, 600, 32)
  52. _TITLE "Child windows"
  53. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  54. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  55. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  56. CONST Minim = 10, Maxim = 20, Closed = 100
  57. CONST wMin = 5, aNull = 0, aQuit = 9999
  58. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  59. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  60. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  61.  
  62.  
  63.  
  64. 'dataset  -----------------------------------------------
  65. TYPE person
  66.     name AS STRING * 10
  67.     age AS INTEGER
  68.     weight AS INTEGER
  69.     height AS INTEGER
  70.     BMI AS INTEGER
  71.  
  72. TYPE wChild
  73.     X AS INTEGER
  74.     Y AS INTEGER
  75.     Height AS INTEGER
  76.     Zorder AS INTEGER
  77.     Status AS INTEGER
  78.  
  79. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  80.  
  81. InitWin
  82.  
  83. DIM Action AS INTEGER
  84.  
  85.  
  86. ' main loop -----------------------------------------------
  87.  
  88.     ' set the main window
  89.     Action = aNull
  90.     CLS , Orange
  91.     DrawAllWin
  92.     GetInput Action
  93.     DoAction Action
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. ' SUBs and FUNCTIONs --------------------------------------
  98. SUB InitWin
  99.     SHARED Windows() AS wChild, OldW() AS wChild
  100.     DIM a AS INTEGER
  101.  
  102.     Windows(1).X = 1
  103.     Windows(1).Y = 1
  104.     Windows(1).Width = 300
  105.     Windows(1).Height = 400
  106.     Windows(1).Zorder = 1
  107.     Windows(1).Status = Minim
  108.     Windows(1).Color = Blu
  109.  
  110.     Windows(2).X = 100
  111.     Windows(2).Y = 1
  112.     Windows(2).Width = 300
  113.     Windows(2).Height = 400
  114.     Windows(2).Zorder = 2
  115.     Windows(2).Status = Minim
  116.     Windows(2).Color = Yellow
  117.  
  118.     Windows(3).X = 200
  119.     Windows(3).Y = 1
  120.     Windows(3).Width = 300
  121.     Windows(3).Height = 400
  122.     Windows(3).Zorder = 3
  123.     Windows(3).Status = Minim
  124.     Windows(3).Color = Green
  125.  
  126.     Windows(4).X = 300
  127.     Windows(4).Y = 1
  128.     Windows(4).Width = 300
  129.     Windows(4).Height = 400
  130.     Windows(4).Zorder = 4
  131.     Windows(4).Status = Minim
  132.     Windows(4).Color = Red
  133.  
  134.     Windows(5).X = 400
  135.     Windows(5).Y = 1
  136.     Windows(5).Width = 300
  137.     Windows(5).Height = 400
  138.     Windows(5).Zorder = 5
  139.     Windows(5).Status = Minim
  140.     Windows(5).Color = Cyan
  141.  
  142.     FOR a = 1 TO wMin STEP 1
  143.         AdjournWin a
  144.     NEXT a
  145.  
  146. SUB RestoreWin (a AS INTEGER)
  147.     SHARED Windows() AS wChild, OldW() AS wChild
  148.  
  149.     Windows(a).X = OldW(a).X
  150.     Windows(a).Y = OldW(a).Y
  151.     Windows(a).Width = OldW(a).Width
  152.     Windows(a).Height = OldW(a).Height
  153.     Windows(a).Zorder = OldW(a).Zorder
  154.     Windows(a).Color = OldW(a).Color
  155.  
  156. SUB AdjournWin (a AS INTEGER)
  157.     SHARED Windows() AS wChild, OldW() AS wChild
  158.  
  159.     OldW(a).X = Windows(a).X
  160.     OldW(a).Y = Windows(a).Y
  161.     OldW(a).Width = Windows(a).Width
  162.     OldW(a).Height = Windows(a).Height
  163.     OldW(a).Zorder = Windows(a).Zorder
  164.     OldW(a).Color = Windows(a).Color
  165.  
  166. SUB DrawAllWin
  167.     SHARED Windows() AS wChild
  168.     DIM Finished AS INTEGER
  169.     Finished = wMin
  170.     DO
  171.         FOR a = 1 TO wMin
  172.             IF Windows(a).Zorder = Finished THEN
  173.                 DrawWindow Windows(a)
  174.                 Finished = Finished - 1
  175.                 EXIT FOR
  176.             END IF
  177.         NEXT a
  178.     LOOP UNTIL Finished = 0
  179.  
  180. SUB Focus (Index AS INTEGER)
  181.     SHARED Windows() AS wChild
  182.     DIM b AS INTEGER
  183.     FOR b = 1 TO wMin
  184.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  185.     NEXT b
  186.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  187.     DrawAllWin
  188.  
  189.  
  190. SUB DoAction (Act AS INTEGER)
  191.     SHARED Windows() AS wChild, OldW() AS wChild
  192.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  193.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  194.  
  195.     SELECT CASE Act
  196.         CASE aQuit
  197.             END
  198.  
  199.         CASE Maxim
  200.             _FULLSCREEN
  201.  
  202.         CASE Minim
  203.             _FULLSCREEN _OFF
  204.  
  205.         CASE mLeft
  206.             mX = _MOUSEX
  207.             mY = _MOUSEY
  208.  
  209.             ' search where and what mouse has touched by leftclick
  210.             OldA = 0
  211.             OldActio = 0
  212.             FOR a = 1 TO wMin ' windows(0) is out of action
  213.                 Actio = IsInWindow(mX, mY, Windows(a))
  214.                 IF Actio THEN
  215.                     IF OldA <= 0 THEN
  216.                         OldA = a
  217.                         OldActio = Actio
  218.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  219.                         OldA = a
  220.                         OldActio = Actio
  221.                     END IF
  222.                 END IF
  223.             NEXT a
  224.             IF a > OldA THEN
  225.                 a = OldA ' restore the last windows interacting
  226.                 Actio = OldActio
  227.             END IF
  228.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  229.  
  230.  
  231.             Focus a 'set zorder on the (a) window that gets the input
  232.  
  233.  
  234.             SELECT CASE Actio
  235.                 CASE cMinim
  236.                     ' here restore to  standard (bar + area of window) status of child window
  237.                     IF Windows(a).Status = Closed + Maxim THEN
  238.                         ' if windows is a closed maximized window
  239.                         ' we restore its status of maximized
  240.                         Windows(a).Status = Maxim
  241.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  242.                         ' if windows is a closed minimized window
  243.                         ' we restore its status of minimized
  244.                         Windows(a).Status = Minim
  245.                     ELSEIF Windows(a).Status = Maxim THEN
  246.                         ' if is a window maximized it gets back all info setting
  247.                         ' we restore its status of minimized
  248.                         RestoreWin a
  249.                         Windows(a).Status = Minim
  250.                     END IF
  251.  
  252.  
  253.                 CASE cMaxim
  254.                     ' here convert the window to full size of main window of the program
  255.                     ' OR gives 1 if both parameter are true or al last one is true
  256.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  257.                         ' it acts if windows if not still maximized
  258.                         ' it is minimized window opened or closed
  259.                         ' memorize window's data when it is not maximized
  260.                         '                        IF Windows(a).Width < _WIDTH THEN
  261.                         AdjournWin a
  262.                         ' it sets maximized status
  263.                         Windows(a).Width = _WIDTH
  264.                         Windows(a).Height = _HEIGHT
  265.                         Windows(a).X = 1
  266.                         Windows(a).Y = 1
  267.                         ' change status
  268.                         Windows(a).Status = Maxim
  269.                     END IF
  270.  
  271.                 CASE cClosed
  272.                     ' here minimize the child window to its window bar
  273.                     IF NOT Windows(a).Status > Closed THEN
  274.                         Windows(a).Status = Windows(a).Status + Closed
  275.                     END IF
  276.  
  277.                 CASE Dragging
  278.                     ' dragging is possible for all status of windows
  279.                     '
  280.                     ' if minimized or Closed and minimized window we save data info
  281.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  282.                     ' it sets variables for dragging
  283.                     OldW(0).X = Windows(a).X
  284.                     OldW(0).Y = Windows(a).Y
  285.                     OldW(0).Width = Windows(a).Width
  286.                     OldW(0).Height = Windows(a).Height
  287.  
  288.                     OmX = _MOUSEX - OldW(0).X
  289.                     OmY = _MOUSEY - OldW(0).Y
  290.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  291.                     DO WHILE _MOUSEBUTTON(1)
  292.                         IF _MOUSEINPUT THEN
  293.                             CLS , Orange
  294.  
  295.                             OldW(0).X = (_MOUSEX - OmX)
  296.                             OldW(0).Y = (_MOUSEY - OmY)
  297.                             DrawAllWin
  298.                             dragWindow OldW(0)
  299.                         END IF
  300.                     LOOP
  301.                     ' new position of window
  302.                     Windows(a).X = OldW(0).X
  303.                     Windows(a).Y = OldW(0).Y
  304.                     OldW(a).X = Windows(a).X
  305.                     OldW(a).Y = Windows(a).Y
  306.  
  307.                 CASE Focusing
  308.                     Focus a
  309.  
  310.                 CASE cResize
  311.                     ' resizing is possible only for minimized opened child windows
  312.                     IF Windows(a).Status = Minim THEN
  313.                         Windows(a).Status = cResize
  314.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP
  315.                         DO WHILE Windows(a).Status = cResize
  316.                             CLS , Orange
  317.                             DrawAllWin
  318.                             ShowDimension Windows(a)
  319.  
  320.  
  321.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  322.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  323.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  324.                             END IF
  325.                             _DISPLAY
  326.                         LOOP
  327.                     END IF
  328.  
  329.             END SELECT
  330.         CASE ELSE
  331.     END SELECT
  332.  
  333. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER)
  334.     SHARED Windows() AS wChild, OldW() AS wChild
  335.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  336.     Actio = 0
  337.  
  338.     IF IsInTheRange%(mX, Win.X, Win.X + Win.Width) THEN
  339.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  340.             ' do nothing if is in the range of window
  341.         ELSE
  342.             ' user click out of area  of window to resize
  343.             Actio = StopResize
  344.         END IF
  345.     ELSE
  346.         ' user click out of area  of window to resize
  347.         Actio = StopResize
  348.     END IF
  349.  
  350.  
  351.  
  352.  
  353.  
  354.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  355.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  356.             ' user click on lefttop square to resize
  357.             Actio = LResize
  358.         END IF
  359.     END IF
  360.  
  361.     IF IsInTheRange%(mX, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  362.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  363.             ' user click on the rightbottom square to resize
  364.             Actio = RResize
  365.         END IF
  366.     END IF
  367.  
  368.     IF Actio = 0 THEN
  369.         ' no action done
  370.     ELSEIF Actio = LResize THEN
  371.         ' choosen LeftTop buttom to resize
  372.         OldW(0).X = Win.X
  373.         OldW(0).Y = Win.Y
  374.         OldW(0).Width = Win.Width
  375.         OldW(0).Height = Win.Height
  376.         OldmX = _MOUSEX
  377.         OldmY = _MOUSEY
  378.         DO WHILE Actio = LResize
  379.             IF _MOUSEINPUT THEN
  380.                 IF (OldW(0).X + OldW(0).Width - OldmX) >= 50 THEN OldW(0).Width = OldW(0).X + OldW(0).Width - OldmX
  381.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY
  382.                 CLS , Orange
  383.                 DrawAllWin
  384.                 ShowDimension OldW(0)
  385.                 OldW(0).X = OldmX
  386.                 OldW(0).Y = OldmY
  387.  
  388.                 OldmX = _MOUSEX
  389.                 OldmY = _MOUSEY
  390.             ELSE
  391.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  392.             END IF
  393.         LOOP
  394.         Win.X = OldW(0).X
  395.         Win.Y = OldW(0).Y
  396.         Win.Width = OldW(0).Width
  397.         Win.Height = OldW(0).Height
  398.  
  399.  
  400.     ELSEIF Actio = RResize THEN
  401.         ' choosen bottomright square
  402.         OldW(0).X = Win.X
  403.         OldW(0).Y = Win.Y
  404.         OldW(0).Width = Win.Width
  405.         OldW(0).Height = Win.Height
  406.         OldmX = _MOUSEX
  407.         OldmY = _MOUSEY
  408.         DO WHILE Actio = RResize
  409.             IF _MOUSEINPUT THEN
  410.                 IF OldmX - OldW(0).X >= 50 THEN OldW(0).Width = OldmX - OldW(0).X
  411.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  412.                 CLS , Orange
  413.                 DrawAllWin
  414.                 ShowDimension OldW(0)
  415.                 OldmX = _MOUSEX
  416.                 OldmY = _MOUSEY
  417.             ELSE
  418.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  419.             END IF
  420.         LOOP
  421.         Win.X = OldW(0).X
  422.         Win.Y = OldW(0).Y
  423.         Win.Width = OldW(0).Width
  424.         Win.Height = OldW(0).Height
  425.  
  426.     ELSEIF Actio = StopResize THEN
  427.         ' click out of window to stop resize action
  428.         Win.Status = Minim
  429.     END IF
  430.  
  431. SUB ShowDimension (win AS wChild)
  432.     LINE (win.X, win.Y)-(win.X + win.Width, win.Y + win.Height), White, B ' windows size
  433.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  434.     LINE (win.X + win.Width - 10, win.Y + win.Height - 10)-(win.X + win.Width, win.Y + win.Height), White, BF 'button for resizing window
  435.     _DISPLAY
  436.  
  437. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  438.     IsInWindow = mFalse
  439.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  440.         ' if window is closed to its bar it cannot get focus on the window area
  441.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  442.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  443.         ' if is the window bar area
  444.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.Width - 31) THEN
  445.             ' if it is to the left of buttons on the bar
  446.             IsInWindow = Dragging
  447.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  448.             ' if it is on the leftest button on the bar
  449.             IsInWindow = cMinim ' icon minimize--> restore to child default
  450.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  451.             ' if it is on the middle button on the bar
  452.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  453.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  454.             ' if is on the rightest button on the bar
  455.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  456.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN
  457.             IsInWindow = cResize
  458.         END IF
  459.     END IF
  460.  
  461. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  462.     IF Min > Max THEN SWAP Min, Max
  463.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  464.  
  465. SUB dragWindow (Win AS wChild)
  466.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B ' windows size
  467.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  468.     _DISPLAY
  469.  
  470. SUB wClosed (Win AS wChild)
  471.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  472.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  473.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  474.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  475.  
  476. SUB wMaxim (win AS wChild)
  477.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  478.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  479.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  480.  
  481. SUB wMinim (Win AS wChild)
  482.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  483.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  484.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  485.  
  486. SUB wResize (Win AS wChild)
  487.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  488.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  489.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  490.  
  491. SUB DrawWindow (Win AS wChild)
  492.     ' the window
  493.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  494.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  495.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  496.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  497.     END IF
  498.     ' the status bar
  499.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  500.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  501.     wMinim Win
  502.     wMaxim Win
  503.     wClosed Win
  504.     wResize Win
  505.  
  506. SUB GetInput (Act AS INTEGER)
  507.     DIM mInput AS INTEGER
  508.  
  509.  
  510.     ' keyboard input
  511.     a$ = INKEY$
  512.     IF a$ = CHR$(27) THEN Act = aQuit
  513.  
  514.     'mouse input
  515.     mInput = mFalse
  516.     IF _MOUSEINPUT THEN mInput = mTrue
  517.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  518.     LOOP
  519.     IF mInput THEN
  520.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  521.             mInput = mLR
  522.         ELSEIF _MOUSEBUTTON(1) THEN
  523.             mInput = mLeft
  524.         ELSEIF _MOUSEBUTTON(2) THEN
  525.             mInput = mRight
  526.         ELSEIF _MOUSEBUTTON(3) THEN
  527.             mInput = mMiddle
  528.         END IF
  529.     END IF
  530.  
  531.     IF mInput = mLR THEN
  532.         Act = aQuit
  533.     ELSEIF mInput = mMiddle THEN
  534.         Act = Minim
  535.     ELSEIF mInput = mRight THEN
  536.         Act = Maxim
  537.     ELSEIF mInput = mLeft THEN
  538.         Act = mInput
  539.     END IF

here 2 screenshot
 
wchild5 demo.jpg
 
wchild6 demo.jpg
Programming isn't difficult, only it's  consuming time and coffee