HitTest and InkEdit Control

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,074
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Does anyone know if the hittest function will work with an Inkedit control?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do you mean, whether or not clicking in a certain section/region/part of the control will register?
 
Upvote 0
Yes, absolutely. I just need to know which row. Or what is on that row.
 
Upvote 0
So I just checked - I was sure that there was a CurLine property or something like that, but I guess not

There is likely a way of getting that info via the TOM (Text Object Model), but I haven't looked into it too closely. The quick and 'easy' way of doing it is to use the SendMessage API against the controls hWnd property.

VBA Code:
Private Declare PtrSafe Function SendMessage Lib "user32" _
     Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
     ByVal wParam As Long, ByVal lParam As Long) As Long

Const EM_LINEFROMCHAR = &HC9

Function GetCurrentLineNumber () As Long
    Dim CurrentLine As Long
    CurrentLine = SendMessage(InkEdit1.hWnd, EM_LINEFROMCHAR, -1, 0)
    GetCurrentLineNumber = (CurrentLine + 1)
End Function
 
Upvote 0
Solution
That's brilliant Dan, works spot on!
Amazing what you can do when you know how.
Many thanks.
 
Upvote 0
You're welcome. This has sent me down a rabbithole though. There must be a better way of doing this. I did a lot of study on the InkEdit control, and by extension RTF and the RichEditTextbox. There is certainly a lot of functionality that I don't think the VBA community (at least) takes advantage of - the automatic spell checking in the inkedit control, or margins and line numbers, etc etc. You can have RichText msgboxes as well, which is flat-out amazing.

And depending on what you're doing, you may even be interested in the Scintilla control - that's the control used in things like Notepad++ etc for code editing.

Anyway, like a said.. a rabbit hole!
 
Upvote 0
That's a coincidence. Originally I started with a Rich textbox but I couldn't find enough info on Excel usage with colours etc and was pointed to the InkEdit control.
This lets me mix colours and bold text and now with a click event is perfect. I do have Notepad ++ but I'm no expert and getting a bit long in the tooth to learn - but still trying!
 
Upvote 0
As discussed on the other thread, here is some of the information I've managed to pull together re: the InkEdit control and the Text Object Model (tom). I understand what you mean re: there being a lack of resources re: the InkEdit control. To be honest, I genuinely don't think that many people even know that it even exists, and of those that do, even fewer know about the InkPicture control... but that's a whole separate rabbit hole!

Ink Edit Control: - I don't know if this is the 'official' documentation for the InkEdit control, but it looks pretty 'official'y to me.
RichEdit - I have found from personal experience that restricting any research into the topic by contraining it to "inkedit" and "vba" somewhat misses the point. It is, at the end of the day, an underappreciated RichEdit TextBox. When we think about it in those terms, we can see a lot more information about what we can do with it: RichEdit versions

Importantly, I've found the best source of information to be the VB6 community - which is unsurprising, given that (at the end of the day) = vb6 = vba - [RESOLVED] InkEdit Control-VBForums , VB6 - InkEdit and SelText-VBForums , Ink Edit Spell Checking-VBForums , VB6 - Ink Editor-VBForums (are a handful of examples)

Text Object Model - I think that the best way of understanding the Text Object Model is to think about it in the same terms as Word VBA - there is a Document (ITextDocuemnt) with Stories (ie. Header/Footer. etc), comprising of a Selection (ActiveDocument.Selection) and Ranges(Application.Range).. I don't know that it gives us 'more' functionality than APs do - it just makes things easier to deal with - Text Object Model - Win32 apps So, for example, to get the current line of the cursor in the InkEdit control (as per your Original Post above), via the Text Object Model, all we need to do is something along the lines of:

VBA Code:
GetCurrentLineNumber = TextDocument.Selection.GetIndex(tomLine)

This is a slight oversimplification, but it's broadly along these lines. A little bit further down the InkEdit Control rabbit hole took me to where I am currently, which is finalising the API generated Inkedit Control (ie., RichEdit TextBox) that functions like a multi-font/multistyled/multicolour Caption:

1731284023212.png


Also, there is a whole lot of functionality available that I never expected - like it has a basic form of spell checking available in it! And you can use it to autodetect URLs... for example:

1731284282296.png


That is all a bit of an information overload, but I thought it might be useful to someone if I just collated some of my research to-date on the topic. I hope that helps. I'm still exploring the TOM and the InkEdit control myself, so your question above was timely!
 
Upvote 0
That's a wealth of info I'm still reading through. Then try your suggestion of GetCurrentLine Number. It was nice surprise to find InkEdit control as it replaced a number of labels on frames that previously used colored and bold heading for blocks of text. Had I continued with Rich text I'd have found 64bit Excel doesn't support it. 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?
 
Upvote 0
The 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.


Untitinkled.png
 
Upvote 0

Forum statistics

Threads
1,223,936
Messages
6,175,507
Members
452,650
Latest member
Tinfish

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top