|
Post by Rod on Nov 7, 2021 7:49:25 GMT -5
Why rely on the vagaries of the users mouse click. Just define the location you want for each pop up and move it with the api call.
|
|
|
Post by Walt Decker on Nov 7, 2021 9:15:32 GMT -5
David: If your popup menus work outside a graphic, congrats!. I could not get them to work that way. But here is a solution:
' MousePosX = 0 MousePosY = 0
BUTTON #DMO.PUSH, "PUSH", [POPUP.1], UL, 5, 5, 50, 25 OPEN "DEMO" FOR WINDOW AS #DMO
PushHndl = HWND(#DMO.PUSH)
RetVal = FN.WindowBottom(PushHndl, MousePosX, MousePosY)
WAIT
[POPUP.1] RetVal = FN.SetCursor(MousePosX, MousePosY) '<--- position cursor to 'lower right corner of 'the graphic box
POPUPMENU "Red Apples", [RED.APPLES], "Golden Delicious", [GOLDEN] WAIT
[RED.APPLES] RetVal = FN.SetCursor(MousePosX, MousePosY) POPUPMENU "Pears", [PEARS], "Bartlet Pears", [BARTLET.PEARS] WAIT
[PEARS] RetVal = FN.SetCursor(MousePosX, MousePosY) 'POPUPMENU Etc.
WAIT
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.WindowBottom(PushHndl, BYREF MousePosX, BYREF MousePosY) '################################################################ ' The below function gets the size of a window in SCREEN COORDINATES. ' To find the size subtract X, Y from X1, Y1. '################################################################
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #user32, "GetWindowRect", PushHndl AS ULONG, tRect AS STRUCT, _ RetVal AS VOID
MousePosX = tRect.X1.struct MousePosY = tRect.Y1.struct END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.SetCursor(MousePosX, MousePosY) '################################################################### ' This function sets the cursor to screen position MousePosX, ' MousePosY '################################################################### RetVal = 0 CALLDLL #user32, "SetCursorPos", MousePosX AS LONG, MousePosY AS LONG, _ RetVal AS VOID
END FUNCTION '
EDIT:
David:
After reading your post about the # of buttons, you will have to modify the code above for each button. The following is psuedo-code:
[POPUP.1] <--- FOR BUTTON 1
PushHndl = HWND(#WIN.BTN1) <--- your button name
RetVal = FN.WindowBottom(PushHndl, MousePosX, MousePosY) RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU TEXT, [ITEM1], TEXT2, [ITEM2] <--- your popup
WAIT
[ITEM1] RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU <--- your popup
WAIT
[ITEM2] RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU <--- your popup
WAIT
[POPUP.2] <--- FOR BUTTON 2
PushHndl = HWND(#WIN.BTN2) <--- your button name
RetVal = FN.WindowBottom(PushHndl, MousePosX, MousePosY) RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU TEXT, [ITEM3], TEXT2, [ITEM4] <--- your popup
WAIT
[ITEM3] RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU <--- your popup WAIT
[ITEM4] RetVal = FN.SetCursor(MousePosX, MousePosY)
POPUPMENU <--- your popup
WAIT
You will have to do the above sequence for each button and popup.
|
|
|
Post by tsh73 on Nov 7, 2021 15:38:37 GMT -5
David,
well I just removed all graphic window related stuff, converted window type to ordinary window, added a button and make it call [popup1] It does work.
global storedCurX, storedCurY
button #gr.btn, "Click", [popup1], UL,10,10 open "test" for window as #gr 'open "test" for graphics_nsb_nf as #gr #gr "trapclose [quit]" '#gr "down; trapclose [quit]" '#gr "home; posxy cx cy"
'#gr "font Times_new_roman 16" txt$="Click Apples|Red Apples|Large Red Apples" 'txtW=200 '#gr "stringwidth? txt$ txtW" '#gr "place ";cx-txtW/2;" ";cy '#gr "\";txt$
'#gr, "when leftButtonDown [popup1]"
wait
[popup1] call StoreCursorPos popupmenu "Apples", [Apples], "Pears", [Pears] 'first popupmenu wait
[Apples] print "[Apples]" call RestoreCursorPos popupmenu "RedApples", [RedApples], "Green Apples", [GreenApples] wait
[Pears] print "[Pears]" call RestoreCursorPos popupmenu "Red Pears", [RedPears], "Green Pears", [GreenPears] wait
[RedApples] print " [RedApples]" call RestoreCursorPos popupmenu "Large Red Apples", [LargeRedApples], "Small Red Apples", [SmallRedApples] wait
[LargeRedApples] print " [LargeRedApples]" notice "end of chain, see mainwin" 'etc
wait
[quit] close #gr end
sub StoreCursorPos Struct tagPoint, x As long, _ y As long CallDLL #user32, "GetCursorPos", _ tagPoint As struct, _ GetCursorPos As long storedCurX = tagPoint.x.struct storedCurY = tagPoint.y.struct end sub
Sub RestoreCursorPos res = SetCursorPos(storedCurX, storedCurY) end sub
Function SetCursorPos ( intX, intY ) CallDLL #user32, "SetCursorPos", intX As long, _ intY As long, _ SetCursorPos As long End Function
|
|
curly
Full Member
Posts: 161
|
Post by curly on Nov 8, 2021 7:18:15 GMT -5
Hi Rod, Walt and Anatoly, Initially, I did not think I knew how to carry out Rod's suggestion. I printed, read, and tried to understand both Walt's and Anatoly's suggestions, and it looked to me that Anatoly's might be the simpler, so I gave it a go. BINGO!!! Not only does it work perfick!, I see I can define storedCurX and storedCurY at will, and call the subroutine RestoreCursorPos to put a popupmenu anywhere as per Rod's suggestion. I'd never seen this way of calling a subroutine before - I have only ever used gosub [somewhere] and return. Thank you all, have a nice day and stay safe, David
|
|
|
Post by Walt Decker on Nov 8, 2021 12:40:42 GMT -5
That is fine, but be aware that storedCurX, storedCurY are in screen coordinates NOT window form coordinates so:
storedCurX = 50 storecCury = 15
is not where you think it is on your form window. It might just put it in the caption of your form window. Ooops!
I do not know whether your forms can be resized, but if they can you are much better off NOT hard coding the cursor coordinates. That makes Anatoly's system just as complicated as mine.
|
|
|
Post by Rod on Nov 8, 2021 14:08:16 GMT -5
Again, why allow a user to resize a perfectly proportioned window? Liberty gives you the full screen size , you can use that to decide how big your display window should be.
Accommodating resizing is just a pain, don’t do it. Craft a perfectly sized gui.
|
|
|
Post by Walt Decker on Nov 8, 2021 14:35:14 GMT -5
Again, why allow a user to resize a perfectly proportioned window? Liberty gives you the full screen size , you can use that to decide how big your display window should be. Accommodating resizing is just a pain, don’t do it. Craft a perfectly sized gui.
Have you ever wanted to work on two or more windows or apps at the same time with them being side by side?
Accommodating size is not difficult. Just takes a bit more code.
|
|
|
Post by Rod on Nov 8, 2021 14:48:59 GMT -5
We are not coding a Windows compliant application that allows the user poetic licence, we are coding a business application that should rigorously control the environment.
|
|
|
Post by Walt Decker on Nov 8, 2021 16:15:45 GMT -5
Murphy's first law amended: If nothing can go wrong, it will.
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Nov 8, 2021 16:23:56 GMT -5
Hi Walt Your comment about Murphy's law made me think about another famous comment made by NASA post Apollo 11. The comment was that they were not thinking about what could go wrong but rather about what could go right on that historic flight...
|
|
|
Post by Walt Decker on Nov 9, 2021 9:49:04 GMT -5
I seem to recall that, Dennis. NASA was not too confident about the first mission.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Nov 9, 2021 12:41:53 GMT -5
Hi again, Walt, thank you for pointing out that the cursor variables are relevant to the entire screen not just my windows. At the moment, the routine is only called when a button is clicked to start the process to autofill a number of boxes, so my application will be fine. Although it's like having a new toy, I plan to use it only for my cascading popupmenus, triggered from buttons, so it shouldn't be an issue.
Rod, when you refer to 'a perfectly sized GUI', what I've got is fine on my monitor, but I'll need to make some adjustments to fit it onto a tablet. I've check to size of the tablet screen in pixels. If I resize my two main windows to the same number of pixels, they should fit???
Another quick question on screen size and compiling. When a standalone programme is created, is all text in the .bas programme compiled, or only the relevant parts? I would like to retain just one .bas file, and compile it to a desktop or tablet programme by using a simple switch to branch to tablet or desktop GUI?
Kind regards, David
|
|
|
Post by Walt Decker on Nov 9, 2021 14:20:30 GMT -5
David:
For commercial purposes there are two things you must check: 1) monitor resolution and 2)PPI or points per inch.
Monitor resolution can be checked by invoking LB's functions DisplayWidth and DisplayHeight and your window forms can be set to appropriate values.
PPI is a different ball of wax. It takes api calls to do that. If I remember correctly WIN default values for PPI ar 98 X 98. Incidentally, to check PPI you will need a dll to do that. LB can't. There is a dll for that purpose in the "Things you don't want to know" series.
Chances are PPI will be the default and you will not have to do any scaling. Manifests can accomplish that for you but LB does not have manifests.
|
|
|
Post by Rod on Nov 9, 2021 14:21:13 GMT -5
On any PC you have a certain amount of real estate. To be sure your program can be seen as intended the simplest option is to code it to fit on the smallest screen resolution you intend to cater for. For a corporate program it will usually grab full screen to take complete control and stop any interference from other windows input. If your tablets are all the same, as corporate tablets are, you will likely cater for one screen size.
Windows has us believing that we NEED to cater for multi windowed applications on varied screen sizes. We don't. Buy everyone a 1028x900 screen tablet and code your application to use every one of those pixels.
Do your engineers need another window on screen? if so what? You are in charge, decide what is best for the site visit and code what can be interferred with least. Coding a variable screen size will add layers and layers of unnecessary code.
|
|
|
Post by Walt Decker on Nov 9, 2021 14:25:48 GMT -5
Not necessarily.
|
|