Results 1 to 7 of 7

Thread: Ok guys here is a toughy

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    How Do you fill in a control of another program say if I had calculator open I could Add numbers to the text box

    and another

    question how would I get what the text box in calculator was saying and put it in a label on my program
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

  2. #2
    Guest
    You can use the SendMessage API:
    Code:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Public Const WM_GETTEXT = &HD
    Public Const WM_SETTEXT = &HC
    Usage:
    Code:
    Dim sText As String
    Dim lMaxLength As Long
    Dim lLength As Long
    
    lMaxLength = 1024
    sText = Space(lMaxLength + 1)
    
    'hwndCalc is the handle of the text box in calculator which you can get using a spy tool or the FindWindow API
    lLength = SendMessage(hwndCalc, WM_GETTEXT, lMaxLength, ByVal sText)
    
    Text1.Text = Left(sText, lLength)
    This should give you the text in the calculator textbox in your own textbox.
    Similarly you can use WM_SETTEXT to change the text in calculator.

    I didn't test it yet, but it should work.
    If it doesn't, post the error you get and I'll try to fix it.

    Hope it helps.

  3. #3
    Guest
    This is what I got using a spy tool:

    Class of calculator: "SciCalc"
    Class of the textbox in calculator: "Static"

    The hwnd of the textbox is not a constant.
    So if you want to get the handle of the textbox, you should loop through all the child windows of the calculator, and find the one with a text like "0." or something like that.

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Although this technique can be used to get or set the text in the label, you should not expect that the calculator really calculates with the numbers you put in the label. Very likely it uses internal variables for this.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, this works for setting the text, but it obviously keeps its calculations to itself because it won't accept it as a number.
    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
        On Error Resume Next
        Dim hWndCalc As Long
        Dim hWndDisp As Long
        Dim sText As String * 50
        Dim sTextB As String
        Dim bTx() As Byte
        
        If KeyAscii <= vbKey9 Or KeyAscii >= vbKey0 Then
            hWndCalc = FindWindow("SciCalc", vbNullString)
            hWndDisp = GetDlgItem(hWndCalc, 403) ' 403 is the ID of the display
        
            sText = String(50, 0)
            GetWindowText hWndDisp, sText, 50
            sTextB = Left(sText, InStr(1, sText, Chr(0)) - 1)
            sTextB = sTextB & Chr(KeyAscii)
            ReDim bTx(Len(sTextB))
            For i = 0 To Len(sTextB)
                bTx(i) = Asc(Mid(sTextB, i + 1, 1))
            Next i
            bTx(Len(sTextB)) = 0
            SendMessage hWndDisp, WM_SETTEXT, 0, bTx(0)
        End If
    End Sub
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Guest
    Another thing you can do is simulate keypresses to the calculator using keybd_event.
    The calculator responds to number keys and -, +, *, / etc.

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Ontario, Canada
    Posts
    61
    Ok thanks guys
    ---~^ Absalom ^~---

    There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width