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.
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.
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?
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?
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 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:
Shell (DMWINSTALL), vbNormalFocus
Sleep 3000
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.
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:
Option Explicit
'Functions, constants and types for the hook
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long _
) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long _
) As Long
Private Declare Function CallNextHookEx Lib "user32" ( _
ByVal hHook As Long, _
ByVal ncode As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
Public Const WH_MOUSE_LL = 14
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type MSLLHOOKSTRUCT
pt As POINTAPI
mouseData As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private hHook As Long
Public IsHooked As Boolean
'functions for getting windows properties
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long _
) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long _
) As Long
Private Declare Function WindowFromPoint Lib "user32" ( _
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?
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:
Private Sub Command1_Click()
Dim hWndForm As Long ' handle to target window
Dim hWndButton As Long ' handle to the button
Dim strCaptionForm As String 'caption of the target form
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:
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
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?
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?
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.
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.
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:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
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
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?
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?
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 .
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?
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).