WinBatch Technical Support Forum

Archived Boards => WinBatch Script Exchange => Topic started by: ....IFICantBYTE on May 28, 2015, 12:05:25 am

Title: Ink Control - text recognition simple example
Post by: ....IFICantBYTE on May 28, 2015, 12:05:25 am
Was playing around with the Microsoft Ink Control.... came up with this... maybe someone can find a use for it in one of their projects.
Have fun.

Code: Winbatch
;Made the following to play around with the Microsoft ink control.
;It doesn't do anything very useful as is, but could be the basis for something in a touch screen environment?
;The text recognition is pretty impressive. Hope you find it helpful one day for something ....IFICantBYTE


;Refer to : https://msdn.microsoft.com/en-us/library/ms823910.aspx


#DefineSubRoutine DlgTest(Dlg_Handle, Dlg_Message, Dlg_ID, Dlg_EventInfo, Dlg_ChangeInfo)
; Dialog messages.
MSG_INIT = 0 ; The one-time initialization.
MSG_BUTTONPUSHED = 2 ; Button press.
MSG_COMEVENT = 14 ; COM control event fired.
; Options for DialogObject function.
DLGOBJECT_ADDEVENT = 1 ;DialogObject add event.
DLGOBJECT_GETOBJECT = 3 ;DialogObject get reference to object.

COM_CHANGE = 1 ; User specified identifier for "change" event.
COM_CLICK = 2 ; User specified identifier for "click" event.

Switch Dlg_Message
        Case MSG_INIT
                DialogProcOptions( Dlg_handle, MSG_BUTTONPUSHED, 1 )
                ; Handle mouse click events.
                DialogObject(Dlg_Handle, "ComControl_1", DLGOBJECT_ADDEVENT, "Change", COM_CHANGE)
                DialogObject(Dlg_Handle, "ComControl_1", DLGOBJECT_ADDEVENT, "Click", COM_CLICK)
                ; Get an object reference to the com control.
                objCom = DialogObject(Dlg_Handle, "ComControl_1", DLGOBJECT_GETOBJECT)
                objCom.Text = "Use the mouse or draw some text directly on a touch screen in this window, then wait a couple of seconds for text recognition."
                objcom.MousePointer=2 ; 0=default dot, 1=Arrow, 2=Cross, 3=Ibeam, 4=SizeNE-SW, 5=SizeN-S, 6=SizeNW-SE, 7=SizeW-E, 8=Up, 9=Hourglass/WaitCircle, 10=NoDrop, 11=Arrow+Hourglass/WaitCircle, 12=Arrow+?, 13=Size, 14=PointingHand, 99=CustomIcon specified by MouseIcon property
                objcom.UseMouseForInput=@True
                blue = 250
                green = 200
                red = 200
                objcom.BackColor=blue*256*256+green*256+red
                objcom.Enabled=@True
                objcom.RecognitionTimeout=2000
                objcom.InkMode=2 ;0=disabled, 1=ink collected, 2=ink and single stroke gestures
                objcom.InkInsertMode=0  ;0=text, 1=ink
                objcom.Locked=@False
                objcom.SelFontName="Times"
                objcom.SelFontSize=20
                blue = 10
                green = 10
                red = 170
                objcom.SelColor=blue*256*256+green*256+red
        Break

        Case MSG_COMEVENT
                ; Correct COM control and event?
                If Dlg_ID == "ComControl_1"
                        If Dlg_EventInfo.identifier == COM_CHANGE
                                Message("CHANGE","changes detected to text in ink area")
                        ElseIf Dlg_EventInfo.identifier == COM_CLICK
;                               Message("CLICK","mouse click detected on ink area")
                        EndIf
                EndIf
        Break

        Case MSG_BUTTONPUSHED
                If Dlg_ID == "PushButton_OK"
                        text = objCom.Text
                        Message("Plain text returned",text)
                        rtftext = objCom.TextRTF
                        Message("RTF text returned",rtftext)
                EndIf
                If Dlg_ID == "PushButton_Cancel"
                        ; Release Objects.
                        Dlg_EventInfo = 0
                        objCom = 0
                        Return(-1)
                EndIf
        Break

EndSwitch
Return(-2)
#EndSubRoutine ; End of Dialog Callback.


MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=220
MyDialogY=072
MyDialogWidth=584
MyDialogHeight=359
MyDialogNumControls=003
MyDialogProcedure=`DlgTest`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`171,339,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`377,339,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`013,011,554,318,COMCONTROL,"ComControl_1",DEFAULT,"InkEd.InkEdit.1",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ButtonPushed=Dialog("MyDialog")
Title: Re: Ink Control - text recognition simple example
Post by: stanl on May 30, 2015, 03:50:38 am
Impressive! Thanks for sharing.
Title: Re: Ink Control - text recognition simple example
Post by: td on May 30, 2015, 09:47:26 am
Created a Tech Database article.  Script is more or less unchanged except for conversion to the new dialog constants.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Dialog~Editor/Dialog~Editor~version~6.2/Samples+Microsoft~InkEdit~COMCONTROL.txt (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Dialog~Editor/Dialog~Editor~version~6.2/Samples+Microsoft~InkEdit~COMCONTROL.txt)
Title: Re: Ink Control - text recognition simple example
Post by: JTaylor on May 30, 2015, 12:17:55 pm
Finally got a chance to take a look....Very Nice!!!   

Thanks.

Jim
Title: Re: Ink Control - text recognition simple example
Post by: stanl on May 30, 2015, 05:35:27 pm
Looked at the control through Tony's Type Viewer. The methods are quite limited, i.e. no save(). However, as it is a subclass of richedit maybe the WB CLR can handle it. I really have a need to use a control like that as a signature in an Excel form. Hope to find time to dig around in that area.
Title: Re: Ink Control - text recognition simple example
Post by: td on May 31, 2015, 10:29:07 am
If you press the 'Get Library' button instead of the 'Get Members' button, you will see that there are a lot of interfaces available, including at least one with a 'Save' method.  It is simply a matter of connecting the interface dots.  MSFT documentation is useful for that purpose. 
Title: Re: Ink Control - text recognition simple example
Post by: stanl on May 31, 2015, 12:56:23 pm
Yeah, got that after I downloaded the 1.7 Tablet SDK just to have the toolbox controls. Using IFICB's code
I am looking at a Save Button with code to save the ink as an Image using binary buffers: But code fails at SelectAll()

Code: Winbatch
binbuf = BinaryAlloc(20000)
offset=0
objCom.SelectAll()  ;error: unknown name
objCom.SelInksDisplayMode = 1
Foreach ink in objCom.SelInks
      BinaryPoke(binbuf,offset,ink)
      offset = BinaryEodGet( binbuf )
Next
BinaryWrite( binbuf,dirscript():"testink.gif"  ) ;default format
 

Title: Re: Ink Control - text recognition simple example
Post by: JTaylor on May 31, 2015, 07:59:05 pm
Was hoping to help but I can't find "SelectAll()" as an option.

Jim
Title: Re: Ink Control - text recognition simple example
Post by: ....IFICantBYTE on May 31, 2015, 10:39:32 pm
Stan,
I don't know how to save the ink, but you might also be interested in the msinkaut.InkPicture.1 control for just ink and pictures?

Title: Re: Ink Control - text recognition simple example
Post by: stanl on June 01, 2015, 06:46:40 am
Thanks IFICB - Actually I'm looking at more of a .NET C# solution. If you download the Tablet SDK 1.7 - there are some neat example programs and code.   
Title: Re: Ink Control - text recognition simple example
Post by: td on June 01, 2015, 07:03:19 am
Tablet SDK 1.7 - a COM interop CLR cover for the same COM interfaces.