PDA

View Full Version : Absolute Cursor Position



nelsonaddiso
03-04-2009, 12:06 PM
I posted this earlier, but to the wrong forum. Sorry.

I'm working on a VBA macro for word 2007. I would like to position a dialog box relative to the cursor in the active window.

fumei
03-04-2009, 12:10 PM
The cursor is Selection. Selection has .Range.Information with parameters giving its position relative to the page.

nelsonaddiso
03-04-2009, 02:21 PM
That's not really what I'm looking for. I know that I can get a vertical/horizontal position relative to the page. I'm looking for a position relative to the window or screen so that I can position a dialog box directly
under a specific *line of text. (*for lack of a better word)

fumei
03-05-2009, 12:02 PM
I think, because you state window or screen, you may have to use API.

That being said, there seems to be a bit of a conflict. you state you want to positrion a dialog box under a specific line of text.

That is VERY different from positioning the dialog relative to the Selection. What if the Selection (cursor) is not there?

Further, any given line of text can be at various places on-screen depending on whether the application window is maximized, or placed differently.

And how, exactly, are you determining, and defining, that specific line of text?

It probably (I think) can be done, but what - may I ask - is the pressing need for this? Why are you trying to do this? Is it worth the effort?

nelsonaddiso
03-05-2009, 10:49 PM
Fumei,

First, thanks for you help. Your original suggestion lead me to a solution, albeit with certain caveats.

I can't upload an image of what I'm trying to achieve, but I can describe it.

Consider a screenplay.

------------------------------------------------------------

CUT TO: <== Transition

EXT. BACKYARD -- DAY <==Slugline

Here is where the action is.

JACK <== Character
(expressively)
If I had something to say, I'd say
it here.

-------------------------------------------------------------

The transition line has a few different possibilities: CUT TO, DISSOLVE TO, FADE OUT.

The slugline has three elements: The first five characters denote whether a scene is inside or outside or both ("INT. ", "EXT. ", and "I/E. "). The second element is the location, and the third is the time of day (DAWN, MORNING, NOON, ETC., again, a finite, standard list).

Two elements are not preset: Location and Character names. Upon opening a document, I loop through and load these values into arrays.

When editing the screenplay, the user uses a hotkey to cycle through the paragraph styles and another to add or update the content. Most stand-alone editors use Tab and Enter for this. I think this is a mistake as it corrupts the editor and is the reason for their notorious bugginess.

I believe I can create an add-on for Word using alt-right and alt-left to cycle the paragraph styles and alt-down to for adding updating content, leaving Tab and Enter alone to their natural purposes. My philosophy is: Let Word be Word.

But I digress. Back to the solution.

Here is the code I settled on

' If the text is too close to the bottom, put the dialog box over it.

If Selection.Information(wdVerticalPositionRelativeToTextBoundary) > 250 Then

TimssOfDay.Top = Selection.Information(wdVerticalPositionRelativeToTextBoundary) - _
40
Else

TimesOfDay.Top = selection.Information(wdVerticalPositionRelativeToTextBoundary) + _
150

End If


This works - sort of.

First, you must force the user to edit the script in draft mode at 100% zoom, and both Word and the active doc must be maximized. In draft mode, Selection.Information(wdVerticalPositionRelativeToTextBoundary) returns the distance from the top of the workspace area to the cursor in points. To place a dialog box relative to the cursor, you must offset that number with
the points above the workspace(the menubar, ribbon, etc.).

When the cursor is on, say, a paragraph with Style = "Character" and they press alt-down, a dialog pops up with a list of names directly under or over the cursor. At that point, they can select a name from the list or type a new name to be added. The list narrows and widens as they type and delete and it is all shown on page as they are doing it. If you are interested I can email you some screen shots.

Another draw back is that I'm hard coding the number of points to offset. If the height of the ribbon changes, the dialog box won't be right.

I know nothing about how to access API information. Although I was a systems analyst back in the late eighties - early nineties, I've done very little windows programming. I mostly do small projects in vb or vba when a need arises. If you can point me to information about API, I'd appreciate it.

As for your final question; is it worth the time and effort? I'm a stand-up comic with a disability. I have way too much time on my hands.

fumei
03-06-2009, 12:05 PM
Whooooa, Nelly. I can agree with some of that, and disagree with other stuff.

"My philosophy is: Let Word be Word."

LOL! Totally agree.

I have done some screen-writing, and, I am a fairly good Word user. I admire your intention, but I don't know. Dedicated screenwriting software is, over all, a better way to go. Trying to duplicate the excellent features of single-purpose software using Word? Yeesssssss, well, hmmmm, gee, I don't know.

"Most stand-alone editors use Tab and Enter for this. I think this is a mistake as it corrupts the editor and is the reason for their notorious bugginess."

What have you been using?

That being said, i have serious issues with:

"First, you must force the user to edit the script in draft mode at 100% zoom, and both Word and the active doc must be maximized. "

I am quite reluctant to "force" users to do things. Yes, I certainly try and make things so that users can NOT do certain things, and I make it as easy as possible to DO things...but I do not like forcing environmental conditions.

Logic? Yes. Actions? Yes. What it looks like? No.

The fact of the matter is, is that for you to do what you say, yes, you DO have to force envrionmental consitions. That was sort of my point earlier, what if the windows is not maximized? Then on-screen location can change.

OK, you solve that by forcing full-screen, then go on from there.

I don't like it.

However, back to your actual description:

"When the cursor is on, say, a paragraph with Style = "Character" and they press alt-down, a dialog pops up with a list of names directly under or over the cursor. At that point, they can select a name from the list or type a new name to be added. The list narrows and widens as they type and delete and it is all shown on page as they are doing it. "

This functionality already exists in stand-alone screen-writing software.

I have to ask. Does your code already deal with things like:

"When the cursor is on, say, a paragraph with Style = "Character"

That is a very definitive piece of logic.

"and they press alt-down, a dialog pops up with a list of names directly under or over the cursor."

Ai carumba! Yes, you could do that, but it would require the constant building and re-building of some sort of array. An array of Characters. If you add a character into the document, that new character has to be added into this constantly checked array.

Why? Because of what you are asking. If the cursor is on a "Character" style, popup a list of (one would assume) current Characters.

OK, but THAT means you have to constantly check - throughout the document - for the list of current characters.

What if you DELETE a character from the document? Now you go to a point that is a "Character" style...should that deleted character be included...or not?

This is all logic, but again, I have to say that this exact logic and functionality is already present is screen-writing software.

Do I think you could do it in Word? Probably. And if you got lots of time on your hand and want to give it a go, all power to you. I gave it a go about four years ago, but lordy lordy it got to be a monster.

I bought Final Draft. It is designed as screen-writing software. Word is designed to be a general word-processor. Yes, it is fun to make it jump through hoops, but for me, in the end, it was NOT worth the time and effort.

"Another draw back is that I'm hard coding the number of points to offset. "

Exactly. Any time one has to hard code values, especially screen layout values, it is asking for trouble.

I am curious. You mention "dialog", but:

TimssOfDay.Top

seems like a UserForm. Yes?

nelsonaddiso
03-06-2009, 03:23 PM
Man, you have some serious issues. I'm just a guy doing a little programming for the hell of it. You have no reason to rip me a new one.

Oh, and my name is Nelson, not Nellie.

Is this how you people treat all your newcomers?

lucas
03-07-2009, 04:46 PM
I read the thread twice. Your's was the only one that I found offensive.

We do pride ourselves on having a friendly forum and I thought Gerry went way out of his way to help you and if you can't stand a little humor and ribbing then maybe you should pay someone so that you can make them behave the way you want them to. People volunteer here, they do it for free. You are the one who is here asking for help.

I'm serious when I tell you this as a friend. I don't think this forum is for you unless you can change the way you interact, immediatly.

Your only warning.

nelsonaddiso
03-08-2009, 01:29 AM
Fumei, Lucas, and All,

Offensive? How was I offensive? This is my first post in this group. I'm working on a project that I'm thoroughly enjoying and I hit a snag. This looked like a cool site with a lot of great programmers on it. So I posted. This guy gives me one suggestion [count the suggestions, Steve, one. The rest is rant.] and asks me what I'm working on. I answer him with enthusiasm. And then... BOOM... I'm slammed with -- what seemed to be -- a mean spirited tirade about how how my project is a waste of time.

Gee, it's almost as if he asked what I do SO he could rant.

You know, I may be a newbie on this board, and I may be new to VBA. But I am no amateur programmer. I started programming 1979 when I was a sophomore in high school. I worked for ten years as a systems analyst for the Eastman Kodak Company. I've taught myself dozens of languages over the years. COBAL, Fortrane, PL/1, IDEAL, all self taught while on the job.

I know that, in time, I could have been an asset to this board. You don't know me. I'm witty. I'm fun. I'm kind. I'm helpful. But I wouldn't fit in here. Why? Because you on this board believe that seniority grants you a waiver on the very rules you agree to when you joined. I wouldn't fit in here because I respect people. I wouldn 't fit in because I wouldn't be able to hold my tongue anytime I saw anyone treat anybody the way Fumei treated me.

I have no doubt that Fumei knows his stuff. I have no doubt that he's helped lots of folks. But Fumei's best talent seems to be backhanded insults laden with a heavy dose of discouragement. How many people have come here for advice, gotten Fumei-gated, and never came back? And how many times has the prevailing attitude been, "If you can't stand the heat, stay out of the kitchen."

"maybe you should pay someone so that you can make them behave the way you want them to."

What kind statement is this? "We're tactless here. So if you want people to have tact, pay them."

Fumei has knowledge. Knowledge is Power. How does Fumei choose to exercise that power? As a license to treat newcomers with disrespect. How does Steve choose to exercise his power? To silence anyone who might suggest that NOBODY should be treated with disrespect. You don't even see the irony in using that quote as your signature. "I'm the admininstrator, and if I say Fumei's rudeness is to be tolerated, then so be it."

Jeepers, don't you see what you've done. You've created a filter to defend the hierarchical power structure. Steve said it very clearly; if I want to remain a member, I must learn not to point out that Fumei's responses -- right, wrong or indifferent -- are tactless at best. And I must learn it right now -- from the start.

I don't even mind you allowing him to be tactless. I understand that tactless people must be tolerated. But what you're doing is being intolerant of people who speak up.

I know you're going to ban me from this site. That blows my mind. I could never have imagined myself getting banned from anything -- let alone a forum... a programming forum... on my first post. No, Steve, I believe I'm right and you're wrong. I think Fumei's rant was unconstructive, discouraging and rude. The only difference is I'm letting you know what I think before you ban me from the site.

So I'll ask the question again: Is this how you treat newcomers?

Now go prove my point. Ban me. And don't forget to delete this thread. There is, after all, the possibility that some people might agree with it.

lucas
03-08-2009, 05:26 AM
Nellie has been banned but I'm leaving his rants here for other to judge.

It seems that being right is more important to him than anything else.

Good luck to him in his quest to find another place that is more friendly and helpful than vbaexpress.

I will leave this thread open and encourage anyone to post their thoughts here. If folks think I am out of line, I will reconsider the ban.

Gerry, you stay out of this one, ok my friend?

Nelviticus
03-09-2009, 03:16 AM
I was reading this with interest until I reached post #7 where nelson suddenly blew his top for no reason I could identify. The way I read it, fumei's prior post was interested, interesting, friendly and constructively critical and had clearly taken him some time to write - essentially "I like what you're trying to do but I don't think it's worth the effort and here's why". Nelson seems to have interpreted it as an insult. I guess he got angry at "Whooooa, Nelly" and stayed angry.

Lucas's attempt to calm things down was answered with a completely over-the-top rant.

Because I'm a wishy-washy liberal I would probably have made one more attempt to explain to nelson that he'd misinterpreted fumei's post. But because of nelson's final post I think the ban was in order. Exit stage left, in a huff.

Don't lose sleep over it. It's only the internet.