Notifications
Clear all

[Closed] ActiveX hittest?

I can’t get the example in the MAXHelpReference concerning “Hittest” to work:

My sample script could be :


rollout listview_rollout "tst" width:180 height:180
(
activeXControl lv_obj "MSComctlLib.ListViewCtrl" width:150 height:150
on listview_rollout open do 
 (
 lv_obj.View = #lvwReport  
 column = lv_obj.ColumnHeaders.add() 
 column.text = "tst"
 LV_FIRST = 0x1000
 LV_SETCOLUMNWIDTH = (LV_FIRST + 30) 
 windows.sendMessage lv_obj.hwnd LV_SETCOLUMNWIDTH 0 100
 lv_obj.ListItems.clear()
 for o in objects do
  (
  li = lv_obj.ListItems.add()
  li.text = o.name
  )
 )
 
on lv_obj mousemove button shift x y do
 (
 pt = getCursorPos lv_obj --get the screen position in pixels
 TwipsPerPixel = 15 --define the twips per pixel factor
 --Now get the list items under the cursor:
 ListItems = lv_obj.hitTest lv_obj.hWnd [((pt.x-2)*TwipsPerPixel),((pt.y-2)*TwipsPerPixel)]
 print ListItems 
 )
)
createdialog listview_rollout 


When “using” the script I get : “ComObject method failed, hittest()”

What am I missing?? Tried everything but even “by the book” it doesn’t work…

7 Replies

try:

rollout listview_rollout "tst" width:180 height:180
 (
 activeXControl lv_obj "MSComctlLib.ListViewCtrl" width:150 height:150
 on listview_rollout open do 
  (
  lv_obj.View = #lvwReport  
  column = lv_obj.ColumnHeaders.add() 
  column.text = "tst"
  LV_FIRST = 0x1000
  LV_SETCOLUMNWIDTH = (LV_FIRST + 30) 
  windows.sendMessage lv_obj.hwnd LV_SETCOLUMNWIDTH 0 100
  lv_obj.ListItems.clear()
  for o in objects do
   (
   li = lv_obj.ListItems.add()
   li.text = o.name
   )
  )
  
 on lv_obj mousemove button shift x y do
  (
  pt = getCursorPos lv_obj --get the screen position in pixels
  TwipsPerPixel = 15 --define the twips per pixel factor
  --Now get the list items under the cursor:
  ListItems = listview.hitTest lv_obj.hWnd [x,y]
  print ListItems 
  )
 )
 createdialog listview_rollout

I think the ‘hittest’ you were accessing with ‘lv_obj.hittest’ was a different function to the tool ‘listview.hitTest’. One requires just a x and y parameters the other requires the ‘hWnd’ and a point2. I realise that in the help docs it says to do this but I guess it’s a mistake? It also tells you to use the ‘[((pt.x-2)*TwipsPerPixel),((pt.y-2)*TwipsPerPixel)]’ method to get the x and y but that I found to return incorrect values.

In general activeX and maxscript is a bit voodoo so I hope you’re of a sane disposition before you’re starting this

Quote from the Help:

The following additional functions packaged in a structure called [b]ListView[/b] work in conjunction with the ListView ActiveX Control. All functions need to be passed the windows handle, which can be acquired with the .hWnd property of the ActiveX control.

[b]Listview[/b].[b]hittest[/b] <hWnd> <point2_pos>

Returns an array of listitem index and the subItem index, subItem index is 0 only when the listItem is hittested. The Point2 value is expected in Pixels, NOT twips!

Note that it shows Listview. in BOLD, which according to “Syntax Definitions in this document” means “written as is”. If it was <listview>. you would have to replace the placeholder rule with an actual AX control…

There IS a misformatting (missing L) in the current build of the help but will be fixed in Max 8.

Are you sure this is in the max 7 help? I can’t find any reference to this in any of the max 7 maxscipt help docs?

The most information I can get out of the docs about hittest is:

[left]The following additional ListView functions work in conjunction with the ListView ActiveX Control. All functions need to be passed the windows handle, which can be acquired with the .hWnd property of the ActiveX control.
[/left]
[left]listview>.hittest <hWnd> <point2_pos>
[/left]
[left]Returns an array of listitem index and the subItem index, subItem index is 0 only when the listItem is hittested.
[/left]
[left]What are Twips?
[/left]
[left]The <point2_pos> value is expected in “twips” (“twentieths of a point”).
[/left]
[left]This means that the screen coordinates in pixels have to be converted to twips before passing to the hitTest method.

[/left]
[left]For example:
[/left]
[left]pt = getCursorPos lv [color=green]–get the screen position in pixels[/color]
[/left]
[left]TwipsPerPixel = 15 [color=green]–define the twips per pixel factor[/color]
[/left]
[left][color=green]–Now get the list items under the cursor:[/color]
[/left]
[left]ListItems = lv.hitTest lv.hWnd [((pt.x-2)*TwipsPerPixel),((pt.y-2)*TwipsPerPixel)]

[/left]
[left]

[/left]

1 Reply
(@bobo)
Joined: 10 months ago

Posts: 0

No, it is not. It was documented incorrectly (shoot me :)) and I fixed it in the 7Rev1 update of the help, but it is still missing the L in the 7.5 update(the reason for the missing L is that there was a Keyword marker in the original source code, but the new CHM compiler behaves differently with Keywords).
All MAXScript reference updates are being made public through the Autodesk webpage:
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=5659551

Thanks guys … solved the issue

Bobo:
Yep, that was the problem. It’s working now … unfortunately it’s not what I was looking for :sad:. Perhaps you already noticed my intention. I’d like to see what item is under the mouse when it moves over the listview. I can handle it base on coordinates as long as the list doesn’t get longer than the visible field (scrolling). When scrolling the mouse coordinates stay the same but the items under it change. Any idea how to solve this?

Impus:
I was refering to the same part in the help file but as Bobo said, there seems to be a little mistake there. Anyway, that’s sorted out now. Yeah, I know the ActiveX stuff is pretty voodoo. Started using it under max6 and then there was not a single reference for it in the help file :D. I’m starting to get a bit familiar with it now ;).

Oups! Correction! I does give me the correct info!
Was testing it on an empty list :banghead: .

1 Reply
(@bobo)
Joined: 10 months ago

Posts: 0

It should
It is the only way to know what is under the mouse when the listview has scrolled…