I want my “About” window to have no tab on the top. I want it to close when the mouse is clicked anywhere. I have this currently, and it doesn’t work:
Also, I tried emailing @bbjimmy for access to Yab forum, but still waiting for a reply, and I want to get this code done, as I only have about 2 or 3 hours in the evening to work on my project. Thanks.
Ideas @michel
#! /bin/yab
// Open the main window
WINDOW OPEN 450,100 TO 900,800, "MainView", "MyProgram"
MENU "File", "About", "A", "MainView"
MENU "File", "Quit", "Q", "MainView"
inloop = true
about_open = false // Track if the About window is open
while (inloop)
msg$ = message$
SWITCH msg$
// Handle main window quit request
CASE "MainView:_QuitRequested|"
window close "MainView"
inloop = false
break
// Handle Quit from menu
CASE "MainView:File:Quit|"
window close "MainView"
inloop = false
break
// Handle About from menu
CASE "MainView:File:About|"
if about_open = false then
about_open = true
// Open the "About" window
WINDOW OPEN 500,200 TO 700,300, "About", "About"
// Set properties of the "About" window
WINDOW SET "About", "look", "bordered"
WINDOW SET "About", "feel", "modal-app"
// Draw the message in the "About" window
DRAW TEXT 20,50, "Click Anywhere to Exit 'About'", "About"
end if
break
// Handle click anywhere in "About" window to close it
CASE "About:_MouseDown|"
window close "About"
about_open = false
break
END SWITCH
WEND
// Open the main window
WINDOW OPEN 450,100 TO 900,800, “MainView”, “MyProgram”
MENU “File”, “About”, “A”, “MainView”
MENU “File”, “Quit”, “Q”, “MainView”
dim mouse$(1)
inloop = true
about_open = false // Track if the About window is open
while (inloop)
msg$ = message$
SWITCH msg$
// Handle main window quit request
CASE "MainView:_QuitRequested|"
window close "MainView"
inloop = false
break
// Handle Quit from menu
CASE "MainView:File:Quit|"
window close "MainView"
inloop = false
break
// Handle About from menu
CASE "MainView:File:About|"
if about_open = false then
about_open = true
// Open the "About" window
WINDOW OPEN 500,200 TO 700,300, "About", "About"
// Set properties of the "About" window
WINDOW SET "About", "look", "bordered"
WINDOW SET "About", "feel", "modal-app"
// Draw the message in the "About" window
DRAW TEXT 20,50, "Click Anywhere to Exit 'About'", "About"
end if
break
END SWITCH
// Handle click anywhere in “About” window to close it
x = window get “About” ,“Exists”
if x=1 then
GetMouse()
if mdown then
window close “About”
about_open = false
end if
end if
WEND
sub GetMouse()
n = token(mouse message$(“About”), mouse$(), “:”)
mx = val(mouse$(1))
my = val(mouse$(2))
mlmb = val(mouse$(3))
mmmb=val(mouse$(4))
mrmb=val(mouse$(5))
mdown=mlmb+mmmb+mrmb
To avoid any program crashes, I would set a number variable to 1 as soon as the about window is opened and only activate the mouse query for the about window when it is opened. When the window is then closed, set the variable back to 0.
even though he has already done this here, related to the window
Why bother with a click? This one will close on mouseover
#!/yab
window open 100,100 to 200,200, "MainW",""
Window set "MainW", "Look", "Bordered"
option set "MainW", "HasFocus", 1
while (true)
if mouse message$ <> "" then
window close "MainW"
exit
endif
wend
This misses the point, the request was for the user to press a button while the mouse is over the window to close the help pindow, your solution would close the window any time the mouse is over the window.
Indeed, and you answered that, so I don’t have to. I’m showing that the original request is not the only way to close something as ephemeral as an About box.
Thanks for the input Michel! I’m going to try both of these solutions out tonight to see how it feels and reacts. As I’m learning Yab right now, I might as well get the experience coding both.
There’s always another way to do it. To make bbjimmy happy, here’s another way to do what you asked for. I quite often use something like this:
#! yab
window open 100, 100 to 200, 200,"MainW", ""
window set "MainW", "Look", "Bordered"
button -10,-10 to 110,110, "DontClickHereIDontWannaDie","", "MainW"
view 1,1 to 100,100, "HidetheButton", "MainW"
//draw your about text on the HidetheButton view
while(true)
a$ = message$
if instr(a$, "DontClickHereIDontWannaDie") then
window close "MainW"
exit
endif
wend
This relies on the fact that in yab, once you have created a button, you can slather ten views on top of it, it always remains a button. So I create a button larger than the window, which makes it invisible. Then I create a view on top of it for your About box text. Click anywhere and the button is activated.
Is there any way to alter this so that the user can click anywhere on the desktop to close the “About” window?
I tried setting mdown=mlmb but of course, it still relied on the if mdown then statement in the CASE to be true, meaning the action has to take place inside the window.
I also added another IF statement so that if the User closed the main window (here I call it “MainView” but they still had the “About” window open, it will close the “About” window too. Don’t need that “About” window hanging around just because they never clicked on it to close it. Gotta think about how users might use the application