How do I trigger a Left-Click event?

Just starting out? Need help? Post your questions and find answers here.
User avatar
purebuilt
User
User
Posts: 46
Joined: Sun Dec 17, 2006 5:30 pm
Location: Milwaukee, WI, USA

How do I trigger a Left-Click event?

Post by purebuilt »

Hello,

I have a treeview that I want to trigger a Left-Click event on to set the last item selected that last time the program was run.
I can "select" the last item, but the even that is triggered with a Left-Click to select it does not fire.

How can I do it?

Thanks.

DB
- DB
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do I trigger a Left-Click event?

Post by netmaestro »

Code: Select all

OpenWindow(0,0,0,640,480,"")
ButtonGadget(0,300,440,80,20,"close")

AddWindowTimer(0,1, 1000)

Repeat
  ev = WaitWindowEvent()
  If ev=#PB_Event_Gadget
    Debug "Button Clicked!"
  EndIf
  If ev=#PB_Event_Timer
    GetWindowRect_(GadgetID(0), @wr.rect)
    SetCursorPos_(wr\left+40,wr\top+10)
    mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
    mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
  EndIf
Until ev=#PB_Event_CloseWindow
BERESHEIT
User avatar
purebuilt
User
User
Posts: 46
Joined: Sun Dec 17, 2006 5:30 pm
Location: Milwaukee, WI, USA

Re: How do I trigger a Left-Click event?

Post by purebuilt »

What I have is a TreeView that I want to select the last item selected when the program last ran. That selection triggers a procedure that reads the text from the tree and does something. When I set the item state to "selected" I call the other procedure and it is not registering the selection the same way even though it is highlighted. LIke this:

Image

The GKCO shows the "selected" line, but the blue shows the Left-Click selected line and that works. That shows as selected when I run the other procedure. The GKCO line does not. When you click on a tree line it gets the SID and Program Assignments for that listing. I want to set what was selected last time the program ran once it opens. All I get it the GKCO line but the procedure to populate the SID/Program Assignment portion does not recognize GKCO as selected as it does Glaceau in this example.

What am I missing?

DB
- DB
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: How do I trigger a Left-Click event?

Post by kenmo »

It sounds like you are using SetGadgetItemState(), with #PB_Tree_Selected ?

Try just using SetGadgetState().

That might be what you want. I think SetGadgetState is effectively the same as left-click selecting an item in a TreeGadget.

(untested though)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How do I trigger a Left-Click event?

Post by RASHAD »

Hi

Code: Select all

  #TVM_GETITEMHEIGHT = #TV_FIRST + 28
  
  If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TreeGadget(0, 10, 10, 160, 160,#PB_Tree_AlwaysShowSelection)                                         ; TreeGadget standard
    For x=0 To 15 
      AddGadgetItem(0,-1,"item"+Hex(x)) 
    Next
    SetGadgetState(0,6)
    GetWindowRect_(GadgetID(0), @wr.rect)
    Height = SendMessage_(GadgetID(0), #TVM_GETITEMHEIGHT,0,0)
    Itempos = 6 * 16 + 8                            ;Item Index * Height + Height/2
    SetCursorPos_(wr\left+30,wr\top+Itempos)
    mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
    mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
    Debug GetGadgetState(0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do I trigger a Left-Click event?

Post by netmaestro »

I should have mentioned that if you must use SetCursorPos_() it's best to push the current position with GetCursorPos_(), hide the cursor, SetCursorPos_(), fire your mouse events, then pop the cursor back to where it was with SetCursorPos_() and unhide. This way it's seamless to the user. Otherwise he'll feel a bit "hijacked".

@RASHAD: Good work 8)
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How do I trigger a Left-Click event?

Post by RASHAD »

Nothing compared to yours NM
BTW: your last excellent piece of code is for PB v4.6+ :)

2# :

Code: Select all

  If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TreeGadget(0, 10, 10, 160, 160,#PB_Tree_AlwaysShowSelection)                                         ; TreeGadget standard
    For x=0 To 15 
      AddGadgetItem(0,-1,"item"+Hex(x)) 
    Next
    GetWindowRect_(GadgetID(0),r.RECT)
    SetCursorPos_((r\left+5),(r\top+5))
    SetGadgetState(0,2)
    ;SendMessage_(GadgetID(0),#TVM_SELECTITEM,#TVGN_CARET,GadgetItemID(0,2))
    mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
    mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)    
    Debug GetGadgetState(0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
Edit : To get only the select effect
Last edited by RASHAD on Mon Jun 27, 2011 3:40 am, edited 2 times in total.
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do I trigger a Left-Click event?

Post by netmaestro »

BTW: your last excellent piece of code is for PB v4.6+
If you mean CustomRegions.pbi, I made it with the 4.6+ CanvasGadget in mind, but there's nothing in it that requires more than PB 4.5 unless I missed something. The demo of course would need 4.6 but not the include :mrgreen:
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How do I trigger a Left-Click event?

Post by RASHAD »

Native regions license :P
Target Compiler
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do I trigger a Left-Click event?

Post by netmaestro »

Native regions license
Target Compiler
Yep. 4.5+ will compile the library, guaranteed. Not the demo though.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How do I trigger a Left-Click event?

Post by RASHAD »

My mistake then
I do not like .pbi
So always I do copy every thing in one workable piece of code to my archive
Sorry NM
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How do I trigger a Left-Click event?

Post by netmaestro »

RASHAD wrote:I do not like .pbi
I didn't either when I first came to coding in PureBasic. Trust me, you'll come to love it. The alternatives are userlibraries, which break at every new release, dlls which nobody likes to add to their release package, or static libs which PureBasic can't (currently..?) produce. The .pbi option publishes the sourcecode so that anyone who likes your libraries can use them with confidence knowing that they can examine them for stability, make modifications if they wish, and update them for new compiler releases as they come out. In most cases, they can compile them with Tailbite if that's their preference. But the main thing is, their options are wide open and unlimited.

I never release libraries in any other format than .pbi these days. It's the most instructive, helpful and useful way to do it. The community can't learn anything from some unreadable binary file called "Customregions.nothing" located in their userlibraries folder. Like you, I enjoy teaching and watching budding PureBasic coders gain strength. Publishing my libraries in the .pbi format is the only way I can help make that happen.

Let me say also how much I (and I'm sure the admins) appreciate your willingness to share your expertise with the members of this forum. Contributions like yours are invaluable for people who are trying to overcome coding hurdles in PureBasic. 8)
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: How do I trigger a Left-Click event?

Post by rsts »

netmaestro wrote:Contributions like yours are invaluable for people who are trying to overcome coding hurdles in PureBasic. 8)
Yeah, I'd still be a hacker like srod if it wasn't for the two of you showing me the right way to code. :lol:

cheers
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How do I trigger a Left-Click event?

Post by RASHAD »

Ya ,I agree with you rsts but only about NM :P
Sometimes his work is very difficult to trace
His mind is very complicated
Egypt my love
User avatar
purebuilt
User
User
Posts: 46
Joined: Sun Dec 17, 2006 5:30 pm
Location: Milwaukee, WI, USA

Re: How do I trigger a Left-Click event?

Post by purebuilt »

I figured out what is going on. When I set the GadgetItemState() to select the previously selected tree item (the last time the program was run) and then use GetGadgetText() is selects the first item on the list.

I used this code to select the item.

Code: Select all

SetActiveGadget(Main_treeClients)
SetGadgetItemState(Main_treeClients,SelectedItemIndex,1)
When I looked at the GetGadgetItemState() values for all the items they were 8 and the selected value was 9.

What's up with that?

DB
- DB
Post Reply