How do I trigger a Left-Click event?
How do I trigger a Left-Click event?
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
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
- netmaestro
- 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?
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
Re: How do I trigger a Left-Click event?
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:

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

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
Re: How do I trigger a Left-Click event?
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)
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)
Re: How do I trigger a Left-Click event?
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
- netmaestro
- 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?
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
@RASHAD: Good work

BERESHEIT
Re: How do I trigger a Left-Click event?
Nothing compared to yours NM
BTW: your last excellent piece of code is for PB v4.6+
2# :
Edit : To get only the select effect
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
Last edited by RASHAD on Mon Jun 27, 2011 3:40 am, edited 2 times in total.
Egypt my love
- netmaestro
- 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?
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 includeBTW: your last excellent piece of code is for PB v4.6+

BERESHEIT
- netmaestro
- 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?
Yep. 4.5+ will compile the library, guaranteed. Not the demo though.Native regions license
Target Compiler
BERESHEIT
Re: How do I trigger a Left-Click event?
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
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
- netmaestro
- 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?
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.RASHAD wrote:I do not like .pbi
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.

BERESHEIT
Re: How do I trigger a Left-Click event?
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.netmaestro wrote:Contributions like yours are invaluable for people who are trying to overcome coding hurdles in PureBasic.

cheers
Re: How do I trigger a Left-Click event?
Ya ,I agree with you rsts but only about NM
Sometimes his work is very difficult to trace
His mind is very complicated

Sometimes his work is very difficult to trace
His mind is very complicated
Egypt my love
Re: How do I trigger a Left-Click event?
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.
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
I used this code to select the item.
Code: Select all
SetActiveGadget(Main_treeClients)
SetGadgetItemState(Main_treeClients,SelectedItemIndex,1)
What's up with that?
DB
- DB