AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,148
- Office Version
- 2019
- 2010
- Platform
- Windows
Does anyone know if the hittest function will work with an Inkedit control?
I did know that InkEdit had a few additional interfaces after stumbling across a thread written by wqweto on the topic: COM interfaces in system supplied type libraries-VBForumsThe InkEdit library provides a number of very useful interfaces such as IStream, IRunningObjectTable, IMoniker etc that could potentially be used instead of using low level api com calls hence making the code much easier and shorter. Unfortunately, some of these interfaces are not compatible with VB(A) clients as they use unsupported data types in VB(A). I guess one could still work around this limitation by using light object versions of the interfaces and the IDispatch interface. I would be curious if this could be done.
View attachment 119193
Exactly. I too stumbled on that post by wqweto a few months ago which drew my attention to the potential of using the interfaces that come with the InkEdit lib. It is a shame the tlbs define various functions whose parameters are unsigned longs, not comptaible with VB(A).I did know that InkEdit had a few additional interfaces after stumbling across a thread written by wqweto on the topic: COM interfaces in system supplied type libraries-VBForums
@AlexanderBB I am very sorry, I completely missed these points/question. In terms of the ActiveX prompt, yes I do get that when I load a workbook. This is unforunate, but I may have come up with a workaround, to this and to your points about changing the properties to the InkEdit control. I will pull some code together for you.Found this when trying the workbook on a 2nd machine. Inkedit still had to be (re)applied from Additional Controls. Maybe that's normal. it would also be nice but I think not possible to vary the font used. Do you also get a Active X prompt on startup that won't go away, even when turned off in trust settings?
Set IE = Me.Controls.Add("Inked.Inkedit.1")
Object
data type is that you then lose access to the control's events. There may be a workaround for this, but I haven't thought about it too much.[Side note] | BTW, adding a reference to the InkEd.dll here is how I managed to get access to the TextObjectModel (tom). I think it would be possible to do so without having to make an explicit reference, but that would likely require use of DispCallFunc (? Jaafra can confirm?), which I still can't use without my code crashing Excel half the time. |
[Caveat] | I am so used to clicking on the 'ok' button when that warning appears that I don't know if my proposed 'solution' indeed actually works, or if my 'ok' in relation to another/earlier workbook just carries over and I'm just not seeing it, so it would be useful to check this when/if you try the code above. |
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As LongPtr, _
ByVal wMsg As Long, _
ByVal wParam As LongPtr, _
lParam As Any) As Long
#Else
Private Enum LongPtr
[_]
End Enum
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
#End If
Private IE As Object ' Cannot use the Object data type with WithEvents
Private WithEvents btnUndo As MSForms.CommandButton
Private ControlsInstalled As Boolean
Private Sub btnUndo_Click()
Call DoUndo(IE.hWnd)
End Sub
Private Sub UserForm_Activate()
If Not ControlsInstalled Then
SetupControls
IE.SetFocus
IE.SelStart = Len(IE.Text) ' Puts the cursor at the end of the text
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If ControlsInstalled Then
Me.Controls.Remove IE.Name
Me.Controls.Remove btnUndo.Name
End If
End Sub
Private Sub SetupControls()
Set IE = Me.Controls.Add("Inked.Inkedit.1")
With IE
.MousePointer = 3 ' IMP_Ibeam = this sets the Mouse Point to the
' IBeam you normally get when hovering over the textbox, etc
.Left = 2
.Top = 2
.Height = Me.InsideHeight - 35
.Width = Me.InsideWidth - 4
.BackColor = RGB(10, 20, 30)
.Text = "Some sample text"
.SelStart = 0
.SelLength = Len(.Text)
.SelFontSize = 11
.SelColor = vbGreen
.SelFontName = "Consolas"
.SelLength = 0
End With
Set btnUndo = Me.Controls.Add("Forms.CommandButton.1", "btnUndo")
With btnUndo
.Width = 55
.Height = 25
.Left = IE.Left + IE.Width - .Width
.Top = IE.Top + IE.Height + 5
.Caption = "Undo"
.Accelerator = "U"
.Default = True
End With
ControlsInstalled = True
End Sub
Sub DoUndo(ByVal TargethWnd As LongPtr)
Const EM_CANUNDO = &HC6
Const EM_UNDO = &HC7
Const EM_EMPTYUNDOBUFFER = &HCD
Dim Result As Long
Result = SendMessage(TargethWnd, EM_CANUNDO, 0&, ByVal 0&)
If Result Then
Call SendMessage(TargethWnd, EM_UNDO, 0&, ByVal 0&)
Call SendMessage(TargethWnd, EM_EMPTYUNDOBUFFER, 0&, ByVal 0&)
Else
MsgBox "There is nothing to undo.", vbInformation, "Undo Queue is empty"
End If
End Sub
Sub FixInkEditSettings()
IE.Visible = False
IE.Appearance = 0 ' rtfFlat = 0
IE.ScrollBars = 2 ' rtfVertical = 2
IE.Visible = True
End Sub
Private Sub UserForm_Initialize()
SetupControls
FixInkEditSettings
IE.SetFocus
IE.SelStart = Len(IE.Text) ' Puts the cursor at the end of the text
End Sub