API TUTORIAL for Beginners-II
This is the 2nd in the series of articles and shows you the significance and importance of the sendmessage api and also showing you how the password text from a password field is captured using the sendmessage api
Original Author: venky_dude
Code
API TUTORIAL FOR BEGINNERS-II The SendMessage API The SendMessage Api is one of the The Windows Operating While programming in VB the Let us look a the declaration of 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 The SendMessage api hwnd-The handle of the window wMsg-The message that is wParam-Parameter to be sent lParam-Parameter to be sent Example1 Let us see a practical Once we have this handle we need Along with the declaration of the sendmessage api you need to Private Const WM_GETTEXT = &HD Put the following in any event of a control .In this example we Private Sub command1_click() Dim length As Long End Sub here hwnd is the handle of the password textbox. Example 2 In this example we will try to change the title of any As was the case previously we have to get the handle of the After we get the handle of this window we do a sendmesaage dim result as long dim str1 as string str1="Venky" result = SendMessage(hwnd, WM_SETTEXT, ByVal 0, ByVal str1) Using almost the similar techniques you can also put your own In this tutorial we have seen a few uses of the Questions,comments send them to venky_dude@yahoo.com
most powerful api functions . Before we take a look at it's uses and
syntax let me give you a brief overview of how the windows os works.
System is a message based operating system .By saying message based means
that whenever the operating system (os) has to comunicate with applications
or two applications need to communicate/send data among themselves they do
so by sending messages to one another. For eg when an application is to be
terminated the os sends a WM_DESTROY message to that application, also when you
are adding an item to a listbox ,the application/os sends a LB_ADDSTRING message
to the listbox .
sendmessage api is not of much use when u want to manipulate objects controls in
your own application.But say u wanted to change the title of some other
application or wanted to get the text from a textbox of another application or
want to terminate another application ,or set the text in a text box of another
application. The uses are endless if u want to play around with your
system.Also if you are planning to move over to win32 programming using
c++ you just cannot escape the sendmessage api.
the sendmessage api
function basically takes 4 parameters
to which the message is being sent
being sent to the window.
along with the message(depends on the message)
along with the message(depends on the message)
implementation of this api . Let us assume that we want to get the ***
masked text from a password textbox of a window!!! .We need to know a few things
before we can do this. The first thing we need to know is the handle
to the textbox window. One way of getting this is by using the
windowfrompoint api.Check my first tutorial on how to use this api and get the
window handle of the textbox.
to send a WM_GETTEXTLENGTH message to the textbox .This message is essentially
sent to query the textbox and get the length of the text string in that
textbox.After we know the length of the string we have to send a WM_GETTEXT
message to the textbox and the textbox will return the text as the result .This
is how it is done
declare the 2 message constants that we are going to use
Private Const WM_GETTEXTLENGTH = &HE
are putting it in a command click event
Dim result As Long
Dim strtmp As String
length = SendMessage(hwnd, WM_GETTEXTLENGTH, ByVal 0, ByVal 0) + 1
strtmp = Space(length)
result = SendMessage(hwnd, WM_GETTEXT, ByVal length, ByVal strtmp)
application ,in this case it will be a windows notepad application.
notepad window .There are 2 ways to get this one is by using the windowfrompoint
api and the other is by using the findwindow api.The findwindow api returns the
handle of the window whose title has been specified in the function.
function
text in the edit window of the notepad application.
sendmessage api.You can try out any of the numerous messages in the windows os
system on any applciation. Sendmessage is in other words a bridge for
communication between your application and another application
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.