meteorelec
asked on
Passing a parameter to VB and then using sendmessage
What I'm doing here is firing an exe from a command line with a parameter at the end. This is then passed to the exe and used to look up the account. I can pass the parameter by using sendkeys but I want to use sendmessage to do it. I have attached snippets of the code that I am trying to use without success. I'm not suer if I should be using WM_SETTEXT or the CStr(AccountName). Any advice would be very welcome. Thanks.
Public AccountName As String = ""
Call SendMessageByString(TPickList, WM_SETTEXT, 0&, CStr(AccountName))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Idle Mind,
I've tried what you have said and this is where I'm at. I can use sendmessage to click the button that I require on the application window, I can now use sendmessage to send a piece of text to the box that needs to be populated. However when I put these onto the one button they do not work so from the form that I have developed I have to button's one to generate the window that needs to be populated and one then to pass the text. I have attached the code below. Thanks for your help.
I've tried what you have said and this is where I'm at. I can use sendmessage to click the button that I require on the application window, I can now use sendmessage to send a piece of text to the box that needs to be populated. However when I put these onto the one button they do not work so from the form that I have developed I have to button's one to generate the window that needs to be populated and one then to pass the text. I have attached the code below. Thanks for your help.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessageByString(TBitBtnEx, BM_CLICK, 0&, 0) 'Not sure if CStr is a function in VB7?'
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call SendMessageByString(TPickList, WM_SETTEXT, IntPtr.Zero, "WM_SETTEXT works...")
End Sub
Have you tried adding a delay between the two to allow the window to pop up?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessageByString(TBitBt nEx, BM_CLICK, 0&, 0)
System.Threading.Thread.Sl eep(1000)
SendMessageByString(TPickL ist, WM_SETTEXT, IntPtr.Zero, "WM_SETTEXT works...")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessageByString(TBitBt
System.Threading.Thread.Sl
SendMessageByString(TPickL
End Sub
ASKER
Yeah I tried that without success, I've just tried it with your code and it was unsuccessful as well.
It seems to be once completes the SendMessageByString(TBitBt nEx, BM_CLICK, 0&, 0) and generates the new window that it is looking for something else.
The reason that I say this is because I cannot go back to Form 1 to click the other button but if I split the commands onto 2 seperate buttons then I can click the 1st button to generate the Account Lookup window and click the 2nd button to pass the text with no problems.
It seems to be once completes the SendMessageByString(TBitBt
The reason that I say this is because I cannot go back to Form 1 to click the other button but if I split the commands onto 2 seperate buttons then I can click the 1st button to generate the Account Lookup window and click the 2nd button to pass the text with no problems.
I wonder if PostMessage() instead of SendMessage() would make a difference... =\
ASKER
Do you know how to define it?
It should be declared exactly like SendMessage....just change "SendMessage" to "PostMessage". =)
ASKER
Hi Idle Mind, I did a bit of playing about and got it working through the use of the Postmessage followed by a delay and then the SendMessageByString. Hopefully the rest of it will be a bit less tricky lol. Thanks for your help.
You're welcome!
I was helping you in two of your other open questions...is this related to those as well? ...or do I need to revisit those threads?
I was helping you in two of your other open questions...is this related to those as well? ...or do I need to revisit those threads?
ASKER
Yeah this is related to those as well but don't worry about them as I think I'll be able to fumble my way from here. If I can't then I'll post a new thread. Once again thanks a million for the help.
Excuse me, Is this code in C#?
That's VB.Net code...though you could easily use a free online converter to get it into C#.
Open in new window