Hello, I would like to modify a value that is in a window of another application using Windows API. I am trying to use Spy++ to determine the particular handle/class, but, I haven't any luck. Attached should be some pictures. One is a snapshot of the window I want to affect. Particularly, the value in the SAG spinner window. The other is a screendump of what Spy++ generated.

Any help on what API calls and how to use them would be greatly appreciated. I have tried FindWindow, GetClassName, and SendDlgItemMessage.

Thanks in advance,

Recommended Answers

All 15 Replies

I have discovered what I need to do is:
(1) Use FindWindow to determine the handle of the parent.
(2) Then use FindWindowEx on the childs to find their handle(s).
(3) Then use SendMessage This is what I have so far...

Dim hWnd As Long
    Dim cWnd(5) As Long
    Dim S As String
    Dim I As Long
    'get parent window
    hWnd = FindWindow(vbNullString, "Tessellation")
    
    cWnd(0) = FindWindowEx(hWnd, 0, "Afx:00400000:0:00010013:00000000:00000000", vbNullString)
    cWnd(1) = FindWindowEx(cWnd(0), 0, "Afx:00400000:0:00010013:00000000:00000000", vbNullString)
    cWnd(2) = FindWindowEx(cWnd(1), 0, "Afx:00400000:0:00010013:00000000:00000000", vbNullString)
    cWnd(3) = FindWindowEx(cWnd(2), 0, "Afx:00400000:0:00010013:00000000:00000000", vbNullString)
    cWnd(4) = FindWindowEx(cWnd(3), 0, "Afx:00400000:400b:00010013:00000000:00000000", vbNullString)
    cWnd(5) = FindWindowEx(cWnd(4), 0, "Edit", vbNullString)

This gets me the handle of the window I want to access. Now I am trying to modify/input the text in that window.

Have a look at this thread - HERE. This is to get the handle and start "communication" with that window.

To find and manipulate the text in another application, have a look at THIS, or the best for last over HERE.:)

I figured out how to use the SENDMESSAGE API to modify the window.

Dim cWndText as String
     If cWnd(5) Then
        cWndText = "0.005in"
        cWndText = Left(cWndText, SendMessage(cWnd(5), WM_SETTEXT, ByVal CLng(0), ByVal cWndText))
    End If

Using this successfully put the text into the spinner window.

Thanks for everyone's help.

commented: Well Done +4

Well done. Some rep points for not giving up.:)

Now I am trying to set the Save As dialog box that opens up when the user selects a button that opens the dialog box.

I can modify the combobox that pertains to the filename, but, I am having trouble modifying the combobox that pertains to the Folder Path to look in.

Is API the proper commands to use to manipulate this window/control? I have tried CB_ADDSTRING and CB_SETITEMDATA with a SendMessage with no luck. I believe that I got the correct handle for this window/control. Spy++ reflects that it is two windows below the parent window.

Below is some of the code that I am attemting to use:

'add file path
    next1 = GetWindow(hWndSaveAs, GW_HWNDNEXT)
    next2 = GetWindow(next1, GW_HWNDNEXT)
    
    If next2 Then
        cWndText = myPartDoc.Path
        SendMessage next2, CB_ADDSTRING, 0&, ByVal cWndText
        SendMessage next2, CB_SETITEMDATA, 0, cWndText
    End If

I would rather use the DriveListBox control. You have much more control over path and files than with a combo box.

Unfortunately, I have no control over what control to use. This combobox has already been created by another application.

Paste the actual code you are using under the combobox's load event and the select event.

Also, is this app used in Vista or Win7?

Attached should be some screen dumps of the windows I am trying to access. When the "..." button is pressed from the Export window, the SAVEAS dialog box appears.

I can use the SendMessage API to enter the filename information, but, I can't enter the path information to the FilePath window. Spy++ tells me that this is a combobox and that it is the second child window of the main Save As window.

I am currently using a Win '98 operating system...but I would like it also to work on a Win 7 platform. I should mention that these windows are from a running application that I am trying to manipulate. Thus, I cannot add any code to its Load or Select event.

I must say, it looks like a textbox to me. (referring to the export form) The only combobox I can see is the one with "Absolute" as its first index text.

The windows "Save As" dialog window should not contain any child windows because it is a normal dialog window called from the common dialog control in vb6.

You should maybe try and manipulate the export form by adding the path first to the export text box and then let the dialog box show. I realize that this will be difficult because you do not know the code behind the app, but I think that might solve your problem.

The combo box that I am trying to access is the one on the SaveAs dialog box...not the Export window. I have tried to set the current directory before the common dialog control shows up to see if this would reflect the directory that I am trying to export a file too....no luck.

I tried to enter the path information to the FileName box on the EXPORT window. While I can have the correct information displayed, the "OK" button on the Export window is disabled. I then enable that window, but, the file was not exported after it is selected. It acted as if the button was never clicked.

This means that you need to manipulate the dialog box. Thats a whole new task. Have a look at THIS link that gives sample code on how to manipulate the dialog box.

You can also set the InitDir property to the folder of your choice within the common dialog control. Google more on InitDir in VB6 for more information.

It looks like that code displays a "BrowseForFolder" dialog box. I'm mainly interested in modifying the existing SaveAs dialog box to have the path already set. I'm trying not to have any end user interaction. Thus, having the user select the path is not a viable option.

It looks like I got everything to work. I used EnumChildWindows to eventually find the handle for the file type combobox. Then I used the WM_KEYDOWN & WM_KEYUP to manipulate the box until the appropriate file type was selected.

I also insert the full path along with a file name in the FileName box and when I select the Save button all of the necessary information is processed correctly.

Thanks for everyone's help.

commented: For solution, not giving up! +4

It was a pleasure. Some kudos for you for not giving up.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.