Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup Window ; row-column versus top-left

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!

I like to have a popup window on a defined place on the screen.
In fact just under a toolbarbutton.
I do know what's the left postion of the toolbar.
The popup window requires row and colum values (as in DOS).

Any idea how to convert those row/column values into top/left pos as usual with objects on a form?

-Bart
 
What are you talking about in regard of the popup window? Define Window/Show Window? You shouldn' t do that. A Form? You set top/left in pixels. A Context menu? Despite the description of FROM nRow,nColumn you can set pixels there, too. A Messagebox? Will appear centered, you need trickery to position it.

Bye, Olaf.
 
Hi Bart,

Not quite sure if I understand the question. Are you trying to convert pixels to foxels? If so, this code should help:

Code:
lnLeftFoxels = lnLeft / (_SCREEN.Width / WCOLS(""))
lnTopFoxels = lnTop / (_SCREEN.Height / WROWS(""))

lnLeft and lnTop are the left and top of an object in pixels.

lnLeftFoxels and lnTopFoxels are the left and top of the object in the units used in DEFINE POPUP and similar commands.

Does that help?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I looked up what I use in case of DEFINE POPUP, and that's simply MROW(),MCOL(), which indeed gives Row and Column values rather than pixels, without parameters in regard to the main _screen, which I don't hide in my application.

Nevertheless it depends on what your popup is, what you really need. In general a calculation if pixels in foxels is just a division by a certain char height/width value you can determine via fontmetric(1) (height) and fontmetric(6) (avg width).

So my guess for converting pixels in foxels would be row = top/fontmetric(1) and col = left/fontmetric(6).

Bye, Olaf.
 
Hi Mike,

good to know. Indeed for the number of rows and columns of the _screen there is SROWS and SCOLS, "" as window name is taken for the screen indeed.

Also both your values match with my guess of fontmtric(1) and fontmetric(6) respectively.

Bye, Olaf.
 
Olaf, we're obviously thinking along similar lines.

But I wonder if Bart is really asking how to determine the co-ordinates of an object relative to the screen (which is what his menu probably needs), as opposed to relative to the object's container (which is what the Left and Top properties give).

Bart, if you could clarify that point, we should be able to take it further.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
In preview of "taking it further", left/top of the toolbar button postition within the toolbar can be transformed to position in regard of the _screen via the OBJTOCLIENT() function.

Despite of that maybe the simples solution would be to take MROW()+1, MCOL() as that would be 1 row below the current mouse position.

I also get the suspicion you want to display a context menu as a combobox dropdown replacement, positioned right under a certain position on the toolbar, this would look and work that way. But that would be overcomplicated, as you could simply add a combobox to a toolbar, you're not limited to buttons in a toolbar, like I thought myself, once.

Bye, Olaf.
 
Olaf, regarding your point about positioning the menu at a certain position on the toolbar - you're right that it would be complicated. In fact, I think it's impossible. As far as I know, a popup menu can only appear over the client area, not over toolbars.

The best he can do is to find the nearest point in the client area that corresponds to the bottom of the button on the toolbar (or the right edge of the button if the toolbar is vertical).

It should all become clear when Bart responds.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Wow, what information!
Went away for while and see....

Just to make things more clear:
I am using a formmanager which automaticly place toolbars.
On the toolbar I do have e.g. a sort button. Than just besides that I do have a button with small arrow as on combobox. That button pops up the custom window using underlisted code.
Code:
PARAMETERS tnLeft

LOCAL lo, lnMenuItems, i, j
local array laItems(1)
lo =_screen.ActiveForm
lnMenuItems = 0

WITH lo
		IF PEMSTATUS(_screen.ActiveForm,'aSearchItems',5)
		IF PEMSTATUS(lo,'aSearchItems',5)		
			lnMenuItems = ALEN(.aSearchItems,1)
			DIMENSION laItems[lnMenuItems]
			DEFINE POPUP SelectMenu  FROM 0,50 MULTISELECT  MARGIN  IN screen   TITLE "Zoeken op:"       && Create multi-choice menu
*			DEFINE POPUP SelectMenu  FROM 0, tnLeft MULTISELECT  MARGIN  IN screen   TITLE "Zoeken op:"       && Create multi-choice menu

			FOR i = 1 TO lnMenuItems
				DEFINE BAR (i) OF SelectMenu PROMPT .aSearchItems[i,1] MARK CHR(2)
			ENDFOR
			
			ON SELECTION POPUP SelectMenu do yourchoice    && Choice routine

			ACTIVATE POPUP SelectMenu 

		ENDIF &&PEMSTATUS(.,'aSearchItems',5)
	ENDWITH 
ELSE
	=MESSAGEBOX("Form mist property 'nSearchSelection'"+CHR(13)+"Zoeken niet mogelijk",0,_screen.Caption) 
ENDIF 

PROCEDURE yourchoice            && Executed when choice is made
LOCAL j

FOR j = 1 TO CNTBAR("SelectMenu")      && Loop for # of items
   IF MRKBAR("SelectMenu", j) = .T.      && Option is marked
  		 _screen.activeform.nSearchIndex = j
   ENDIF
NEXT

deACTIVATE POPUP SelectMenu 

RETURN

tnLeft is taken from a toolbar-ref and currently displays most left part of the toolbar.

I commented (*) out the try to have the popup window according the tnLeft value.
But than the popup window appeared in the upper right corner of the screen.
Than I found the figures, after consulting help, re row and column values.
I'll try with Mike's formule to see what happens.

-Bart

-Bart
 
Mike,

After better reading the messages I think I have to update using indeed a combobox in the toolbar. But that looks (imhu) less nicer than a sort button with 'select'-button besides it.
Microsoft app's gave me that idea and I just tried to imitate a bit.

-Bart
 
Bart,

Thanks for the clarification.

Unfortunately, you won't be able to get the menu to appear immediately below the button, because popup menus can't appear above a toobar. The best you can do is to put it outside the toolbar, but as close as possible to the button.

You might be able to use the following code to get the left-hand co-ordinate for your menu. The top co-ordinate will be 0 (the very top of the client area). This assumes that the toolbar is docked horizontally along the top edge of the screen:

Code:
* this code goes in the Click of the button, before
* it creates the menu
OBJTOCLIENT(this, 2) + thisform.Left + SYSMETRIC(3)

This code will give you the left co-ordinate in pixels. You can then use my earlier code to convert it to foxels.

Hope this makes sense.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Bart,

not 100% clear which MS app's
Microsoft app's gave me that idea and I just tried to imitate a bit.
you are trying to imitate, please give a screenshot.

Regards,

Jockey(2)

P.S. You are aware that your above given code will not work, as it has some nesting errors regarding with/endwith, if/endif in it? Also the use of lo=_screen.activeForm is used and not used but I suppose that all has to do with some quick and dirty copy & paste from existing code. Otherwise you should review.
 
Jockey,
You are right about the nesting error but though the code works as expected. And yes, I was testing some with active.form and lo.
Active.form gives errors during debugging so I tried lo.
A screenshot given seems difficult to me but if you are using office 2007 than have a look at the ribbon's button 'follow up flag'.
That's about same what I try to achieve.
-Bart
 
Mike, I have worked out your code and yes! It does exactly what I wanted to achieve.
Thanks again for your help!!
-Bart
 
Bart,
unfortunately I have already installed Office 2010, which has significant changes to 2007. Which application of Office 2010 (Word/Excel/Outlook) has this follow up flag? I recall something in Outlook.
Screenshot:
1.activate the screen with situation you would like to copy.
2.Press Shift and PrtSCrn buttons simultaneausly.
3.Activate MsPaint and start a new blank paint object.
4.Press buttons Ctrl+V and you are done when you save this file somewhere. C:\Temp would be a good place
optional you may even, if you know how paint works, capture only a bit from your screen and save the new file also somewhere on your hard disc.
When you are done you create a new reply here and attach your file in C:\Temp

Regards,

Jockey(2)
 
Jockey,
Making of screenshot is no prob.
But don't know how to add to this message.
-Bart
 
Bart,

Glad to hear my code worked.

The visual effect probably won't be too bad, especially if the button is low down in the toolbar - or, better still, if its bottom edge is right at the bottom of the toolbar. In that case, you'll only see a gap of one or two pixels between the button and the menu.

Also, you probably don't need to take an special action if the button is at the extreme right-hand end of the toolbar. If the position is such that the menu would be off the screen, VFP will automatically shift it to the left, which is what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Bart,
I see, however since Mike has given you an elegant solution there is no need to continue this thread.
Regards,

Jockey(2)
 
A totally different solution would be not to use the toolbar for your toolbar, but as you talk about office 2007, there is the new ribbon concept and vfp folks have imitated that with normal forms:
It depends on how much toolbars and code within them you have, but it might be worth to think about migration to these much nicer looking controls.

Bye, Olaf.
 
Olaf, Yes, I agree. There's a lot to be said for not using a toolbar in this case.

About four years ago, I created my own pseudo-Office 2007 ribbon in VFP. I still use it in most of my apps. But I used a toolbar as the main container, and somehow this just doesn't look right.

I did this before the VFPX Themed Controls project was available. If I was starting from scratch today, I would consider using that project.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top