Page 1 of 1

Windows 7 LVM_GETITEMPOSITION

Posted: Sun May 08, 2011 3:25 am
by Frank Webb
Hello All;

I have the same problem as Gaute as posted in the Microsoft MSDN forum. The LVM_GETITEMPOSITION function does not work for a List-View control declared as LIST or REPORT with OWNERDATA style in Windows 7 32 bit or 64 bit (I've tried both).

It appears to be a problem introduced with the latest version 6 of COMCTL32.DLL, Version 5.8 as used in XP does not have the problem.

Does anyone know if it is possible in PB to specifiy the version and location of a MS DLL as you would in a manifest?

The command syntax is given below and I have not found a way to make this work in Windows 7, the function has always worked correctly though in Windows XP.

result = SendMessage_(DeviceHandle,#LVM_GETITEMPOSITION,ItemIndex,Coord.Point)

The coord\y parameter always returns the same very large value regardless of what ItemIndex value is used.

The MSDN article URL IS:
http://social.msdn.microsoft.com/Forums ... f269d7722/
"LVM_GETITEMPOSITION bug in Vista and Windows 7? (I have no problem in XP)"


Thanks in advance, best regards Frank.

Re: Windows 7 LVM_GETITEMPOSITION

Posted: Sun May 08, 2011 6:05 am
by IdeasVacuum
...from the discussion, it seems that you can use a ListIconGadget() instead?

Re: Windows 7 LVM_GETITEMPOSITION

Posted: Sun May 08, 2011 6:48 am
by RASHAD
Hi
Works as expected
PB v4.51 x86\x64 Win 7 x64

Code: Select all

Procedure WinProc(hwnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  
  Select msg 
    Case #WM_DRAWITEM 
       *lpdis.DRAWITEMSTRUCT = lparam
       Rows = SendMessage_(GadgetID(0), #LVM_GETITEMCOUNT,0,0)
       For i = 0 To Rows
           SendMessage_(GadgetID(0),#LVM_GETITEMPOSITION,i,@p.POINT)        ;Works as expected
           text$ = GetGadgetItemText(0,i, 0)  
           TextOut_(*lpdis\hDC, p\x,p\y,text$, Len(text$))
           text$ = GetGadgetItemText(0,i, 1)
           TextOut_(*lpdis\hDC, p\x+100,p\y, text$, Len(text$))
      Next

    Case #WM_MEASUREITEM 
      *lpmis.MEASUREITEMSTRUCT = lparam 
      *lpmis\itemheight = 16

  EndSelect 
  
  ProcedureReturn result 
  
EndProcedure 


OpenWindow(0,0,0,280,350,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0,10,10,260,310,"Column 0", 100, #LVS_OWNERDRAWFIXED|#PB_ListIcon_GridLines )
AddGadgetColumn(0,1,"Column 1",80)

For i = 1 To 35
AddGadgetItem(0, -1, "Item"+Str(i)+Chr(10)+"Item"+Str(i)+"-2") 
Next
 
SetWindowCallback(@WinProc())

Repeat 
  Select WaitWindowEvent()
  
        Case #PB_Event_CloseWindow
              Quit = 1
               
  EndSelect 
Until Quit = 1


Re: Windows 7 LVM_GETITEMPOSITION

Posted: Sun May 08, 2011 8:11 am
by Frank Webb
Thanks RASHAD but the problem occurs with a "Virtual List-View" control (or ListIconGadget) that uses the OWNERDATA style not the OWNERDRAWN.

The LVM_GetItemPosition works correctly with the normal ListIconGadget control without OWNERDATA (Virtual List-View) style, changing it to a OWNER date style results in the LVM_GetItemPosition function returning a static large valued coord\y value.

From the MSDN article its nothing to do with PB its a Microsoft change to the latest version 6 of the COMCTL32.DLL that is the problem and the problem is not with the version 5.8 used in XP.

I would like to be able to through the PB programming environment use the redistributable version 5.8 of the COMCTL32.DLL to see if this will overcome the problem but I don't know if this is possible under Windows 7.

Re: Windows 7 LVM_GETITEMPOSITION

Posted: Sun May 08, 2011 4:35 pm
by RASHAD
Hello Frank
Just add #LVS_AUTOARRANGE to the ListIcon Gadget creation flags
Tested with PB v4.51 x86 Win 7 Ultimate x64

Code: Select all


#ItemCount = 1000

#LVSICF_NOINVALIDATEALL = 1
#LVN_ODCACHEHINT = #LVN_FIRST - 13


Global Dim myItems.s(#ItemCount,2)

Procedure WinCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
  
  Case #WM_SIZE
        WinX = WindowWidth(0)
        WinY = WindowHeight(0) 
        ResizeGadget(0,10,10,WinX - 20,WinY - 20)
        
    Case #WM_NOTIFY
      *pnmh.NMHDR = lParam
      Select *pnmh\code
        Case #LVN_ODCACHEHINT
          result = 0 
        Case #LVN_GETDISPINFO
          *pnmlvdi.NMLVDISPINFO = lParam
          If *pnmlvdi\item\mask & #LVIF_TEXT
             *pnmlvdi\item\pszText = @myItems(*pnmlvdi\item\iItem,*pnmlvdi\item\iSubItem)
          EndIf

        Case #LVN_ODFINDITEM
          result = -1 
         
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SizeGadget|#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinCallback())
  ListIconGadget(0,10,10,620,240,"ID",50,#LVS_OWNERDATA| #LVS_AUTOARRANGE|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
  ButtonGadget(1,10,260,80,25,"TEST")
  SendMessage_(GadgetID(0), #LVM_SETITEMCOUNT, #ItemCount,1 )
  AddGadgetColumn(0,2,"Name",100)
  AddGadgetColumn(0,3,"Name2",100)
  For i=0 To #ItemCount
    myItems(i,0) = Str(i)
    myItems(i,1) = "Name"+Str(i)
    myItems(i,2) = "Name2"+Str(i)
  Next i

Repeat
  Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow
              Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
            SendMessage_(GadgetID(0), #LVM_GETITEMPOSITION,3,@p.POINT)             
            MessageRequester("System Modal Requester", Str(p\x)+"   "+Str(p\y), #MB_SYSTEMMODAL)

          EndSelect
  EndSelect
Until Quit = 1
EndIf 


Re: Windows 7 LVM_GETITEMPOSITION

Posted: Mon May 09, 2011 4:48 am
by Frank Webb
Hello Rashad;

Many thanks once again, I loaded your program and confirmed that it worked with my PB installation (Version 4.51)
The inclusion of #LVS_AUTOARRANGE did the trick, everything now works in Windows 7 as it used to under Windows XP.

It's interesting that under Windows XP it was not necessary to include the LVS_AUTOARRANGE for the function to work.

best regards ....... Frank

Re: Windows 7 LVM_GETITEMPOSITION

Posted: Mon May 09, 2011 5:55 pm
by IdeasVacuum
...Nothing short of genius Rashad - you have defined a fix where Microsoft did not. Top man! 8)

Re: Windows 7 LVM_GETITEMPOSITION

Posted: Tue May 10, 2011 5:13 am
by RASHAD
Hi IdeasVacuum :)
Thank you
It is a great amount of Good Luck nothing less nothing more