My Assistant
![]() ![]() |
|
|
Sep 20 2005, 06:44 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 159 From: Enkhuizen, Nederland |
I guess we have all seen the stupid behaviour of the context menu in many applications when using the keyboard button instead of the mouse to right-click some selected item. It usually pops up in the upper left corner, or exact middle of the window. I am trying to fix it, in a tree control, but for the life of me i can not seem to find out how many pixels every node in my tree takes up. I need this size to be able to move the mouse location to exactly where the selected item is.
I tried this very elegant solution with a custom dummy report that i open, set the fontname and size of text-control on that, SizeToFit the thing and take the new size of the detail-section, to calculate that into pixels for the mouse. This went just perfect for Tahoma 8 point, but messes up completely when i make it 11 point. In C++ they can do it, by something like HTREEITEM ht = tc.GetSelectedItem(); RECT rect; tc.GetItemRect( ht, &rect, true ); tc.ClientToScreen( &rect ); Now there happens to be a ClientToScreen in the windows "user32" api, but can get no handle to the selected item, like this tc.GetSelectedItem() does. So... does anyone have a better idea for me, or IS there a handle to be found? It's not that i except ever displaying this tree in 11 point, but it is a matter of principle, and besides it ought to work on other displays too. Thirsty for thine suggestions i drink to thee, Daan o! |
|
|
|
Oct 3 2005, 12:56 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
Hi,
I'm not exactly sure what it is you are trying to acomplish, but there if I'm understanding you right you want something to pop up in the place where the cursor is right? There is indeed an API which figures out the cursor position. I believe the two API's you would need are: Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Then you could create a sub like this: Sub MousePos(ByRef FRM As Form, ByRef x, ByRef y) Dim pt As POINTAPI ' Get the current mouse position. GetCursorPos pt ScreenToClient FRM.hwnd, pt ' Convert to twips. x = FRM.ScaleX(pt.x, vbPixels, vbTwips) y = FRM.ScaleY(pt.y, vbPixels, vbTwips) End Sub Then use the x and y cordinates to print your things in that position. This is untested and I'm not even sure if that's what you need or want, but maybe it is something to get you started! HTH Good luck |
|
|
|
Oct 4 2005, 02:42 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 159 From: Enkhuizen, Nederland |
Hi Freak, thanks for responding!
I fear i explained too vaguely though. You see i am a keyboard loving guy, and what i want is a little menu to pop up where the text cursor is: I scroll through the nodes in this tree control, with my up and down buttons, then i press the 'context menu button' on my keyboard, the one with the mouse&menu picture on it. This is where i want the popup menu to show up, making it work as if i took my mouse and right-clicked on this same node. I need the mouse to move to there, simply because a 'custom popup menu' in Access shows up exactamento where the mouse-cursor is. I move the mouse with the SetCursorPos from the user32 api, that works smooth, the problem is finding out the exact coordinates for the spot. I hope this explains my goal better. (I would like to post an example mdb but it is in a huge big application, and it's hard to isolate just the needed parts.) Thanks again, please keep trying - i found nothing still. Humble greetings, Daan |
|
|
|
Oct 4 2005, 03:03 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
Mhhh,
I c, well you could somewhere store the positions of each treeview item (you would need to try that out for each) and then you can use code to determine which part is currently selected, and then if that part is selected, then pull its cordinates and reposition the mouse cursor to that position. I think you could use code like this: If Me.YourTreeView.Object.SelectedItem = "YourItem" Then YourCode to reposition the cursor to that position End If Obviously you can use a case statement if you have many options! HTH Good luck |
|
|
|
Oct 4 2005, 03:17 PM
Post
#5
|
|
|
UtterAccess Addict Posts: 159 From: Enkhuizen, Nederland |
MMhhh!
Thanks once again, but in my tree, there are going to be hundreds of nodes, and i just cannot get any node's coordinates - only when the mouse is right on one of them and clicks it. You know, i think i should be able to ask Windows what the Hwnd of the current selected rectangle is, it's just another window. But there are no child-windows to be found inside the tree-control. As i said, in C++ there is a simple function for the same thingy and we should have that too, but i can't find it. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/crazy.gif) Cheers, Daan o! |
|
|
|
Oct 4 2005, 03:38 PM
Post
#6
|
|
|
UtterAccess VIP Posts: 31,413 From: NC, USA |
Mhhh...no I don't know how to go about this then anymore.
The only way I can see this working as earlier mentioned is to manual check what position each item is at (x,y values), then storing these values somewhere and then checking which is currently selected to pull it's position value and use it to move the mouse. I don't know of any other way or option which actually lets you determine the position of the selected item. By just calling it. Maybe someone else has some more inside on this! HTH Good luck |
|
|
|
Oct 4 2005, 06:16 PM
Post
#7
|
|
|
UtterAccess VIP Posts: 3,645 From: Near Toronto, ON, CA |
I also have no idea. That's not helpful, I realize, but having recently learned how to get cursor position relative to the mouse, or relative to a corner of a control, I can tell you that I saw nothing on location of the text cursor or location of rows within an activeX control. Now if you want to respond to a click that would be way different....
|
|
|
|
Oct 6 2005, 08:53 AM
Post
#8
|
|
|
UtterAccess Editor Posts: 15,974 From: Northern Virginia, USA |
As a "work-around" ... maybe you can just scroll your mouse to a known location in the TreeView control, like the upper left or upper right of the control, then at least, you (and your users), will always know where the context menu will be.
|
|
|
|
Oct 13 2005, 03:09 PM
Post
#9
|
|
|
UtterAccess Addict Posts: 159 From: Enkhuizen, Nederland |
Hallo again,
How very kind of you all to try and help me. Brent your suggestion is a bit like the Freak's first one, but my point is: i wanna be able to do this stuff without the mouse. Isn't that normal no more? I'll leave it to rest for a while now. Got to learn PHP for a new job. Thanks, cheers, Daan o! |
|
|
|
Oct 17 2005, 12:00 AM
Post
#10
|
|
|
UtterAccess Editor Posts: 15,974 From: Northern Virginia, USA |
I mean't for you to scroll (force your mouse to a known location) your mouse programaticaly when the user hit the "flying window" ....
I hate using the mouse ... so I understand your intent !!!! |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 24th May 2013 - 09:13 PM |