|
-
Sep 1st, 2000, 04:54 PM
#1
Thread Starter
Member
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.
-
Sep 1st, 2000, 05:08 PM
#2
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.
-
Sep 1st, 2000, 05:15 PM
#3
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.
-
Sep 2nd, 2000, 08:16 AM
#4
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.
-
Sep 2nd, 2000, 10:45 AM
#5
Monday Morning Lunatic
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
-
Sep 2nd, 2000, 11:51 AM
#6
Another thing you can do is simulate keypresses to the calculator using keybd_event.
The calculator responds to number keys and -, +, *, / etc.
-
Sep 2nd, 2000, 03:10 PM
#7
Thread Starter
Member
---~^ 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|