1. I know the Blizzard tooltips take account of the quantity of an item when displaying the Sell Price, but I can't find my way through their code.

    How do I go about reading the stack size of the object that is currently under my mouse. This could be in either a bag, on the auction house, in a bank slot, or anywhere else that a tooltip pops up with information about an item.

    I was trying to get the container frame name and slot number using:

     frame=GetMouseFocus()
     temp=frame:GetName()
    

    and obtaining the container and slot numbers from temp, which would look something like ContainerFrame2Slot6, meaning slot 6 of bag 2.

    However, this points to the 2nd bag that is actually open, which could actually be the fifth bag on my taskbar. GetContainerItemInfo (which returns the itemCount as its 2nd return value) would expect to receive (5,6) as its passed parameters to get the correct information for the item in slot 6 of bag 5, so it would seem this method is not the right way to go about it.

    Any ideas would be very helpful.

    Thanks as always Philburt

    Actually I think I may have found the answer to this after searching through a couple of other addons. The answer may lie in secure-function-hooking one of blizzards tooltip functions, and if I get it to work I'll publish the full answer here.

    Ah, cool!

    Ok, got the answer. Two function hooks are required, one to handle your normal bag contents, and one to handle items in the bank.

     --This Hook Does Standard Bad Items
     hooksecurefunc (GameTooltip, "SetBagItem",
     function(tip, whichbag, whichslot)
     _, StackSize = GetContainerItemInfo(whichbag, whichslot);
     end
     );
    
     --This Hook Does The Bank Objects
     hooksecurefunc (GameTooltip, "SetInventoryItem",
     function (tip, whichunit, whichslot)
     StackSize=GetInventoryItemCount(whichunit,whichslot)
     end
     );
    

    Now, whenever an items tooltip is displayed, (from either your bags or the bank), the variable StackSize will hold (surprise surprise) the size of the stack.

    Just make sure you declare the StackSize as a local variable at the start of your addon, so you can access it anywhere you need to.

    There are other function hooks available to do the same for items in the guild bank, loot on mobs etc, but these two were the main ones i needed.

    Interested in adding this to the snippets page? =)

    Sure - done :)