Click here to Skip to main content
15,884,986 members

Comments by Andre Oosthuizen (Top 200 by date)

Andre Oosthuizen 17-Apr-24 12:59pm View    
Using the values from the pointers is not entirely possible and WAY over even my head. Without testing, you can try the following but I personally think that is just paving the way for even more questions and less answers -
To calculate the width of the selection border indirectly you can use the information given by 'EM_GETMARGINS' and some additional Windows messages and properties -
Left and right margins using 'EM_GETMARGINS' -
Dim margins As New RECT()
Dim lParam As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(margins))
SendMessage(Me.Handle, EM_GETMARGINS, IntPtr.Zero, lParam)
margins = Marshal.PtrToStructure(lParam, GetType(RECT))
Marshal.FreeHGlobal(lParam)
Dim leftMargin As Integer = margins.Left
Dim rightMargin As Integer = margins.Right


Width of the rich text box control's client area by subtracting the left and right margins from the control's width -
Dim clientAreaWidth As Integer = Me.RichTextBox1.Width - leftMargin - rightMargin


Width of the rich text box control itself (including borders) by sending the 'EM_GETRECT' message -
Dim controlRect As New RECT()
Dim rectParam As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(controlRect))
SendMessage(Me.Handle, EM_GETRECT, 0, rectParam)
controlRect = Marshal.PtrToStructure(rectParam, GetType(RECT))
Marshal.FreeHGlobal(rectParam)
Dim controlWidth As Integer = controlRect.Right - controlRect.Left


Lastly, calculate the width of the selection border by subtracting the client area width from the control's width -
Dim selectionBorderWidth As Integer = controlWidth - clientAreaWidth
Andre Oosthuizen 17-Apr-24 11:43am View    
You're welcome, glad you found the correct method.
Andre Oosthuizen 17-Apr-24 11:42am View    
These values are actually not meaningless, they are memory addresses or pointers returned that are being used internally by the SendMessage API call. "Doesn't work" is actually meaningless :) as you need to be specific on what does not work.
Andre Oosthuizen 15-Apr-24 11:36am View    
It seems that your 'ItemsSource' expects an object that implements the 'IInspectable' interface, not 'IIterable<iinspectable>'.

Change your class to -
#include <winrt/Windows.Foundation.Collections.h>

struct SuggestionSource : winrt::implements<SuggestionSource, winrt::Windows::Foundation::IInspectable>
{
    winrt::Windows::Foundation::Collections::IVector<winrt::hstring> Suggestions;

    SuggestionSource()
    {
        Suggestions = winrt::single_threaded_vector<winrt::hstring>();
    }

    void AddSuggestion(winrt::hstring suggestion)
    {
        Suggestions.Append(suggestion);
    }
};


This should do the trick.
Andre Oosthuizen 13-Apr-24 14:03pm View    
Let me play with this, there is an easy solution, just missing it right now...