Page 1 of 2 12 LastLast
Results 1 to 40 of 67

Thread: Can this be done?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Can this be done?

    I have attached an image to demonstrate what iam about to say, i need some code that will simulate teh user clicking the login button, is this possible?

    Notes on this problem,
    1. Sadly the program does not load with the login button pre-selected, therefore clicking enter wont work.
    2. There is no tab order(when you press tab it does not highlight the buttons).

    Anyone got any ideas? please give full code as iam new to VB.

    Thanks
    Attached Images Attached Images  

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Yes,

    Get handle to button using FindWindowEX
    Send BM_CLICK message to button

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    moeur thanks for that reply, can u explain what FindWindowEX is? :S i am new to this stuff. or maybe provide a website that i can read up on it myself if you havent got the time as i have no idea how to use it.

    Thanks

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    Ok i done a search in google and found an MSDN page on this function however i still have no idea how to use it :S. Could someone provide me with the code i need to find out how to identify the login button habdle?

    Thanks

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Can this be done?

    Quote Originally Posted by Balboa.sCo
    Ok i done a search in google and found an MSDN page on this function however i still have no idea how to use it :S. Could someone provide me with the code i need to find out how to identify the login button habdle?

    Thanks
    Find window api...

    http://www.mentalis.org/apilist/FindWindow.shtml

    i'm not sure on the other item though will have to wait for him/her to reply for that one

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    OK, here is some code
    Note that you might have to look up the correct caption and class values using SPY++
    VB Code:
    1. Option Explicit
    2.  
    3. 'Returns handle to target window
    4. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    5.     ByVal lpClassName As String, _
    6.     ByVal lpWindowName As String _
    7. ) As Long
    8.  
    9. 'Returns handle to target control
    10. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    11.     ByVal hWnd1 As Long, _
    12.     ByVal hWnd2 As Long, _
    13.     ByVal lpsz1 As String, _
    14.     ByVal lpsz2 As String _
    15. ) As Long
    16.  
    17. 'Sends a message to our target
    18. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    19.     ByVal hwnd As Long, _
    20.     ByVal wMsg As Long, _
    21.     ByVal wParam As Long, _
    22.     lParam As Any _
    23. ) As Long
    24.  
    25. 'The message we want to send
    26. Const BM_CLICK = &HF5
    27.  
    28.  
    29. Private Sub Command1_Click()
    30.  Dim hWndForm As Long ' handle to target window
    31.  Dim hWndButton As Long ' handle to the button
    32.  Dim strCaptionForm As String 'caption of the target form
    33.  Dim strClassButton As String ' Button Class
    34.  Dim strCaptionButton As String ' Button Caption
    35.  
    36. 'Get the correct values from SPY++
    37. strCaptionForm = "DMW3-Client Login"
    38. strCaptionButton = "Login"
    39. strClassButton = "Button"
    40.  
    41.  'Get handle to desired form
    42. ' if this returns 0 we didn't get it
    43.  hWndForm = FindWindow(vbNullString, strCaptionForm)
    44.  If hWndForm = 0 Then
    45.   MsgBox "Sorry, could not find requested form"
    46.   Exit Sub
    47.  End If
    48.  'Get handle to desired button on form
    49. ' if this returns 0 we didn't get it
    50.  hWndButton = FindWindowEx(hWndForm, 0, strClassButton, strCaptionButton)
    51.  If hWndButton = 0 Then
    52.   MsgBox "Sorry, could not find requested button"
    53.  Else
    54.  'Send click message to button
    55.   Call SendMessage(hWndButton, BM_CLICK, 0, 0)
    56.  End If
    57.  
    58. End Sub

    -Him

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    I tried this code although i do not know what SPY++ is or how to use it for that matter, If i was to send the the DMW program(only 1mb or 2) could you possibly give me the exact code i will need?

    When i try the code i get "sorry, could not find requested form"

    I have attached DMW.

    please help!!
    Attached Files Attached Files

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Sorry,

    I can't run your executable code (not wise)
    Anyway, SPY++ comes with Visual Studio, see if you have it.

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Can this be done?

    Google for SPY++, unless you have Enterprise Edition, then you already have it.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    i have VB 6.0 Proffesional, i cnt find SPY++ anywhere, i read what it does and i was able to play about with the code moeur sent me and managed to find out that the form name for the DMW program was Form1 :P, i cant find out the name of the button tho.

    The thing i attached was not my code, it was the DMW program, you can download it at www.dmwworld.com(it may help you understand the question more). I worked out that pressing enter when the program loads does nothing, but pressing space bar logs me in. Therefore i used the following code to try get my program to log me in;

    VB Code:
    1. Shell (DMWINSTALL), vbNormalFocus
    2. Sleep 3000
    3. SendKeys " ", True

    On screen i can see that my program runs the DMW program and after 3seconds it appears to log me in. My problem is that for some reason it is not loging me in correctly. I know this because when i go to play the game the game crashes for some reason with an OpenGL error. If i manually open DMW log myself in then play the game, the game runs perfect.

    The only thing i can think off is to do what i thin moeur was trying, to somehow simulate a mouse click on the button. Iam currently trying to contact the person who made the program to ask what he named it. If anyone could find out the name of this button for me by using SPY++ as i cant find it on google, i would greatly appreciate it

    Thanks for all the help so far guys, still needing more tho.

    Martyn Rendall

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Can this be done?

    I can't find Spy++ right now, either. I'll post back if I find it.

  12. #12
    Junior Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    20

    Re: Can this be done?

    Why dont you call the sub directly?

    Code:
    Sub Form_Load()
       '
       '
       Call cmdLogin_Click()
    End Sub

  13. #13
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    OK, here is some code to do what SPY++ does, but from VB. It sets a system-wide low level mouse hook so that when you move the mouse over the top of a window or control, it gets you the handle, caption and class name. It's amazing what you can do with the functions provided in the API.

    Start a new project with a form and a module, add a command button (cmdStart) and three text boxes (txtHandle, txtCaption and txtClassName) to the form.

    Put this code in the module:
    VB Code:
    1. Option Explicit
    2.  
    3. 'Functions, constants and types for the hook
    4. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
    5.     ByVal idHook As Long, _
    6.     ByVal lpfn As Long, _
    7.     ByVal hmod As Long, _
    8.     ByVal dwThreadId As Long _
    9. ) As Long
    10.  
    11. Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
    12.     ByVal hHook As Long _
    13. ) As Long
    14.  
    15. Private Declare Function CallNextHookEx Lib "user32" ( _
    16.     ByVal hHook As Long, _
    17.     ByVal ncode As Long, _
    18.     ByVal wParam As Long, _
    19.     lParam As Any _
    20. ) As Long
    21.  
    22. Public Const WH_MOUSE_LL = 14
    23.  
    24. Public Type POINTAPI
    25.         x As Long
    26.         y As Long
    27. End Type
    28.  
    29. Public Type MSLLHOOKSTRUCT
    30.     pt As POINTAPI
    31.     mouseData As Long
    32.     flags As Long
    33.     time As Long
    34.     dwExtraInfo As Long
    35. End Type
    36.  
    37. Private hHook As Long
    38. Public IsHooked As Boolean
    39.  
    40. 'functions for getting windows properties
    41. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
    42.     ByVal hwnd As Long, _
    43.     ByVal lpString As String, _
    44.     ByVal cch As Long _
    45. ) As Long
    46.  
    47. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
    48.     ByVal hwnd As Long, _
    49.     ByVal lpClassName As String, _
    50.     ByVal nMaxCount As Long _
    51. ) As Long
    52.  
    53. Private Declare Function WindowFromPoint Lib "user32" ( _
    54.     ByVal xPoint As Long, _
    55.     ByVal yPoint As Long _
    56. ) As Long
    57.  
    58. Sub GetWindowData(x As Long, y As Long)
    59.  Dim hWndFrm As Long
    60.  Dim lpClassName As String, lpString As String
    61.  lpClassName = Space(100)
    62.  lpString = Space(100)
    63.  'get handle to window
    64.  hWndFrm = WindowFromPoint(CLng(x), CLng(y))
    65.  If hWndFrm = 0 Then Exit Sub
    66.  'get window text (caption)
    67.  Call GetWindowText(hWndFrm, lpString, Len(lpString))
    68.  'get window class name
    69.  Call GetClassName(hWndFrm, lpClassName, Len(lpClassName))
    70.  
    71.  With Form1
    72.   .txtHandle = Hex(hWndFrm)
    73.   .txtCaption = lpString
    74.   .txtClassName = lpClassName
    75.  End With
    76. End Sub
    77.  
    78. Public Sub SetMouseHook()
    79.     If IsHooked Then
    80.         MsgBox "Don't hook the MOUSE_LL hook twice or you'll be sorry."
    81.     Else
    82.         'This has to be set up as a system-wide hook
    83.         hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0)
    84.         IsHooked = True
    85.     End If
    86. End Sub
    87.  
    88. Public Sub RemoveMouseHook()
    89.     Dim temp As Long
    90.     temp = UnhookWindowsHookEx(hHook)
    91.     IsHooked = False
    92. End Sub
    93.  
    94.  
    95. Public Function MouseProc(ByVal uCode As Long, ByVal wParam As Long, lParam As MSLLHOOKSTRUCT) As Long
    96.     If uCode >= 0 Then
    97.         Call GetWindowData(lParam.pt.x, lParam.pt.y)
    98.     End If
    99.            
    100.     MouseProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    101. End Function

    This code goes into your form:
    VB Code:
    1. Option Explicit
    2.  
    3. 'Always on top stuff
    4. Private Const HWND_TOPMOST = -1
    5. Private Const SWP_NOSIZE = &H1
    6. Private Const SWP_NOMOVE = &H2
    7. Private Const SWP_NOACTIVATE = &H10
    8. Private Const SWP_SHOWWINDOW = &H40
    9.  
    10. Private Declare Sub SetWindowPos Lib "user32" ( _
    11.     ByVal hwnd As Long, _
    12.     ByVal hWndInsertAfter As Long, _
    13.     ByVal x As Long, _
    14.     ByVal y As Long, _
    15.     ByVal cx As Long, _
    16.     ByVal cy As Long, _
    17.     ByVal wFlags As Long _
    18. )
    19.  
    20. Private Sub cmdStart_Click()
    21. 'make window always on top
    22.  SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    23.     SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    24.  'set the system-wide low level mouse hook
    25.  Call SetMouseHook
    26. End Sub
    27.  
    28. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    29.  Call RemoveMouseHook
    30. End Sub

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Can this be done?

    sweet!

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    I done as u stated moeur and i have attached teh finding as an image with this post. All i need to know to do now is simulate the user clicking login with the mouse, is this possible? if so could you show me how, i use shell to open the program then i take a sleep for a few seconds so the program loads up then i want to simulate the mouse click.

    I was also like to say to moeur that you are a credit to this community mate, you have been patient with me and provided som excellent help so far, hopefully we will get to the end of the problem soon. Is there anyway i can vote for you or somethign moeur?id like to show support for your help if i can in some way?

    Thanks
    Attached Images Attached Images  

  16. #16
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Now you have two of the three values you needed.
    VB Code:
    1. strCaptionButton = "Login"
    2. strClassButton = "Button"

    To get the third value,
    VB Code:
    1. strCaptionForm = ????
    It should be something like "DMW3 - Client Login"

    Use the above program to get the caption of the main form. Put the mouse over the form area not any of the buttons for this third value.

    Understand?

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    ok when i put the cursor over the title bar of the form i get the information attached below.
    Attached Images Attached Images  

  18. #18
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    OK, you have everything you need.
    In the first code I gave you, replace the command1_click event code with this
    Make sure the caption and class names match exactly what you got from the above SPY-- code.
    VB Code:
    1. Private Sub Command1_Click()
    2.  Dim hWndForm As Long ' handle to target window
    3.  Dim hWndButton As Long ' handle to the button
    4.  Dim strCaptionForm As String 'caption of the target form
    5.  Dim strClassButton As String ' Button Class
    6.  Dim strCaptionButton As String ' Button Caption
    7.  Dim strClassForm As String 'Form Class Name
    8.  
    9. strCaptionForm = "DMW3 - Client Login"
    10. strCaptionButton = "Login"
    11. strClassButton = "Button"
    12. strClassForm = "#32770"
    13.  
    14.  'Get handle to desired form
    15. ' if this returns 0 we didn't get it
    16.  hWndForm = FindWindow(strClassForm, strCaptionForm)
    17.  If hWndForm = 0 Then
    18.   MsgBox "Sorry, could not find requested form"
    19.   Exit Sub
    20.  End If
    21.  'Get handle to desired button on form
    22. ' if this returns 0 we didn't get it
    23.  hWndButton = FindWindowEx(hWndForm, 0, strClassButton, strCaptionButton)
    24.  If hWndButton = 0 Then
    25.   MsgBox "Sorry, could not find requested button"
    26.  Else
    27.  'Send click message to button
    28.   Call SendMessage(hWndButton, BM_CLICK, 0, 0)
    29.  End If
    30.  
    31. End Sub

    Does it work?

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    i get the sorry, could not find requesed form error

  20. #20
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    What are the values of your strClassForm and strCaptionForm variables? Did you cut and paste them from the SPY-- form so that you don't make any errors?

    Here is a test you can use to see if this whole thing is going to work anyway.

    1. Start your target program
    2. Get the handle from the button like you did above with the SPY-- code. (ex: A0128). Note, this value changes everytime you run the target program, so you can't hardwire it into your final program.
    3.from a VB project, run the command
    VB Code:
    1. Call SendMessage(&HA0128, BM_CLICK, 0, 0)
    where A0128 is the new value you get.

    If this technique is going to work, then it should click the target button

    Try it out.

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    tried(One line of code in entire program):

    Call SendMessage(&H401CC, BM_CLICK, 0, 0)

    to start with got the error "invalid outside procedure".

    then tried

    Private Sub Command1_Click()
    Call SendMessage(&H401CC, BM_CLICK, 0, 0)
    End Sub

    and got the error "Sub or Function not defined".

    the code above is all i have in the program, for example the first one only has 1 line of code in the entire program, i take it this is incorrect? and that iam missing somehting obvious?

  22. #22
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    OK,

    I was assuming you knew to declare the SendMessage function as
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.     ByVal hwnd As Long, _
    3.     ByVal wMsg As Long, _
    4.     ByVal wParam As Long, _
    5.     lParam As Any _
    6. ) As Long

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any _
    ) As Long

    Private Sub Command1_click()
    Call SendMessage(&HA02B2, BM_CLICK, 0, 0)
    End Sub

    tried that code, no errors but nothing happens on the target program? that mean im at a lose end?

  24. #24
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Can this be done?

    Quote Originally Posted by sachin_bhatt
    Why dont you call the sub directly?

    Code:
    Sub Form_Load()
       '
       '
       Call cmdLogin_Click()
    End Sub
    Can I ask why you want to simulate a mouse click exactly, when the above code should achieve the same result If you are using MouseDown or MouseUp events then no problem, just replace _Click with the appropriate event plus any arguments etc.

  25. #25
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Remember you have to do this also
    VB Code:
    1. Const BM_CLICK = &HF5

    Why dont you call the sub directly?
    I'm assuming he doesn't have access to the source code of the other program.

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    the original code, where i send the space bar command to the running program appeared to work, on the screen visually i could see the login button bein pressed, the program therefore appeard to work, however if once i have started DMW i try to play the computer game the game crashes. If i just open the DMW and click login myself then play the game it loads and play fine. I have been asking questions on the DMW forums and the original program was coded in C, does this make a difference?

    Basically for some reason pressing spacebar to activate the program appears to work, but for some reason it doesnt, as the computer game has a problem loading once i start the DMW program using my program.

    Therefore i decided to try simulate a mouse click to see if this would work, however this is my first time in visual basic and although moeur and other are providing some great help and support im struggling to get this program working as i miss out thinks that should be obvious it seems. Maybe trying to get the mouse click to work is to advanced for me?

    I really want this program to work, but im sure you guys must be getting annoyed with my silly mistakes.

  27. #27
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Let's try one more time
    1. open DMW program, don't close it througout this whole process
    2. Get handle to button using SPY+-. Make sure you are looking at button. Classname text box should be Button and caption should be Login.
    3. put that number into this code
    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    3.   ByVal hwnd As Long, _
    4.   ByVal wMsg As Long, _
    5.   ByVal wParam As Long, _
    6.   lParam As Any _
    7. ) As Long
    8.  
    9. Private Sub Command1_click()
    10.   Call SendMessage(&H[I]<Your number>[/I], &HF5, 0, 0)
    11. End Sub

    4. Run code
    5. If it works then smile, if not then cry.
    Last edited by moeur; Feb 15th, 2005 at 10:52 AM.

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    IT WORKS , what i have to do is click the button twice tho, it looks like what the first click does is give the DMW program focus and the second clicks the button. All we need to work on now is to get my program to open the DMW one aswell as login now . MOEUR is my hero :P

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    so what i need now is some way of doing this process without having that unique code. Is that unique code hexadecimal?

    Any ideas anyone?, liek to achieve this with as little code as possible so i can understand it

  30. #30
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Finally!

    To start program use the VB Shell command

  31. #31

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    i can do that, but how do i get it to click the login button each time? cos that code will change each time the DMW program is loaded? how can i get round this?

  32. #32
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    You've got to get this code working
    VB Code:
    1. Option Explicit
    2.  
    3. 'Returns handle to target window
    4. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    5.     ByVal lpClassName As String, _
    6.     ByVal lpWindowName As String _
    7. ) As Long
    8.  
    9. 'Returns handle to target control
    10. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    11.     ByVal hWnd1 As Long, _
    12.     ByVal hWnd2 As Long, _
    13.     ByVal lpsz1 As String, _
    14.     ByVal lpsz2 As String _
    15. ) As Long
    16.  
    17. 'Sends a message to our target
    18. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    19.     ByVal hwnd As Long, _
    20.     ByVal wMsg As Long, _
    21.     ByVal wParam As Long, _
    22.     lParam As Any _
    23. ) As Long
    24.  
    25. 'The message we want to send
    26. Const BM_CLICK = &HF5
    27.  
    28. Private Sub Command1_Click()
    29.  Dim hWndForm As Long ' handle to target window
    30.  Dim hWndButton As Long ' handle to the button
    31.  Dim strCaptionForm As String 'caption of the target form
    32.  Dim strClassButton As String ' Button Class
    33.  Dim strCaptionButton As String ' Button Caption
    34.  Dim strClassForm As String 'Form Class Name
    35.  
    36. [B][COLOR=Red]'Get these values right or it will not work!
    37. strCaptionForm = "DMW3 - Client Login"
    38. strCaptionButton = "Login"
    39. strClassButton = "Button"
    40. strClassForm = "#32770"[/COLOR][/B]
    41.  
    42.  'Get handle to desired form
    43. ' if this returns 0 we didn't get it
    44.  hWndForm = FindWindow(strClassForm, strCaptionForm)
    45.  If hWndForm = 0 Then
    46.   MsgBox "Sorry, could not find requested form"
    47.   Exit Sub
    48.  End If
    49.  'Get handle to desired button on form
    50. ' if this returns 0 we didn't get it
    51.  hWndButton = FindWindowEx(hWndForm, 0, strClassButton, strCaptionButton)
    52.  If hWndButton = 0 Then
    53.   MsgBox "Sorry, could not find requested button"
    54.  Else
    55.  'Send click message to button
    56.   Call SendMessage(hWndButton, BM_CLICK, 0, 0)
    57.  End If
    58. End Sub
    I know yo're close, you just have to get the correct values into the caption and class variables. Did you try cutting and pasting from the text boxes?

  33. #33

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    i get the error cannot find the requested form!! , i cnt copy and paste the values because they change be4 i can get to box to copy them. have u got the spy++ program u could send me?

  34. #34
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    i cnt copy and paste the values because they change be4 i can get to box to copy them
    Of course... Duh
    Print them out to your immediate window by adding the lines:
    VB Code:
    1. Debug.Print "Caption: "; lpString
    2. Debug.Print "Class Name: "; lpClassName
    to the end of the GetWindowData subroutine in the SPY-- program. If your immediate window is not visible, the press ctrl-G

  35. #35

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    i now have my program logging me in succesffully IF i open the program first, if i use Shell command to open DMW this causes the error, therefore is there any other way to open up an exe program in VB wihout using the shell command? progressign well

    What i done moeur was decided that something was obviously wrong wrong with the DMW3 ...... bit so i added a space at the end and to my surprise it worked .

  36. #36
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    What i done moeur was decided that something was obviously wrong wrong with the DMW3 .....
    Good job!
    Maybe the program needs to wait for the login window to open.
    After the line in your code
    VB Code:
    1. hWndForm = FindWindow(strClassForm, strCaptionForm)
    Add the following
    VB Code:
    1. While hWndForm = 0
    2.     DoEvents
    3.     hWndForm = FindWindow(strClassForm, strCaptionForm)
    4. Wend
    Let's hope that works.

  37. #37
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Can this be done?

    or use runprogram

    VB Code:
    1. Option Explicit
    2. Private Const SW_SHOWNORMAL = 1
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4.     (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    5.     ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
    6.     As Long) As Long
    7.  
    8. Private Sub RunProgram(strProgram As String)
    9.     Dim lRet As Long
    10.     lRet = ShellExecute(vbNull, "", strProgram, "", "", SW_SHOWNORMAL)
    11. End Sub
    12.  
    13. Private Sub Form_Load()
    14. RunProgram ("ya")
    15. End Sub

  38. #38

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    It istn because i need to wait for th program to load, i used 2 buttons, one to openDMW and one to login, i think the porblem is the shell command. Is there any other way to open a program using its path? What is ShellExecute?

  39. #39

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    27

    Re: Can this be done?

    I dont understand whay this aint working!!!

    I can start DMW with my program, login manually then play a game fine.

    I can start DMW manually and make my program log me in to DMW, then play the game fine.

    However if i try to do these two things it doesnt work!!! i can see my program opening DMW and then clickign the login button, however if i try to play a game this way i get an error with the computer game(Something to do with OpenGL and a file not found).

    Needing help!!

    Thanks

  40. #40
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Can this be done?

    Try putting a long pause in between opening the program and clicking the button

Page 1 of 2 12 LastLast

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