1. Win32Lib - Updating Interface with Click on TV

When clicking on the TreeView in the following program, the label text should be updated with the currently selected TV item. However, it always lags behind one. I'm sure I'm doing something stupid... but what? :/

--  code generated by Win32Lib IDE v0.19.1 
 
  
include Win32lib.ew 
without warning 
 
-------------------------------------------------------------------------------- 
--  Window Window1 
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300, 0, 0 ) 
constant TreeView2 = createEx( TreeView, "TreeView2", Window1, 8, 12, 208, 200, w32or_all({TVS_HASLINES,TVS_LINESATROOT,TVS_HASBUTTONS,TVS_SHOWSELALWAYS}), 0 ) 
constant closefolder = addIcon( extractIcon("clsdfold.ico") ) 
constant openfolder  = addIcon( extractIcon("openfold.ico") ) 
constant LText3 = createEx( LText, "LText3", Window1, 228, 80, 148, 20, 0, 0 ) 
--------------------------------------------------------- 
-------------------------------------------------------------------------------- 
procedure Window1_onActivate (integer self, integer event, sequence params)--params is () 
atom rent 
	rent = addTVItem( TreeView2, 0, 0, "Momma", 0 ) 
	for t=1 to 10 do 
		VOID = addTVItem( TreeView2, 0, 0, "Item #" & sprint(t),rent) 
	end for 
end procedure 
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate")) 
-------------------------------------------------------------------------------- 
procedure TreeView2_onClick (integer self, integer event, sequence params)--params is () 
	setText( LText3, getTVSelectedText( self ) ) 
end procedure 
setHandler( TreeView2, w32HClick, routine_id("TreeView2_onClick")) 
 
 
WinMain( Window1,Normal ) 
new topic     » topic index » view message » categorize

2. Re: Win32Lib - Updating Interface with Click on TV

euphoric said...

When clicking on the TreeView in the following program, the label text should be updated with the currently selected TV item. However, it always lags behind one. I'm sure I'm doing something stupid... but what? :/

No, your code is good. I know the problem but haven't got a good solution yet.

The problem is that Microsoft has made different rules for treeviews and it regards a click to occur on a mousedown event for a TV item, but it only changes the selection after the mouseup event. So your code is getting the text from the item that was selected at the time the mousedown happened, but then after you display the text, Microsoft changes the selection to the item that the mouse(up) event occured on.

I'm trying different ideas to get around this stupidity, but haven't got the ideal solution yet.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Win32Lib - Updating Interface with Click on TV

Here is some code that seems to work for me.

   
include Win32lib.ew  
without warning  
  
--------------------------------------------------------------------------------  
--  Window Window1  
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300, 0, 0 )  
constant TreeView2 = createEx( TreeView, "TreeView2", Window1, 8, 12, 208, 200, w32or_all({TVS_HASLINES,TVS_LINESATROOT,TVS_HASBUTTONS,TVS_SHOWSELALWAYS}), 0 )  
constant closefolder = addIcon( extractIcon("clsdfold.ico") )  
constant openfolder  = addIcon( extractIcon("openfold.ico") )  
constant LText3 = createEx( LText, "LText3", Window1, 228, 80, 148, 20, 0, 0 )  
---------------------------------------------------------  
--------------------------------------------------------------------------------  
procedure Window1_onActivate (integer self, integer event, sequence params)--params is ()  
atom rent  
	rent = addTVItem( TreeView2, 0, 0, "Momma", 0 )  
	for t=1 to 10 do  
		VOID = addTVItem( TreeView2, 0, 0, "Item #" & sprint(t),rent)  
	end for  
end procedure  
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate"))  
--------------------------------------------------------------------------------  
integer pendclick = 0 
procedure TreeView2_onClick (integer self, integer event, sequence params)--params is ()  
	setText( LText3, getTVSelectedText( self ) )  
	pendclick = 1 
end procedure  
setHandler( TreeView2, w32HClick, routine_id("TreeView2_onClick"))  
 
 
procedure TreeView2_onChange (integer self, integer event, sequence params)--params is () 
	if pendclick = 1 then 
		setText( LText3, getTVSelectedText( self ) )  
		pendclick = 0 
	end if 
end procedure  
setHandler( TreeView2, w32HChange, routine_id("TreeView2_onChange"))  
  
  
WinMain( Window1,Normal )  


The trick is to show the text on every click event AND on every Change event if a click has also just occurred.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Win32Lib - Updating Interface with Click on TV

Derek, what about putting the code in the onEvent handler, specifying "if params[1] = WM_LBUTTONCLICK" (or whatever the constant is)? I'll try to find that constant and test it out...

new topic     » goto parent     » topic index » view message » categorize

5. Re: Win32Lib - Updating Interface with Click on TV

For now, I'm putting it in the onChange event handler. Seems to work out just fine for my purposes.

Thank you!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu