Results 1 to 20 of 20

Thread: Send contents of another program's textbox to my vb app

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Send contents of another program's textbox to my vb app

    Hi,
    Trying to interface an off-shelf label printing program by logging the last part number entered by the operator.

    The label program has a textbox where the operator scans in the part number, he presses Print and the program prints the label. That part number stays in the textbox until a new one is scanned in.

    I need to write an app that will grab this part number every ??? seconds so I know at all times what was the last part number that they entered.

    This label printing program's window may be minimized or not have focus.

    I should also mention that I KNOW the window's title of the program.

    As always any help appreciated.
    Thanks

    Tomexx.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Send contents of another program's textbox to my vb app

    Do you know how to find the hWnd of the textbox? You will need to.
    Since the user can type into it, it very well may be control with an hWnd, but maybe not. I think that is the 1st step.

    The next step would be to test to ensure you can get the text out of the box after you know the hWnd. This would include one of the APIs: GetWindowText or SendMessage using both WM_GetTextLength & WM_GetText.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Send contents of another program's textbox to my vb app

    The following will get the text from the Edit box of Calculator, you can modify it to suit your needs.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
    4. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    5. Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As Any, ByVal lpszWindow As Any) As Long
    6.    
    7. Private Const WM_GETTEXT        As Long = &HD
    8. Private Const WM_GETTEXTLENGTH  As Long = &HE
    9.  
    10. Private Sub Command1_Click()
    11.     Dim wintext         As String
    12.     Dim slength         As Long
    13.     Dim retval          As Long
    14.     Dim hwndDialog      As Long
    15.     Dim hwndButton      As Long
    16.    
    17.     hwndDialog = FindWindow("SciCalc", vbNullString)
    18.     If hwndDialog = 0 Then Exit Sub
    19.    
    20.     hwndButton = FindWindowEx(hwndDialog, 0, "Edit", vbNullString)
    21.    
    22.     slength = SendMessage(hwndButton, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
    23.     wintext = Space$(slength)
    24.     retval = SendMessage(hwndButton, WM_GETTEXT, ByVal slength, ByVal wintext)
    25.     wintext = Left$(wintext, retval)
    26.     MsgBox "The text is: " & wintext
    27. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Send contents of another program's textbox to my vb app

    Thanks for the code, I'll try it on monday.
    TGIF!
    Thanks

    Tomexx.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Send contents of another program's textbox to my vb app

    Just tried it and it worked!
    Question:
    Where did you get the name of the calculator "SciCalc" and the name of the Textbox "Edit". The calculator's caption is "Calculator".

    I guess it comes down to finding the form's name and Textbox's name. Where can I get them?
    Thanks

    Tomexx.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Send contents of another program's textbox to my vb app

    Do you have Spy++ that came with VB's installation CDs?
    SciCalc is not the title, it is the class name of the window. All windows are created from registered classes. SciCalc is the class name of the calculator's window. Edit is a standard textbox class/window. Spy++ can help identify these for you which is easier than writing your own code to do the "spying". By the way, VB forms have classes too, when compiled: ThunderRT6FormDC and uncompiled: ThunderFormDC
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Send contents of another program's textbox to my vb app

    Almost there

    Got SPY++ on the VB CD and tried it on a window with two textboxes.
    Both of them have the same class (Edit) so I guess they have be distinguished by their handles? I need to specify which text box am I getting the text from if there's more than one. Class name is the same for all textboxes (Edit), but the FindWindowEx() in the DEE-U's example works on class name.
    Last edited by Tomexx; Jan 9th, 2009 at 08:49 PM.
    Thanks

    Tomexx.

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Send contents of another program's textbox to my vb app

    You can try getting its ID so that the next time you have to set it then you can determine the ID before setting it.
    Code:
    Option Explicit
    
    Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Const GWL_ID As Long = -12
    
    Private Sub Command1_Click()
        Dim ID As Long
        ID = GetWindowLong(Text1.hWnd, GWL_ID)
        MsgBox ID
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Send contents of another program's textbox to my vb app

    To piggyback on Dee-U's suggestion. Try identifying the IDs multiple times to see if they change. Some apps will create those textboxes dynamically and assign dynamic IDs. Note: Spy++ gives you the ID also, it's the Control ID when you select to view a selected window's properties. Regarding handles, no you cannot use those. They will change a vast majority of the time.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    Code:
    Option Explicit
    
    Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Const GWL_ID As Long = -12
    
    Private Sub Command1_Click()
        Dim ID As Long
        ID = GetWindowLong(Text1.hWnd, GWL_ID)
        MsgBox ID
    End Sub
    hi
    i need ID but
    when i use this code for find my own class result is only hwnd of my class!

    (my class is:TsMemo)

    whats problem?

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Send contents of another program's textbox to my vb app

    Class? May we see how you are doing it?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    when i use this code for get id of richedit its give me only hwnd of richedit?!

    how can i get only id?

  13. #13
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Send contents of another program's textbox to my vb app

    Are you using the code you posted in post #10?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  14. #14
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    yes, its work on some object but
    not work on a text edit with class name:TsMemo
    why?

  15. #15
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Send contents of another program's textbox to my vb app

    Haven't seen such class type previously. how do you know that it is returning the handle instead of the ID?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  16. #16
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    because i use this and work with vb progRAM AND VC++(ex:1050)
    but not work for this class(TsMemo)

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Send contents of another program's textbox to my vb app

    Do you have Spy++ or something similar (think there is one called WinInspector)? If you do, use that program to get the hWnd of the textbox. It is possible the textbox is windowless and is drawn on the control; meaning it does not have an hWnd, nor ID. I think you have to positively verify whether or not it has an hWnd.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    Quote Originally Posted by LaVolpe
    Do you have Spy++ or something similar (think there is one called WinInspector)? If you do, use that program to get the hWnd of the textbox. It is possible the textbox is windowless and is drawn on the control; meaning it does not have an hWnd, nor ID. I think you have to positively verify whether or not it has an hWnd.

    yes i have
    but dont show to me id of this control!

    i think i can find DIFFERENCE betwen this classes.
    with size or position of object.
    can u tell me how can i get size of window of a richedit?

  19. #19
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Send contents of another program's textbox to my vb app

    You need the hWnd. Does Spy++ show you an hWnd? If so, use the API GetWindowRect to get size/position. hWnds are not static, they cannot be hardcoded in your app, so you still need to locate the hWnd via the FindWindow or FindWindowEx APIs.

    P.S. Spy++ does have an ID entry on the main tab when you opt to view the window's properties.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  20. #20
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: Send contents of another program's textbox to my vb app

    yes,
    thanks
    resloved.

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