Show complete Itemtext on mousehoover...

Just starting out? Need help? Post your questions and find answers here.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Show complete Itemtext on mousehoover...

Post by Joris »

Hi,

How can I retrieve the complete text of each item when the mouse is hoovering them ?
There is some software which does this by showing it in a Tooltiptext-box, the best sollution but in a textbox is also a sollution.
(Now only a part is visible, as the text is indeed to long for some items, and that will probably the case on users freedom...)

Thanks.

Code: Select all

Procedure CMB(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  If  IsGadget(1)
    
    ;If wparam = GadgetID(1)
      Select msg 
        Case #WM_MOUSEHOVER  ; 
          SetWindowTitle(0, Str(wparam)+" "+Str(lparam))
        Case #WM_SETCURSOR
          SetWindowTitle(0, Str(wparam)+" "+Str(lparam))
          Debug Str(wparam)+" "+Str(lparam)
        Case #WM_CTLCOLORLISTBOX
          Debug Str(wparam)+" "+Str(lparam)
         Case #WM_NOTIFY : Debug "WM_NOTIFY"
      EndSelect
    ;EndIf
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,200,"",$C80001)
ComboBoxGadget(1, 10, 10, 285, 20)
SetWindowCallback(@CMB())
 
For a=0 To 20
   s.s= s+ InsertString("test ", "test ", 5)
   AddGadgetItem(1, -1, s  +Str(a))
Next

Repeat
  ev=WaitWindowEvent()
Until ev=#PB_Event_CloseWindow
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4667
Joined: Sun Apr 12, 2009 6:27 am

Re: Show complete Itemtext on mousehoover...

Post by RASHAD »

Hi

Code: Select all

OpenWindow(0,0,0,400,200,"",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ComboBoxGadget(1, 10, 10, 285, 20)
OpenWindow(1,0,0,0,0,"",#PB_Window_BorderLess)
TextGadget(2,0,0,0,0,"",#SS_CENTERIMAGE)
SetGadgetColor(2,#PB_Gadget_BackColor,$E7FEFF)
SetGadgetColor(2, #PB_Gadget_FrontColor, $0000FF)
dlh = FindWindow_("ComboLBox",0)
SetWindowLongPtr_( WindowID(1), #GWL_HWNDPARENT,dlh )

For a=0 To 20
   s.s= s+ InsertString("test ", "test ", 5)
   AddGadgetItem(1, -1, s  +Str(a))
Next

;cbith = SendMessage_(GadgetID(1), #CB_GETITEMHEIGHT, 0, 0) +1
SendMessage_(GadgetID(1), #CB_GETDROPPEDCONTROLRECT, 0, r.RECT)
SetActiveWindow(0)

Repeat
 Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
       Quit = 1
       
    Case #WM_MOUSEMOVE
        If SendMessage_(GadgetID(1), #CB_GETDROPPEDSTATE, 0, 0) = 1
            GetCursorPos_(p.POINT)
            If p\x >= r\left And p\x <= r\right And p\y >= r\top + 20 And p\y <= r\bottom
              index = SendMessage_(GadgetID(1), #CB_GETCURSEL, 0, 0)
              Text$ = GetGadgetItemText(1,index)
              ScreenToClient_(WindowID(0),p)
              ResizeWindow(1,WindowX(0)+20,WindowY(0)+p\y+40,Len(text$)*4+15,20)
              ResizeGadget(2,0,0,Len(text$)*4+15,20)
              SetGadgetText(2,"  "+Text$)
            Else
              ResizeWindow(1,0,0,0,0)
              SetGadgetText(2,"")
            EndIf
        EndIf
        
    Case #WM_LBUTTONUP
        If SendMessage_(GadgetID(1), #CB_GETDROPPEDSTATE, 0, 0) = 0
           ResizeWindow(1,0,0,0,0)
        EndIf
        
 EndSelect
Until Quit = 1
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8435
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Show complete Itemtext on mousehoover...

Post by netmaestro »

Nice work except for this line hurts my eyes:

Code: Select all

If p\x >= r\left And p\x <= r\right And p\y >= r\top + 20 And p\y <= r\bottom
where you might rather do:

Code: Select all

If PtInRect_(r, PeekQ(@p))
and save your precious digits for those emotionally-charged gestures in traffic.

Also, the FindWindow for the list seems a bit loose. It's just going to return the first window of that class it finds. Maybe not the right one? I know GetComboBoxInfo is a pain in PureBasic because the COMBOBOXINFO structure has to be handcoded but reading the hwndList member after this call seems a more solid approach than FindWindow. Just my nitpicky two cents, it's still a great solution you've posted.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4667
Joined: Sun Apr 12, 2009 6:27 am

Re: Show complete Itemtext on mousehoover...

Post by RASHAD »

Hi NM
Unfortunately PtInRect_(r, PeekQ(@p)) will take the gadget itself into account
Just move the mouse over the gadget to see the difference

Thanks for commenting

Code: Select all

Structure COMBOBOXINFO
 cbSize.l
 rcItem.RECT
 rcButton.RECT
 stateButton.l
 hwndCombo.i
 hwndItem.i
 hwndList.i
EndStructure

OpenWindow(0,0,0,400,200,"",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ComboBoxGadget(1, 10, 10, 285, 20)
OpenWindow(1,0,0,0,0,"",#PB_Window_BorderLess)
TextGadget(2,0,0,0,0,"",#SS_CENTERIMAGE)
SetGadgetColor(2,#PB_Gadget_BackColor,$E7FEFF)
SetGadgetColor(2, #PB_Gadget_FrontColor, $0000FF)

inf.COMBOBOXINFO
inf\cbSize = SizeOf(inf)
GetComboBoxInfo_(GadgetID(1),@inf)

SetWindowLongPtr_( WindowID(1), #GWL_HWNDPARENT,inf\hwndList )

For a=0 To 20
   s.s= s+ InsertString("test ", "test ", 5)
   AddGadgetItem(1, -1, s  +Str(a))
Next

;cbith = SendMessage_(GadgetID(1), #CB_GETITEMHEIGHT, 0, 0) +1
SendMessage_(GadgetID(1), #CB_GETDROPPEDCONTROLRECT, 0, r.RECT)
SetActiveWindow(0)

Repeat
 Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
       Quit = 1
       
    Case #WM_MOUSEMOVE
        If SendMessage_(GadgetID(1), #CB_GETDROPPEDSTATE, 0, 0) = 1
            GetCursorPos_(p.POINT)
            If p\x >= r\left And p\x <= r\right And p\y >= r\top + 20 And p\y <= r\bottom
              index = SendMessage_(GadgetID(1), #CB_GETCURSEL, 0, 0)
              Text$ = GetGadgetItemText(1,index)
              ScreenToClient_(WindowID(0),p)
              ResizeWindow(1,WindowX(0)+20,WindowY(0)+p\y+40,Len(text$)*4+15,20)
              ResizeGadget(2,0,0,Len(text$)*4+15,20)
              SetGadgetText(2,"  "+Text$)
            Else
              ResizeWindow(1,0,0,0,0)
              SetGadgetText(2,"")
            EndIf
        EndIf
        
    Case #WM_LBUTTONUP
        If SendMessage_(GadgetID(1), #CB_GETDROPPEDSTATE, 0, 0) = 0
           ResizeWindow(1,0,0,0,0)
        EndIf
        
 EndSelect
Until Quit = 1
BTW
FindWindow_("ComboLBox",0) after any combobox will give us the same result as using the COMBOBOXINFO structure

Code: Select all

Structure COMBOBOXINFO
 cbSize.l
 rcItem.RECT
 rcButton.RECT
 stateButton.l
 hwndCombo.i
 hwndItem.i
 hwndList.i
EndStructure

OpenWindow(0,0,0,600,200,"",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ComboBoxGadget(1, 10, 10, 285, 20)
dlh1 = FindWindow_("ComboLBox",0)
Debug dlh1
inf.COMBOBOXINFO
inf\cbSize = SizeOf(inf)
GetComboBoxInfo_(GadgetID(1),@inf)
Debug inf\hwndList


ComboBoxGadget(2, 310, 10, 100, 20)
dlh2 = FindWindow_("ComboLBox",0)
Debug dlh2
GetComboBoxInfo_(GadgetID(2),@inf)
Debug inf\hwndList

Repeat
 Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
       Quit = 1       
       
 EndSelect
Until Quit = 1
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Show complete Itemtext on mousehoover...

Post by Joris »

Woow that looks great RASHAD !!
Nicely done.

My reserch on the other msg Case's (#WM_CTLCOLORLISTBOX etc) didn't give any possibilities to retrieve the itemindex or itemtext ?
I'm still wondering how some software (Xplorer2) does this within a tooltipbox or would it be just what you created but a bit refined to look as a tooltipbox ?
Now I'm gonna study on what is posted further.

Thanks guys.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4667
Joined: Sun Apr 12, 2009 6:27 am

Re: Show complete Itemtext on mousehoover...

Post by RASHAD »

Hi Joris
Another work around

Code: Select all

OpenWindow(0,0,0,400,300,"Window",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
  ComboBoxGadget(1,10,10,180,24,#PB_ComboBox_Editable)
  
  ListIconGadget(2,10,34,180,250,"",155,#LVS_NOCOLUMNHEADER)
  SendMessage_(GadgetID(2),#LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_LABELTIP,#LVS_EX_LABELTIP) 
  For a=0 To 20
   s.s= s+ InsertString("test ", "test ", 5)
   AddGadgetItem(2, -1, s  +Str(a))
  Next
  HideGadget(2,1)   
      
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
              Case 1
                    
              Case 2
                   SetGadgetText(1, GetGadgetText(2))
                   HideGadget(2,1)
      
          EndSelect           
          
      Case #WM_LBUTTONUP
          If GetActiveGadget() = 1
             HideGadget(2,0)
             SetActiveGadget(2)
          EndIf
                  
  EndSelect 

Until Quit = 1
End
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Show complete Itemtext on mousehoover...

Post by Joris »

RASHAD you did it again !!
Great, mangific everytime to see how you get things done.

So a big thanks again.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply