Is there a SetText message for the Win32 ListBox control? - windows

This is easy in .NET (not my question) but I'm trying to figure out if it is possible to simply change the text of a string in a Win32 list box control given an index.
There is a GetText function that takes an item index but nothing to change the text of an existing item/string. My workaround will be to remove it and add it back in the box (which is also a weird prospect since there is no single command to add a string + item data -- these must be done carefully by inserting the string and then setting the item data on the index of the inserted string, which is tricky (not possible?) with sorting active).

Yes, the lack of a LB_SETITEMTEXT message is a bit weird.
You should put your Delete+Insert+SetData calls between calls to WM_SETREDRAW...

At the risk of being off topic...
I tend to use the ListView control all of the time. You'll want it in report view to mimic a listbox, and, as a plus, it supports multiple columns.
Oh.. and it has a LVM_SETITEM Message :)
http://msdn.microsoft.com/en-us/library/bb761186(v=VS.85).aspx

Although this question is old, but I think this documentation presented by Microsoft will be able to answer anyone questions based on this one.
So according to Microsoft documentation which you can find here
Changes the text of a list-view item or subitem. You can use this
macro or send the LVM_SETITEMTEXT message explicitly.
void ListView_SetItemText(
hwndLV,
i,
iSubItem_,
pszText_
);
And it also presents other macros for managing the list box. You can build a wrapper around this macros to simplify handling list view controls, etc.

Related

IAccessible deisgn questions: child objects, thread safety, and header rows/comctl32.dll header controls, and a few other questions on top of that

So before I continue developing my accessible table I read this, on exposing data tables and the general MSAA documentation and I want to clear up a few things before I actually go ahead and write out this implementation, just so I can get everything just right.
For the record, this table is strictly owner-data and is row-based, where a given row can be selected, and a single cell within this row can be focused. Otherwise it behaves similarly to a listview control, but is not one, so I'm not going to try to take advantage of its accessibility features. In particular, any column can contain text, images, or checkboxes (and I might add more features); there might be background colors and text editability in the future as well. All cells in a given column have one of these types. The type will not change during runtime.
I am choosing to use MSAA because I still need Windows XP support, and I would rather not require developers and end users to have both SP3 and the .net framework together, which UI Automation seems to require (and even if the SP3 part is wrong, the "is not standalone/does not come out of the box with the OS" part still makes me uneasy about implementing that).
Is it process-safe/thread-safe to call my internal control functions within the accessible object method implementations, or should I use WM_USER messages to make sure everything happens all on one thread of one process? (In addition, would my error handling/debugging traps be run in the client or in the server in either case?)
From what I can gather, I need to build a three-level IAccessible hierarchy: the table itself on top, followed by each row, followed by each cell in the row. However, the various IAccessible methods that take a child object only take a VT_I4 VARIANT to specify the child. Does this mean I'm going to have to create an IAccessible for each row as well, or for each cell as well, or something else? Should I have a standard accessible object for each of these? Can they share? And what about NotifyWinEvent(); how would I indicate that a given cell has changed? Or should I say the whole row has changed...?
If the answer to question 2 is "yes", I'm going to wind up with a lot of IAccessible objects that need to be notified when the table control is destroyed. If the answer to question 1 is "it is not thread-safe", then is it safe to hold a lock in my IAccessible methods whenever I access my table control and have that hold the lock when it's time to invalidate all those IAccessibles? Or should I investigate some other approach? I see talk on MSDN of "proxy objects" but I'm not really following how that would help... especially if I need to make lots of IAccessibles.
From what I can gather I need to return (number of rows) + 1 rows in my table's get_accChildCount() method, with the first row being full of column header cells. But I'm not using a custom header control; I'm using the standard comctl32.dll header control. Should I hide that control and construct my column headers according to the Exposing Data Tables document or should I relegate the first row to the header control? I don't see a way to do both... (I do not have row headers, so will not be implementing that.) Columns can be user-resized, but may be automatically sized to fit until the user first does so (maybe).
Is it safe to relegate IDispatch methods to the window handle's standard accessible object? Even in the case of the row and cell IAccessibles? Or will the standard accessible object's IDispatch not call my IAccessible methods?
What should accDoDefaultAction() do for a checkbox cell, toggle the checkbox state? And for an editable text cell, should it enter editing mode?
Thanks. (Hoping none of this sounds dumb...)
UPDATE 6 January 2015
I changed the wording of some of the paragraphs above and have one more question:
How do I correctly check for errors from LresultFromObject(), by casting to an HRESULT and checking that, or by comparing a signed version of the LRESULT value and seeing if it's less than zero, or something else?

UI Automating a VB6 application from .NET

For the last few days i have been trying to figure out the best way to get AutomationElement for a specific control in a vb6 application.
My initial way of doing so was by doing a search with the following condition:
new PropertyCondition(AutomationElement.NameProperty, controlName)
I was under the assumption that this was working correctly for about a week in a little test VB6 application.
but i few days ago i realized something... when i dragged a vb6 textbox into the form, the 'Name' property and 'Text' property were both set to 'Text1'
So when i searched with:
new PropertyCondition(AutomationElement.NameProperty, 'Text1')
it return the correct element, but if i then went and set the 'Text' property to '' the same search would bring nothing back.
Question: Has anyone found a way to get a AutomationElement based on a the VB6 control name
What i have tried:
getting the MSAA equivalent interface and looking at the 'Name' property - Result: ''
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318490%28v=vs.85%29.aspx
getting the control based on other properties (AutomationId, RuntimeId) - Result: AutomationId - not all controls seem to have this property available - RuntimeId - changes each time the app runs
I have looked at alot of different sites the main one is listed below - while some say they have manage to get it working - i don't believe i can see how they do it.. or i just dont understand it :$
http://blogs.msdn.com/b/brianmcm/archive/2006/01/17/getting-the-winforms-id-of-a-control.aspx
While i have access to the demo app, i will not access to the production app as that has been created by a third party.
What i plan on doing from here is to get the Automation element based on their position on the form..
Thank you
Can't comment due to low rep. Do you absolutely HAVE to have an AutomationElement?
You may want to look at invoking [user32.dll] (http://pinvoke.net/default.aspx/user32.EnumChildWindows). Look at FindWindowEx, GetWindow, EnumWindows, EnumChildWindows, GetWindowText, etc.
You need the handle of the parent window, so you can use this loop to get it. From there you can use the other functions to get the information you need about the control.
IntPtr hWnd = IntPtr.Zero;
foreach(var process in System.Diagnostics.Process.GetProcesses())
if(condition)
hWnd = process.Handle;
Comment with the exact information you need out of the VB6 window, and I'll give you better code.
You can use the relational position of the AutomationElement in a specific Window (or any other container for that matter), in order to detect it. For example, if you have 5 TextBox AutomationElements in your main window, and you're certain that the order will not be changing, you could create a PropertyCondition on the TextBox class name, and then use the FindAll method to return a collection of AutomationElements and iterate through it, querying the BoundingRectangle property to find out which is the lowest one (or middle, or any other position, for that matter).
I would create a helper method that would return a Dictionary<int,AutomationElement> with the key being the visual position of the AutomationElement, and the value being the AutomationElement itself.
This way you can avoid using a specific Point on your screen (any window size change or element positioning will easily break your code) while not being bound to the AutomationId property.

How do I go about writing new controls in VB6?

I'm looking to create controls based on text boxes that validate numeric fields and restrict them to certain ranges without having to write all the callbacks for each control on the form.
Does anyone know of a tutorial on how to create and use such things?
Or alternatively, as I can't be the first person to have this requirement, are there a set of such controls available for use anywhere?
The simplest way is to use control arrays. Google turned up this tutorial. You could encode the minimum/maximum range into the Tag property of each individual control, or you could use the Index to look them up from arrays.
You can create a user-defined control in VB6 but I'm not sure it's worthwhile for this task. You have to write a lot of boilerplate code.
I think you can use the default text box, using the Validate event, or alternatively, if you need "live" checking then you could check in the KeyPressed, Change, etc events.

Custom editor in QAbstractTableModel

Does anyone have an example of using a QWidget as an editor in a QAbstractTableModel?
I have a column which when edited should create a QCombobox with the list of choices.
The docs seem to suggest I need to write a QAbstractItemDelegate and a custom paint function but that seems overkill to simply pop-up a standard QCombobox in Qt::EditRole.
Note - the combo box contents are the same for every row and it only needs to be shown when somebody clicks in the cell.
I know this should be simple but I can't get it to work. It's easy for a QTableWidget based table - but I need it for a very large data table.
The docs seem to suggest I need to write a QAbstractItemDelegate and a custom paint function but that seems overkill to simply pop-up a standard QCombobox in Qt::EditRole.
You don't need to go that far. One way is to subclass QStyledItemDelegate and then override createEditor() so that it returns your prepopulated combo box. Its setEditorData and setModelData functions will probably already suffice if you`re using basic Qt value types.
If you need something more generic that works across many different models, you can create a QItemEditorFactory that associates your editor with the correct type. This also works well with custom types.
When indicated by your view's EditTrigger, your view will get the delegate specific to the cell on which the edit is being invoked and call delegate->createEditor(...) which can then size the combo box according to the options parameter as well as set the current entry to the value specified by the model, although most of this should be handled by the QStyledItemDelegate. Thus, you won't have to worry about the Qt::EditRole directly as the view will handle that.
Did you try and have a look at the following example from Qt :
Spin Box Delegate Example
Maybe it will give you a much clearer view on the subject !
Hope it helps a bit !

Outlook 2003 - Add an icon column to a View?

I want to add a custom column to the Inbox which is a Yes/No column. I want an icon to show in the Yes case. How can I do this?
Everything I've looked up is either about adding a column through the View.XML property, through UserProperties.Add with addToFolderFields = true, or through Field Chooser.
There are also a lot of forums where Dmitry from dimastr.com just tells people it's not possible to set an icon with no real explanation.
It's pretty frustrating - why would Outlook's UI support creating Icon fields if you can't set an icon for them?! Won't they just always be blank columns?!
Some alternative questions that would also help if they were answered:
What is the "bitmap" element in the View.XML of a <column>?
How can I set a userproperty as the value of a column using the "prop" element of a <column>?
Where can I find a description of the View.XML definition? Microsoft articles all have bad links.
Icons in the Header and icons in the column itself aren't possible without some kind of Windows API hacks on the column cells.
If someone has a good one, I'll mark it as an answer. Otherwise, I'll mark this ("Impossible") as the accepted answer.
EDIT: I looked with Spy++. Outlook's view is a "SUPERGRID" that is manually painted. You don't have access to individual cells. So that makes it a lot harder. A hack would have to like subclass the SUPERGRID and override some internal method or something. Then replace Outlook's SUPERGRID with the subclassed one. Or something equally terrible. I'm thinking impossible is the only real answer...
may you check that thread, therer might be an solution via form
http://www.outlookcode.com/threads.aspx?forumid=3&messageid=31897

Resources