07-29-2011, 11:15 PM
(This post was last modified: 07-30-2011, 12:18 AM by AceInfinity.)
http://msdn.microsoft.com/en-us/library/...85%29.aspx
http://msdn.microsoft.com/en-us/library/...85%29.aspx
I was fooling around with the FindWindow function and found out how to send windows messages to your system. With this method, you can actually press buttons on external programs of your choice and do almost anything you want inside of them.
&HC is just a hexadecimal value of "12"
You can have the code as this instead if you wanted, but hexidecimal is much easier in my opinion:
Previews:
One more thing:
If you aren't familiar with hexidecimal you can cheat and use a simple vb.net code that I sometimes use.
That will messagebox the result of &HC in integer format which is "12". Change "&HC" to whatever you want to find the value of, or you can use this in a reverse way to get the hexadecimal format.
basically by calling the windows api, we should be able to invoke the windows message to be able to send it.
Reading windows messages is even easier, as we don't have to call the windows api to do it.
http://msdn.microsoft.com/en-us/library/...85%29.aspx
I was fooling around with the FindWindow function and found out how to send windows messages to your system. With this method, you can actually press buttons on external programs of your choice and do almost anything you want inside of them.
Code:
Public Class Form1
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) _
As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" _
(ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) _
As Integer
Private Declare Function SendMSG Lib "user32.dll" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) _
As Integer
'Declare constant Windows Message Set Text with the int value of 12
Private Const WM_SETTEXT As Integer = &HC
'hwnd is now a system handle and Int_hwnd
Private hwnd As IntPtr
Private Int_hwnd As IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'setting lpwindowname with the value of textbox1.text for the window we are trying to "find"
hwnd = FindWindow(vbNullString, TextBox1.Text)
'send a windows message to set the text of the window with Textbox2.text
SendMSG(hwnd, WM_SETTEXT, 0, TextBox2.Text)
'Here we set Textbox3.text with the value of the specified new "title" we
'inputted earlier so that we don't have to input the new "title" twice
'(optional) but it helps
TextBox3.Text = TextBox2.Text
End Sub
'Same idea below but we use the handler defined for Int_hwnd instead
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
hwnd = FindWindow(vbNullString, TextBox3.Text)
Int_hwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString)
SendMSG(Int_hwnd, WM_SETTEXT, 0, TextBox4.Text)
End Sub
End Class
&HC is just a hexadecimal value of "12"
You can have the code as this instead if you wanted, but hexidecimal is much easier in my opinion:
Code:
Private Const WM_SETTEXT As Integer = 12
Previews:
One more thing:
If you aren't familiar with hexidecimal you can cheat and use a simple vb.net code that I sometimes use.
Code:
Dim input As String = "&HC"
Dim value As Integer = Val(input)
MsgBox(value)
That will messagebox the result of &HC in integer format which is "12". Change "&HC" to whatever you want to find the value of, or you can use this in a reverse way to get the hexadecimal format.
basically by calling the windows api, we should be able to invoke the windows message to be able to send it.
Reading windows messages is even easier, as we don't have to call the windows api to do it.