What’s the difference between LVM_HITTEST and LVM_INSERTMARKHITTEST?

Date:October 24, 2007 / year-entry #386
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20071024-00/?p=24703
Comments:    3
Summary:One customer was confused by the two list view hit-test messages LVM_HITTEST and LVM_INSERTMARKHITTEST. What is the difference between the two? The LVM_HITTEST message tries to find the item the point is over. The LVM_INSERTMARKHITTEST message tries to find the item the point is next to. For example, suppose you have two 32×32 items, item...

One customer was confused by the two list view hit-test messages LVM_HITTEST and LVM_INSERTMARKHITTEST. What is the difference between the two?

The LVM_HITTEST message tries to find the item the point is over.

The LVM_INSERTMARKHITTEST message tries to find the item the point is next to.

For example, suppose you have two 32×32 items, item zero at (0, 0) and item one at (0, 32).

Coordinates LVM_HITTEST LVM_INSERTMARKHITTEST
(0, 34) On item 1 Next to item 1 on the top side
(0, 99) Nowhere Next to item 1 on the bottom side

You use LVM_HITTEST when you the user is dragging something and you want to see what the item is going to be dropped on. For example, your program might ask the user to drag an icon representing a trouble report and drop it onto the icon representing the department the report should be assigned to.

You use LVM_INSERTMARKHITTEST when the user is dragging something and you want to see what the item is going to be dropped between. For example, your program might show a list of customers, and the user can drag a new customer into the list or rearrange the customers by dragging an existing one. The LVM_INSERTMARKHITTEST message tells you where the dropped item should go.

The shell uses both of these hit-test messages when you drop a file into an Explorer window. It uses the Explorer uses LVM_HITTEST to determine whether you're dropping the file onto an item in the folder (hit-test reports an item) or whether you're dropping the file into the folder itself (hit-test reports nowhere). Furthermore, if you're dropping into the folder and Auto-Arrange is enabled, then Explorer uses the LVM_INSERTMARKHITTEST to determine where to place the item after it is dropped.


Comments (3)
  1. COSMO says:

    It seems the same message exist for tool bar (TB_INSERTMARKHITTEST) but not for tree control (

    TVM_INSERTMARKHITTEST).

  2. John says:

    Shouldn’t that be "and Auto-Arrange is disabled"?  If it’s enabled, it doesn’t really matter where you drag it; Explorer is going to re-arrange it.  If it’s disabled, Explorer is going to put it where you drop it.

  3. anon says:

    Perhaps "Align to grid"

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index