|
Post by dagnabitboy on Oct 14, 2019 19:50:58 GMT -5
I'm trying to implement a recent file function under the file menu. I discovered that I cannot create a menu item programmatically, so I'm using a listbox.
The list box is initially hidden, but when I click on 'recent file' in my program it enables and shows the list box. Unfortunately it comes up behind other controls that are already on the screen. When I click anywhere inside the listbox it then appears on top of the other controls, which is what I want. I've tried all the various listbox commands such as enable, show, and set focus but none do what I need! Any suggestions? I've attached a couple of images that shows the issue.
Thanks!
This is how the listbox appears when first enabled.
This is how it appears when I click anywhere in the listbox itself, and how I'd like it to appear when first opened.
|
|
|
Post by tsh73 on Oct 15, 2019 1:34:27 GMT -5
Open separate modal window with just the file list. Close it after selection is made.
(sorry I could not make controls "behave" then one over the other. Let's see if other folks could)
|
|
|
Post by Rod on Oct 15, 2019 3:12:57 GMT -5
You can show and hide some controls so you can replace one with another if they occupy the same space. You would need to hide all overlapping controls in the example shown. So tsh73’s advice about opening a modal window is much cleaner and easier to implement.
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Oct 15, 2019 9:08:02 GMT -5
What about a popup menu?
|
|
|
Post by tsh73 on Oct 15, 2019 9:31:59 GMT -5
Author said: So if you have example, post it (or give a link)
|
|
|
Post by dagnabitboy on Oct 15, 2019 11:09:34 GMT -5
the problem with the popup is the same issue as the main menu, I cannot create a menu item programmatically because the menu function does not accept a string variable as input. It would be awesome if it did! Since I want to create a list of files (that change) the user can select from it has to be programmable. It sounds like the best solution is to open a new modal window per tsh73.
Thanks!
|
|
|
Post by dagnabitboy on Oct 15, 2019 11:11:02 GMT -5
Open separate modal window with just the file list. Close it after selection is made. (sorry I could not make controls "behave" then one over the other. Let's see if other folks could) Good suggestion! I'll implement this!
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Oct 15, 2019 11:42:18 GMT -5
Sorry, you were right. I did this fast using a popup window. Might need fixes.
nomainwin
WindowWidth = 640 : WindowHeight = 480 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) textbox #main.tb1,10,10,230,28 textbox #main.tb2,250,10,230,28 textbox #main.tb3,10,48,230,28 textbox #main.tb4,250,48,230,28 textbox #main.tb5,10,86,230,28 button #main.b1, "menu", [doButton],ul,250,86,230,28
Open "Window" for Window as #main #main "font arial 12" #main "trapclose [quit]"
wait
[quit]
close #main : end
[doButton]
for i = 1 to 10 ar$(i) = "test_" ;int(rnd(0)*10000) next
WindowWidth = 320 : WindowHeight = 240 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) #main "disable" listbox #101.listbox1, ar$(, doListboxAction, 0,0,320,240 stylebits #101, _WS_SYSMENU, 0,0, 0 '_WS_SYSMENU needed for the Kill BASIC Apps' open "" For window_popup As #101 #101 "trapclose [quitPop]" #101 "font arial 10"
wait
[quitPop] #main "enable" close #101 wait
sub doListboxAction h$ #main "enable" close #101 end sub
|
|
|
Post by dagnabitboy on Oct 15, 2019 13:00:40 GMT -5
The modal window works nicely. When I click on 'recent files' it opens a new window with the listbox showing. However, if I move the main window before I open the modal window, the placement of the modal window is messed up. Is there a way to detect the current location of the main window? I tried the resize handler but that only shows a new window size and is not even trapped when just moving the main window.
Nevermind! I found the DLL call to get the main window position on Alice's Restaurant!
|
|
|
Post by Brandon Parker on Oct 15, 2019 18:57:45 GMT -5
The issue with it showing up behind the other controls might be that it has a lower Z-Order preference. You can change that if you would like, but ...
Also, you can most certainly create Popup Menus in Liberty BASIC using the Windows API. You can use the code below to create different menus, using CreatePopupMenu() and InsertMenu()," on the fly, and then check the result that you get back from TrackPopupMenu() to determine which item was selected. The fourth parameter in InsertMenu() is a number that you specify when creating the menu item; that number is returned from TrackPopupMenu(). Wrap it all up in a Function, and it can be a nice and tidy way to create as many different Popup Menus as you would like. To get the window to execute the Function, one could use WMLiberty.dll to trap the right-click and direct it to the function via CallBack.
'Programmed by Brandon R. Parker
Struct point, x As long, y As long Struct rect, left As long, top As long, right As long, bottom As long Global hMenu
Open "Window" For Window As #Test #Test "TrapClose Quit"
selectionArray$(0) = "Hello World!!" selectionArray$(1) = "Good-Bye World!!"
hMenu = CreatePopupMenu() result = InsertMenu(hMenu, 0, _MF_BYPOSITION Or _MF_STRING, 1, selectionArray$(0)) result = InsertMenu(hMenu, 1, _MF_BYPOSITION Or _MF_SEPARATOR, _NULL, "") result = InsertMenu(hMenu, 2, _MF_BYPOSITION Or _MF_STRING, 2, selectionArray$(1)) result = TrackPopupMenu(hMenu, _TPM_RETURNCMD Or _TPM_LEFTALIGN Or _TPM_TOPALIGN Or _TPM_LEFTBUTTON, Hwnd(#Test))
If (result = 0) Then Print "No menu item selected." Else Print selectionArray$(result - 1) End If Wait
Sub Quit handle$ result = DestroyMenu(hMenu) Close #handle$ End End Sub
Function CreatePopupMenu() CallDLL #user32, "CreatePopupMenu", CreatePopupMenu As ulong End Function
Function DestroyMenu(hMenu) CallDLL #user32, "DestroyMenu", hMenu As ulong, _ DestroyMenu As long End Function
Function DeleteMenu(hMenu, uPosition, uFlags) CallDLL #user32, "DeleteMenu", hMenu As ulong, _ uPosition As ulong, _ uFlags As ulong, _ DeleteMenu As long End Function
Function InsertMenu(hMenu, uPosition, uFlags, uIDNewItem, lpNewItem$) lpNewItem$ = lpNewItem$ + chr$(0) CallDLL #user32, "InsertMenuA", hMenu As ulong, _ uPosition As ulong, _ uFlags As ulong, _ uIDNewItem As ulong, _ lpNewItem$ As ptr, _ InsertMenu As long End Function
Function TrackPopupMenu(hMenu, uFlags, hWnd) result = GetCursorPos() xPos = point.x.struct yPos = point.y.struct CallDLL #user32, "TrackPopupMenu", hMenu As ulong, _ uFlags As ulong, _ xPos As long, _ yPos As long, _ _NULL As long, _ hWnd As ulong, _ rect As struct, _ TrackPopupMenu As long End Function
Function GetCursorPos() CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong End Function
{:0)
Brandon Parker
|
|
|
Post by dagnabitboy on Oct 16, 2019 15:20:56 GMT -5
Thanks Brandon! I'll keep that for reference. I do have it working nicely with a second window on top of the main. It looks unusual of course, but it's simple and was easy to program in LB. My old brain gets overwhelmed sometimes with Windows API!
|
|
|
Post by Brandon Parker on Oct 16, 2019 16:53:04 GMT -5
No problem...
I was playing around with what you were describing in your first post, and I wanted to share a way to actually get what you were trying to do to work. The way to just work with what you had originally, without opening another window, would be to do the following.
1. Disable the TextBox and StaticText Controls on the window 2. Show the ListBox Control
This assumes the ListBox is created after any control that would be "under" it.
This should force the ListBox to actually show in front of the Textbox and StaticText Controls. Disabling the other controls in that case if what you would want anyway since you would want the user to only be able to select from the ListBox.
The Modal window completely takes care of that though as would a Popup menu.
Glad you got something working to your satisfaction!!
{:0)
Brandon Parker
|
|
|
Post by dagnabitboy on Oct 17, 2019 22:18:11 GMT -5
I considered that as well, Brandon, but I've got a lot doo-dads on the screen that I'd have to disable and then re-enable. Plus, I think it might look a bit weird! Although, I've done it on a different program. Anyhoo, I did get it all working opening up another window. I also made a call to windows to get the start x and y location of the programs first window so I place the next window on top in an overlapping fashion, so it looks decent!
Thanks!
|
|