Can you highlight cell/row in listicon on mouseover
- OldSkoolGamer
- Enthusiast
- Posts: 150
- Joined: Mon Dec 15, 2008 11:15 pm
- Location: Nashville, TN
- Contact:
Can you highlight cell/row in listicon on mouseover
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.
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.
Re: Can you highlight cell/row in listicon on mouseover
Hi
Code: Select all
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
Last edited by RASHAD on Tue Sep 08, 2015 10:46 pm, edited 1 time in total.
Egypt my love
Re: Can you highlight cell/row in listicon on mouseover
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?RASHAD wrote:Hi
- OldSkoolGamer
- Enthusiast
- Posts: 150
- Joined: Mon Dec 15, 2008 11:15 pm
- Location: Nashville, TN
- Contact:
Re: Can you highlight cell/row in listicon on mouseover
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.
Re: Can you highlight cell/row in listicon on mouseover
Hi
Another simple approach
Hope you like it
Edit :Modified # 2
Another simple approach
Hope you like it
Code: Select all
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
Egypt my love
- OldSkoolGamer
- Enthusiast
- Posts: 150
- Joined: Mon Dec 15, 2008 11:15 pm
- Location: Nashville, TN
- Contact:
Re: Can you highlight cell/row in listicon on mouseover
Nice, I like the second one better as it requires no callback. Thanks a ton for that useful code. I like your 'simple' approaches.
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.
Edit:
NVM, was able to figure that out at least, amended code below:
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.
Edit:
NVM, was able to figure that out at least, amended code below:
Code: Select all
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
Re: Can you highlight cell/row in listicon on mouseover
As per your last request
# 1 :
# 2 :
# 1 :
Code: Select all
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
Code: Select all
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
- OldSkoolGamer
- Enthusiast
- Posts: 150
- Joined: Mon Dec 15, 2008 11:15 pm
- Location: Nashville, TN
- Contact:
Re: Can you highlight cell/row in listicon on mouseover
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
Re: Can you highlight cell/row in listicon on mouseover
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.
Re: Can you highlight cell/row in listicon on mouseover
Hi BarryG
Code: Select all
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
Re: Can you highlight cell/row in listicon on mouseover
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.