curly
Full Member
Posts: 161
|
Post by curly on Feb 3, 2021 7:32:13 GMT -5
It's me again - I'm trying to create a menu bar by listing headings along the top row in either a long text box or graphic box that is the same colour as the background and without a border, and then trap a mouse button click to determine which menu item I am over? My brain has gone after 4 hours - please help! ...and can I change the background colour of a text or graphic box when the window is open?
nomainwin
WindowWidth = 1100 WindowHeight = 900
row=30 ' to allow simple alignment row1=row+30: row2=row+60: row3=row+90: row4 = row+120: row5 = row+150: row6 = row+180: row7=row+210: row8 = row+240 row9 = row+270: row10=row+300: row11 = row+330: row12 = row+360: row13 = row+ 390: row14 = row+420: row15=row+450 row16 = row+480: row17 = row+520: row18 = row+550: row19 = row+580: row20 = row+610: row21 = row+640: row22 = row+670 row23 = row+700
ccu = 1 'sets number for first DB way = 1 'sets first way in a DB pos = 1 'counts the total ways in the system
' gosub [DimArraysAndDefineValues]
'Home page
UpperLeftX= int((DisplayWidth-WindowWidth)/2) UpperLeftY= int((DisplayHeight-WindowHeight)/2)
Dim file$(6): file$(1) = "New": file$(2) = "Open": file$(3) = "Save": file$(4) = "Save As"
' TextboxColor$ = "buttonface" GraphicboxColor$ = "buttonface" ' textbox #home.textbox1,10,row1+10,55,20 graphicbox #home.graphicbox1,10,row1+10,55,20 ' Stylebits #home.textboxbox1, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE Stylebits #home.graphicbox1, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE
open "DSA" for window as #home print #home, "trapclose [quit.home]" print #home, "font ms_sans_serif 12" print #home, "when leftButtonDown [GetMousePosition]" print #home.graphicbox1, " Files "
wait
[GetMousePosition] notice "Detected mouse position" notice MouseX; " "; MouseY wait
[quit.home] Close #home END
|
|
|
Post by Rod on Feb 3, 2021 10:21:56 GMT -5
Yes it is possible to put a long graphicbox to act as a menu bar. You don't want lots of graphicboxes. bmpbuttons would also work. You need to address the graphicbox when sending it commands so #home.graphicbox1 You also need to use the mouse position to decide what menu item was clicked.
nomainwin
WindowWidth = 800 WindowHeight = 600
row=30 ' to allow simple alignment row1=row+30: row2=row+60: row3=row+90: row4 = row+120: row5 = row+150: row6 = row+180: row7=row+210: row8 = row+240 row9 = row+270: row10=row+300: row11 = row+330: row12 = row+360: row13 = row+ 390: row14 = row+420: row15=row+450 row16 = row+480: row17 = row+520: row18 = row+550: row19 = row+580: row20 = row+610: row21 = row+640: row22 = row+670 row23 = row+700
ccu = 1 'sets number for first DB way = 1 'sets first way in a DB pos = 1 'counts the total ways in the system
' gosub [DimArraysAndDefineValues]
'Home page
UpperLeftX= int((DisplayWidth-WindowWidth)/2) UpperLeftY= int((DisplayHeight-WindowHeight)/2)
Dim file$(6): file$(1) = "New": file$(2) = "Open": file$(3) = "Save": file$(4) = "Save As"
' TextboxColor$ = "buttonface" GraphicboxColor$ = "buttonface" ' textbox #home.textbox1,10,row1+10,55,20 graphicbox #home.graphicbox1,10,row1+10,500,25 ' Stylebits #home.textboxbox1, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE Stylebits #home.graphicbox1, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE
open "DSA" for window as #home print #home, "trapclose [quit.home]" print #home, "font ms_sans_serif 12" print #home.graphicbox1, "when leftButtonDown [GetMousePosition]" print #home.graphicbox1, "down ; backcolor buttonface ; fill buttonface ;\\ Files Next And Another "
wait
[GetMousePosition] notice "Detected mouse position" notice MouseX; " "; MouseY wait
[quit.home] Close #home END
|
|
|
Post by tsh73 on Feb 3, 2021 11:43:55 GMT -5
Playing with long graphic box example (But what wrong with normal MENU command?)
nomainwin w = WindowWidth - 16 'initial position adjusted for borders (YMMW) graphicbox #main.gr,0,0,w,25 open "test" for window as #main #main "trapclose [quit]" #main "resizehandler [resize]"
content$ = "Veni vidi vici" content$ =content$ +" if you think I have more then you are wrong"
#main.gr "down; fill buttonface; backcolor buttonface" For i = 1 to 3 #main.gr "place ";100*(i-1);" ";15 #main.gr "\";" ";word$(content$, i) next #main.gr "flush bg"
#main.gr "when mouseMove [move]" #main.gr "when leftButtonDown [LMB]" oldPos = -1 'bogus so if oldPos <> newPos works from the start wait
[LMB] newPos = int (MouseX /100) notice "You clicked ";chr$(13);_ "segment ";newPos+1;chr$(13);_ word$(content$, newPos+1) wait
[move] newPos = int (MouseX /100) if oldPos <> newPos then oldPos = newPos #main.gr "redraw bg" #main.gr "place ";newPos*100;" ";0 #main.gr "backcolor darkgray" #main.gr "boxfilled ";(newPos+1)*100;" ";25 #main.gr "place ";100*(newPos);" ";15 #main.gr "\";" ";word$(content$, newPos+1) end if wait
[resize] w = WindowWidth 'this will resize 'graphicbox #main.gr,0,0,w,25 #main "refresh" wait
[quit] close #main end
|
|
|
Post by tsh73 on Feb 3, 2021 12:20:48 GMT -5
More playing
nomainwin 'thi is for resisable graphicbox 'w = WindowWidth - 16 'initial position adjusted for borders (YMMW) 'but I'd rather just make LONG one w = DisplayWidth 'really long, better more then DisplayWidth graphicbox #main.gr,0,0,w,25 open "test" for window as #main #main "trapclose [quit]" #main "resizehandler [resize]"
content$ = "Veni vidi vici" content$ =content$ +" if you think I have more then you are wrong" while 1 i=i+1 w$=word$(content$, i) if w$ ="" then exit while wend n = i-1 'notice n; " ";word$(content$, n)
dim border(n+1) border(0)=0 border(n+1)=DisplayWidth 'so we never came over it for i =1 to n s$ = " "+word$(content$, i)+" " #main.gr "stringwidth? s$ txtWidth" border(i)=border(i-1)+txtWidth 'print i, border(i) next
#main.gr "down; fill buttonface; backcolor buttonface" For i = 1 to n #main.gr "place ";border(i-1);" ";15 #main.gr "\";" ";word$(content$, i) next #main.gr "flush bg"
#main.gr "when mouseMove [move]" #main.gr "when leftButtonDown [LMB]" oldPos = -1 'bogus so if oldPos <> newPos works from the start wait
[LMB] 'newPos = int (MouseX /100) for i = 1 to n if border(i)>MouseX then exit for next newPos = border(i-1) notice "You clicked ";chr$(13);_ "segment ";i;chr$(13);_ word$(content$, i) wait
[move] 'newPos = int (MouseX /100) for i = 1 to n if border(i)>MouseX then exit for next newPos = border(i-1) if oldPos <> newPos then 'print i, newPos, word$(content$, i) oldPos = newPos #main.gr "redraw bg" #main.gr "place "; newPos;" ";0 #main.gr "backcolor darkgray" #main.gr "boxfilled ";border(i);" ";25 #main.gr "place "; newPos;" ";15 #main.gr "\";" ";word$(content$, i) end if wait
[resize] w = WindowWidth 'this will resize 'graphicbox #main.gr,0,0,w,25 #main "refresh" wait
[quit] close #main end
|
|
|
Post by Brandon Parker on Feb 5, 2021 13:21:54 GMT -5
As it stands right now, the highlighted selection is removed when the window is resized, and if the user goes straight back to that same selection the highlighting does not occur. Making the following changes allows for one or both of those actions to occur; comments are in the code.
[resize] w = WindowWidth 'Setting oldPos to -1 forces the ability to allow the user to immediately 'hover back over the same selection and have it get highlighted after a resize oldPos = -1 'this will resize 'graphicbox #main.gr,0,0,w,25 #main "refresh" 'Calling [move] at the end of the resize forces the previously highlighted element to 'automatically be highlighted again after the resize GoTo [move] wait
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Feb 5, 2021 14:48:58 GMT -5
Why not use check buttons (boxs) with the style (BS_FLAT OR BS_PUSHLIKE)? That way you can use the same button event.(I don't have those equates just now but will look then up)
BS.PUSHLIKE = HEXDEC("&H00001000") BS.FLAT = HEXDEC("&H00008000")
STYLEBITS #1.CKB1, WS.FLAT OR WS.PUSHLIKE, 0, 0, 0 CHECKBOX #1.CKB1, Set, Rset, 0, 0, wide, high STYLEBOX #1.CKB3, WS.FLAT OR WS.PUSHLIKE, 0, 0, 0 CHECKBOX #1.CKB2, Set, Rset, Wide + 1, 0, wide, high OPEN "TEST" FOR WINDOW AS #1 CkbHndl.1 = HWND(#1.CKB1) CkbHndl.2 = HWND(#1.CKB2) WAIT END SUB Set Handl$ Hndl = HWND(#Hndl$) IF Hndl = CkbHndl.1 THEN do something IF Hndl = CkbHndl.2 THEN do something else END SUB SUB Rset Hndl$ END SUB
|
|
|
Post by Brandon Parker on Feb 5, 2021 22:34:29 GMT -5
CheckBoxes would not look the part for representing a menu IMO. You can use the same event even if you draw a menu using a GraphicBox. You simply have to figure out which menu option your user selected using the coordinates of the click as shown above.
Your example does not actually compile or work though. I presume this is more of what you wanted to try and show.
Global False : False = 0 Global True : True = 1
BS.PUSHLIKE = HEXDEC("&H00001000") BS.FLAT = HEXDEC("&H00008000")
StyleBits #Test.CKB1, WS.FLAT Or WS.PUSHLIKE, 0, 0, 0 CheckBox #Test.CKB1, "Menu 1", set, reset, 0, 0, 45, 25 StyleBits #Test.CKB2, WS.FLAT Or WS.PUSHLIKE, 0, 0, 0 CheckBox #Test.CKB2, "Menu 2", set, reset, 46, 0, 45, 25 Open "Test" For Window As #Test #Test "TrapClose quit" Wait
Sub quit handle$ Close #handle$ End End Sub
Sub set handle$ 'If getCheckBoxStatus(handle$) Select Case Hwnd(#handle$) Case Hwnd(#Test.CKB1) Notice "Menu 1" Case Hwnd(#Test.CKB2) Notice "Menu 2" End Select End Sub
Sub reset handle$
End Sub
{:0)
Brandon Parker
|
|