mehdigholamim
26-03-2012, 10:46
با سلام
من يه برنامه دارم كه توي vb.net نوشتم. حالا مي خوام يه كد توش بذارم كه مانند babylon كلمه اي كه روي اون كليك مي كنم رو Capture كنه و مثلاً بذاره توي يه TextBox يا كپي كنه توي Clipboard.
البته از طريق WordCaptureX يه كد بدست آوردم كه فكر مي كنم كاملترين و مطمئن ترين كدي باشه كه بدست آوردم. ولي مشكل اينه كه وقتي كد رو مي ذارم توي برنامه ام، يك سري كدها رو ميگه "is not defined" بعضي رو هم ميگه "is not declared" و زيرشون زيگزاگ آبي مي كشه كه در زير به رنگ صورتي مشخص كردم. و از اونجايي كه من تسلط كافي ندارم، نمي تونم اين مشكل رو حل كنم. لطفاً راهنمايي كنيد (اين كد خيلي برام مهمه) - متشكرم :
Private Sub StartMonitoring()
Dim color As Integer
Dim wLineStyle As W_LINE_STYLE
Dim wKey As W_KEY
Dim wMouse As W_MOUSE
Dim dwHotkeyCursor As Integer
Dim dwHotkeyCaret As Integer
Dim dwHotkeySelectedText As Integer
Dim dwIdleTime As Integer
wKey = W_KEY.wmKeyNone
wMouse = W_MOUSE.wmMouseMiddle
m_wMonitor.LineStyle = wLineStyle
m_wMonitor.LineColor = color
m_wMonitor.Start(wKey, wMouse, True)
End Sub
Private Function PerformCapture(ByVal hwnd As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As WResult
Dim objInput As IWInput2 = ComFactory.Instance.NewWInput
Dim wOptions As Integer = 0
' set the highlight word flag
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsHighlightWords
' set the getContext flag
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsGetContext
'set capture parameters
objInput.Hwnd = hWnd
objInput.StartX = x1
objInput.StartY = y1
objInput.EndX = x2
objInput.EndY = y2
objInput.Options = wOptions
' set the number of context words
objInput.ContextWordsLeft = 1
objInput.ContextWordsRight = 1
Dim objResult As WResult = m_wCapture.Capture(objInput)
'get the text from the capture
Dim strResult As String = objResult.Text
'use OCR if native method fails
If strResult = String.Empty Then
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsGetTessOCRText
objInput.OCRLanguage = "eng"
objInput.Options = wOptions
objResult = m_wCapture.Capture(objInput)
strResult = objResult.Text
End If
Return objResult
End Function
من يه برنامه دارم كه توي vb.net نوشتم. حالا مي خوام يه كد توش بذارم كه مانند babylon كلمه اي كه روي اون كليك مي كنم رو Capture كنه و مثلاً بذاره توي يه TextBox يا كپي كنه توي Clipboard.
البته از طريق WordCaptureX يه كد بدست آوردم كه فكر مي كنم كاملترين و مطمئن ترين كدي باشه كه بدست آوردم. ولي مشكل اينه كه وقتي كد رو مي ذارم توي برنامه ام، يك سري كدها رو ميگه "is not defined" بعضي رو هم ميگه "is not declared" و زيرشون زيگزاگ آبي مي كشه كه در زير به رنگ صورتي مشخص كردم. و از اونجايي كه من تسلط كافي ندارم، نمي تونم اين مشكل رو حل كنم. لطفاً راهنمايي كنيد (اين كد خيلي برام مهمه) - متشكرم :
Private Sub StartMonitoring()
Dim color As Integer
Dim wLineStyle As W_LINE_STYLE
Dim wKey As W_KEY
Dim wMouse As W_MOUSE
Dim dwHotkeyCursor As Integer
Dim dwHotkeyCaret As Integer
Dim dwHotkeySelectedText As Integer
Dim dwIdleTime As Integer
wKey = W_KEY.wmKeyNone
wMouse = W_MOUSE.wmMouseMiddle
m_wMonitor.LineStyle = wLineStyle
m_wMonitor.LineColor = color
m_wMonitor.Start(wKey, wMouse, True)
End Sub
Private Function PerformCapture(ByVal hwnd As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As WResult
Dim objInput As IWInput2 = ComFactory.Instance.NewWInput
Dim wOptions As Integer = 0
' set the highlight word flag
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsHighlightWords
' set the getContext flag
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsGetContext
'set capture parameters
objInput.Hwnd = hWnd
objInput.StartX = x1
objInput.StartY = y1
objInput.EndX = x2
objInput.EndY = y2
objInput.Options = wOptions
' set the number of context words
objInput.ContextWordsLeft = 1
objInput.ContextWordsRight = 1
Dim objResult As WResult = m_wCapture.Capture(objInput)
'get the text from the capture
Dim strResult As String = objResult.Text
'use OCR if native method fails
If strResult = String.Empty Then
wOptions = wOptions Or W_CAPTURE_OPTIONS.wCaptureOptionsGetTessOCRText
objInput.OCRLanguage = "eng"
objInput.Options = wOptions
objResult = m_wCapture.Capture(objInput)
strResult = objResult.Text
End If
Return objResult
End Function