1

Using Win32 API functions on VB6/VBA, I would like to create a SUB procedure like the following:

Call SelColor(Lview, Row, Col, Start, Len, Color) 

Where Lview is the target control (in this case a Listview), Row and Col are the coordinates to find the target text, and Start, Length and Color are the parameters to set the color to the selected the text.

I know that this can be easily done in a Richtextbox using the following code:

    RTB.SelStart = 2    ' Starts selection at character 2
    RTB.SelLength = 3   ' Selecting 3 characters 
    RTB.SelColor = blue ' Setting blue color for selection

However, I have not been able to find a direct way to do it on multirow controls like Listbox, Combobox, ListView, Flexgrid, and so on.

Can you please provide some guidance on API functions to achieve the intended job?

Thanks!!!

Frank Zav
  • 11
  • 1
  • None of the controls support rich text. Aside from owner-drawing I suspect there is no way to do this. Even then you'd have to store markup somewhere describing your color changes within a cell so you can draw them correctly. – Bob77 Feb 16 '21 at 07:47
  • Does [this](https://stackoverflow.com/questions/4999822/changing-the-text-colour-in-a-listview-control-win32) answer your question? – Strive Sun Feb 17 '21 at 01:46
  • Thanks Bob77 and StriveSun for sharing your thoughts. – Frank Zav Feb 18 '21 at 00:05
  • Hi @Bob77 I've seen lots of **API** programming examples doing advanced tasks on User Interface elements as well as at OS level like _**API hooking/subclassing**_ or _**copying/retrieveng data to/from other programs memory areas**._ So my instinct tells me that there should be a way to do the intended job using API functions. For example, It can be a good start to try the _**ExtTextOut**, **SetTextColor**, and **Textwidth**_ API functions as well as some others to **get the coordinates** from every area where I want to place the colored text. – Frank Zav Feb 18 '21 at 20:00
  • Hi @StriveSun-MSFT. I checked your recommended [article](https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win32-API). The job done is very close to what I am looking for. However, It doesnt do exactly what I want (**_Set Text/Background color of selected text in a cell from any multirow control_**). Instead, It **_sets the color for the whole text in a cell_**. On the other side, the code was done in **_VC++ 6_**. I dont understand **_C++_** syntax. I am looking for **_VB6_** code with **API** functions. Thanks ...! – Frank Zav Feb 18 '21 at 20:43
  • I did not try the code in the article. For the code of vb6, I think you only need to understand the api call, you can write your own code. – Strive Sun Feb 19 '21 at 02:30

0 Answers0