ListViewGadget and #PB_EventType_RightClick

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

ListViewGadget and #PB_EventType_RightClick

Post by Kiffi »

Hello,

it would be nice, if a ListViewGadget also receives a #PB_EventType_RightClick

Code: Select all

OpenWindow(0, #PB_Ignore, #PB_Ignore, 100, 100, "EventType()")
CreateGadgetList(WindowID(0))
ListViewGadget(0,  5, 5, 90, 90)

For i = 0 To 5
  AddGadgetItem(0, -1, "item no"+Str(i))
Next

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget
      If  EventGadget() = 0

        Select EventType()
          
          Case #PB_EventType_LeftClick  : Debug "LeftClick"  ; This works
          Case #PB_EventType_RightClick : Debug "RightClick" ; This unfortunately not 
            
        EndSelect
        
      EndIf
  EndSelect
ForEver
TIA & Greetings ... Kiffi
Criss
New User
New User
Posts: 9
Joined: Mon Dec 04, 2006 9:41 am

Post by Criss »

Code: Select all

#LB_ITEMFROMPOINT = $1A9

If OpenWindow(0,0,0,290,200,"", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ListViewGadget(0,20,35,250,120)
  For a=1 To 12
    AddGadgetItem (0,-1,"Item "+Str(a)+" of the Listview")
  Next
  SetGadgetState(0,9)
EndIf

Repeat

  Event = WaitWindowEvent()

  If Event = #WM_RBUTTONDOWN
    GetCursorPos_(@cursor_pos.POINT)
    ScreenToClient_(GadgetID(0),@cursor_pos)
    cpos = cursor_pos\x + cursor_pos\y << 16 ; x AND y are passed as lparam
    itemNum = SendMessage_(GadgetID(0), #LB_ITEMFROMPOINT, 0, cpos)

    If itemNum <= CountGadgetItems(0)-1 ; itemNum is zero based
      SetGadgetState(0, itemNum)
    EndIf

  EndIf


Until Event = #PB_Event_CloseWindow
End
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

@Criss: Certainly it is possible with Windows-API, but i would prefer, if PB
supports this eventtype native.

Greetings ... Kiffi
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I think he's just providing a solution until it can become native. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

It's pretty code.. and it works. Good thing I checked here after 4 hours
of trying to make it work that 'pb' way. Hope this is something on the
fix-list.

- np
Post Reply