It is currently Thu Nov 21, 2019 10:41 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Can you highlight cell/row in listicon on mouseover
PostPosted: Tue Sep 08, 2015 7:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Hello,

Anybody have any idea how to highlight the selected cell/row within a listicon on mouseover without a click event? Perhaps even with a lighter color than the normal selected item.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Tue Sep 08, 2015 8:49 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
Hi
Code:
Procedure wCback(hWnd, uMsg, wParam, lParam)
Static oldiitem,oldisubitem
Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
        *nmlv.NM_LISTVIEW = lParam
        If *nmlv\hdr\code = #LVN_HOTTRACK And *nmlv\hdr\hwndFrom = GadgetID(0)       
           iitem = *nmlv\iitem             
           isubitem = *nmlv\isubitem
           If iitem >= 0 And (iitem <> oldiitem Or isubitem <> oldisubitem Or (iitem >= 0 And isubitem = 0))
              SetGadgetItemColor(0,oldiitem,#PB_Gadget_BackColor,-1,oldisubitem)
              SetGadgetItemColor(0,iitem,#PB_Gadget_BackColor,$00FF00,isubitem)
              oldiitem = iitem: oldisubitem = isubitem
           EndIf                     
        EndIf     
  EndSelect
ProcedureReturn Result
EndProcedure
 
LoadFont(0,"Arial",12)
If OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
    SetGadgetFont(0,FontID(0))
      For x = 1 To 6     
        AddGadgetColumn(0, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
  EndIf
 
  SetWindowCallback(@wCback())
Repeat
  Select WaitWindowEvent() 
        Case #PB_Event_CloseWindow
              Quit = 1

  EndSelect
Until Quit = 1

_________________
Egypt my love


Last edited by RASHAD on Tue Sep 08, 2015 10:46 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Tue Sep 08, 2015 10:33 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue May 28, 2013 10:51 pm
Posts: 539
Location: Europe
RASHAD wrote:
Hi
RASHAD, as usual, great code, but I must be to tired to figure it out myself - why is the first column highlighted (W7 x64) when you get to the bottom and than hover over "empty" row?

_________________
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Tue Sep 08, 2015 10:47 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
Previous post updated

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Wed Sep 09, 2015 1:40 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Wow, Rashad, that was FAST and great code to boot as usual. I wasn't 100% sure it was possible, but as usual you come through and (BANG!) shoot any doubts dead.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Wed Sep 09, 2015 7:12 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
Hi
Another simple approach
Hope you like it

Code:
Global is.LVHITTESTINFO

Procedure IsMouseOver(hWnd)
    GetWindowRect_(hWnd,r.RECT)
    GetCursorPos_(p.POINT)
    Result = PtInRect_(r,p\y << 32 + p\x)
    ProcedureReturn Result
EndProcedure
 
LoadFont(0,"Georgia",14)
OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
    SetGadgetFont(0,FontID(0))
      For x = 1 To 6     
        AddGadgetColumn(0, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
 
  ListIconGadget(1,  330,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      For x = 1 To 6     
        AddGadgetColumn(1, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(1, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
Repeat
  Select WaitWindowEvent() 
        Case #PB_Event_CloseWindow
              Quit = 1
             
        Case #WM_MOUSEMOVE
          If IsMouseOver(GadgetID(0))
              GetCursorPos_(p.POINT)
              ScreenToClient_ (GadgetID(0), @p)           
              is\pt\x = p\x
              is\pt\y = p\y
              index = SendMessage_(GadgetID(0),#LVM_GETHOTITEM ,0,0)
              SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST ,0,@is)
              If is\iItem >= 0 And index >= 0
                  SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1,oldsubitem)
                  SetGadgetItemColor(0,is\iItem,#PB_Gadget_BackColor,$00FF00,is\iSubItem)
                  olditem = is\iItem
                  oldsubitem = is\iSubItem
              Else
                  SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1,oldsubitem)
                  SetGadgetItemColor(0,is\iItem,#PB_Gadget_BackColor,-1,is\iSubItem)
              EndIf
          EndIf

  EndSelect
Until Quit = 1


Edit :Modified # 2

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Wed Sep 09, 2015 1:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Nice, I like the second one better as it requires no callback. Thanks a ton for that useful code. I like your 'simple' approaches. :D
How would I make it so it highlights the entire row and not just the selected cell? Tried some things, messed it up, had to recopy the code from the post to get it back to working order. :oops:


Edit:

NVM, was able to figure that out at least, amended code below:

Code:
Global is.LVHITTESTINFO

Procedure IsMouseOver(hWnd)
    GetWindowRect_(hWnd,r.RECT)
    GetCursorPos_(p.POINT)
    Result = PtInRect_(r,p\y << 32 + p\x)
    ProcedureReturn Result
EndProcedure
 
LoadFont(0,"Georgia",14)
OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
    SetGadgetFont(0,FontID(0))
      For x = 1 To 6     
        AddGadgetColumn(0, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
 
  ListIconGadget(1,  330,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      For x = 1 To 6     
        AddGadgetColumn(1, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(1, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
Repeat
  Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
              Quit = 1
             
        Case #WM_MOUSEMOVE
          If IsMouseOver(GadgetID(0))
              GetCursorPos_(p.POINT)
              ScreenToClient_ (GadgetID(0), @p)           
              is\pt\x = p\x
              is\pt\y = p\y
              index = SendMessage_(GadgetID(0),#LVM_GETHOTITEM ,0,0)
              SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST ,0,@is)
              If is\iItem >= 0 And index >= 0
                  SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1)
                  SetGadgetItemColor(0,is\iItem,#PB_Gadget_BackColor,$00FF00)
                  olditem = is\iItem
              Else
                  SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1)
                  SetGadgetItemColor(0,is\iItem,#PB_Gadget_BackColor,-1)
              EndIf
          EndIf

  EndSelect
Until Quit = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Wed Sep 09, 2015 3:28 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
As per your last request

# 1 :
Code:
 
LoadFont(0,"Georgia",14)
OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
    SetGadgetFont(0,FontID(0))
      For x = 1 To 6     
        AddGadgetColumn(0, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
 
  ListIconGadget(1,  330,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      For x = 1 To 6     
        AddGadgetColumn(1, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(1, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
     
    SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE,0,SendMessage_(GadgetID(0),#LVM_GETEXTENDEDLISTVIEWSTYLE,0,0)| #LVS_EX_TRACKSELECT)
    SendMessage_(GadgetID(0), #LVM_SETHOVERTIME, 0, 10)
Repeat
  Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
              Quit = 1             

  EndSelect
Until Quit = 1



# 2 :
Code:
Procedure IsMouseOver(hWnd)
    GetWindowRect_(hWnd,r.RECT)
    GetCursorPos_(p.POINT)
    Result = PtInRect_(r,p\y << 32 + p\x)
    ProcedureReturn Result
EndProcedure
 
LoadFont(0,"Georgia",14)
OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
    SetGadgetFont(0,FontID(0))
      For x = 1 To 6     
        AddGadgetColumn(0, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
 
  ListIconGadget(1,  330,  10, 300, 280, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      For x = 1 To 6     
        AddGadgetColumn(1, x, "Column " + Str(x), 120)
      Next
      For x = 0 To 20
          AddGadgetItem(1, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
      Next
     
Repeat
  Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
              Quit = 1
             
        Case #WM_MOUSEMOVE
          If IsMouseOver(GadgetID(0))
              item = SendMessage_(GadgetID(0),#LVM_GETHOTITEM ,0,0)
              If item >= 0
                SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1)
                SetGadgetItemColor(0,item,#PB_Gadget_BackColor,$00FF00)
                olditem = item
              Else
                SetGadgetItemColor(0,olditem,#PB_Gadget_BackColor,-1)
                SetGadgetItemColor(0,item,#PB_Gadget_BackColor,-1)
              EndIf
          EndIf

  EndSelect
Until Quit = 1

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Wed Sep 09, 2015 6:17 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Thanks again RASHAD, I chose to use the #2 on your list as I like the way the item stays highlighted upon clicking on it, works perfectly for my needs. Once again, a million thanks. You must have the MSDN API on a USB drive attached to your head or something as you seem to be a Windows API king 8)


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Fri Jun 14, 2019 3:38 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 394
Rashad, I like the highlighting by changing the background, but is there a way to get a cell's X/Y/W/H dimensions using your code? I want to know how big a cell is, and where it is located on the window. I would get this info when the user clicks the cell. Thanks if you can help.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Fri Jun 14, 2019 7:53 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3457
Hi BarryG
Code:
Procedure IsMouseOver(hWnd)
  GetWindowRect_(hWnd,r.RECT)
  GetCursorPos_(p.POINT)
  Result = PtInRect_(r,p\y << 32 + p\x)
  ProcedureReturn Result
EndProcedure
 
LoadFont(0,"Tahoma",14)

OpenWindow(0, 0, 0, 800, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 600, 380, "Column 0", 120,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  SetGadgetFont(0,FontID(0))
  For x = 1 To 6     
    AddGadgetColumn(0, x, "Column " + Str(x), 120)
  Next
  For x = 0 To 20
      AddGadgetItem(0, -1, "Row : "+Str(x)+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5")
  Next
  TextGadget(1,620,10,170,380,"",#WS_BORDER)
  SetGadgetFont(1,FontID(0))
  i.LVHITTESTINFO   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
          Quit = 1
         
    Case #WM_MOUSEMOVE
      If IsMouseOver(GadgetID(0))
        GetCursorPos_(p.POINT)
        ScreenToClient_ (GadgetID(0), @p)           
        i\pt\x = p\x : i\pt\y = p\y
        SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST ,0,@i)
        text$ = " Row : "+Str(i\iItem)+#CRLF$+" Column : "+Str(i\iSubItem)+#CRLF$
        r.RECT
        r\top = i\iSubItem
        r\left = #LVIR_BOUNDS
        SendMessage_(GadgetID(0), #LVM_GETSUBITEMRECT, i\iItem, r)
        If i\iSubItem = 0
           r\right = SendMessage_(GadgetID(0), #LVM_GETCOLUMNWIDTH, 0, 0)
        EndIf
        text$ = text$ +" X : "+Str(r\left)+#CRLF$+" Y : "+Str(r\top) +#CRLF$+" W : "+Str(r\right-r\left)+#CRLF$+" H : "+Str(r\bottom-r\top)
        SetGadgetText(1,text$)


      EndIf

  EndSelect
Until Quit = 1

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Can you highlight cell/row in listicon on mouseover
PostPosted: Fri Jun 14, 2019 7:58 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 394
Thank you, my friend. I have plans for a small grid of images and wanted to make sure they'd resize to fit the cells. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye