Programmatically applied mouse click

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Programmatically applied mouse click

Post by IdeasVacuum »

PB 5.60 x86 Win7 x86
If the User mouse-clicks a ListIcon row to select it, that row is highlighted (#COLOR_HIGHLIGHT). If the row is selected programmatically using SetGadgetState(MyList, MyRow), the row is not highlighted.

Is there a simple way to send a mouse click to a specific row to get that highlighting?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Programmatically applied mouse click

Post by RASHAD »

Hi
No need for simulating mouse click

Code: Select all

Procedure selectrow(gadget,index)
  Row_H = SendMessage_(GadgetID(gadget), #LVM_GETITEMSPACING, 1, 0) >> 16 
 SendMessage_(GadgetID(0), #LVM_SCROLL, 0,-CountGadgetItems(gadget)*Row_H)
  SetGadgetItemState(gadget,index,#PB_ListIcon_Selected)
  SetActiveGadget(gadget)  
  SendMessage_(GadgetID(0), #LVM_SCROLL, 0,index*Row_H)
EndProcedure

LoadFont(0,"Arial",12)
If OpenWindow(0, 0, 0, 640, 350, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 400,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect| #PB_ListIcon_AlwaysShowSelection)
    SetGadgetFont(0,FontID(0))
    AddGadgetColumn(0, 1, "Column 1" , 200)
    For x = 0 To 100
      AddGadgetItem(0, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x))
    Next
    
    ButtonGadget(1,10,310,80,20,"TEST")
EndIf
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          If run = 0
            run = 1
            selectrow(0,2)
          ElseIf run = 1
            run = 2
            selectrow(0,15)
          ElseIf run = 2
            selectrow(0,4)
          EndIf
      EndSelect
  EndSelect
  
Until Quit = 1
But if it is required

Code: Select all

Procedure Selectrow(gadget,index)
  r.RECT
  Cell.LVHITTESTINFO 
  Cell\iItem       = index
  r\left = #LVIR_BOUNDS 
  SendMessage_(GadgetID(gadget), #LVM_GETSUBITEMRECT, Cell\iItem, r)
  MapWindowPoints_(GadgetID(0),0,r,1)
  SetCursorPos_(r\left+10,r\top+10)
  In.INPUT
  In\type        = #INPUT_MOUSE
  In\mi\dwFlags  = #MOUSEEVENTF_LEFTDOWN
  SendInput_(1,@In,SizeOf(INPUT))
  In\mi\dwFlags  = #MOUSEEVENTF_LEFTUP  
  SendInput_(1,@In,SizeOf(INPUT))
EndProcedure

LoadFont(0,"Arial",12)
If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 400,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect| #PB_ListIcon_AlwaysShowSelection)
    SetGadgetFont(0,FontID(0))
    AddGadgetColumn(0, 1, "Column 1" , 200)
    For x = 0 To 100
      AddGadgetItem(0, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x))
    Next  
  
  Selectrow(0,2)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Programmatically applied mouse click

Post by IdeasVacuum »

Hi Rashad :D

Thanks for that very quick help - the difference was actually made by SetActiveGadget(MyListIcon) :oops:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply