SendMessage/PostMessage - API makes Your programs run faster and smoother since it doesn't need to go through VB run-time for processing. Take this as Your advantage!
OK, so You want to experiment with API functions. That's a great idea because there is a lot of things You can do using API. In this article I will talk about using SendMessage and PostMessage API functions which offer pretty neat stuff.
Let's look how to close the form using SendMessage API function. First, You have to decide where to declare SendMessage. If You declare it inside the form's general declaration section, declare it as Private, if in the module, as Public. To close the form, you need WM_CLOSE as wMsg parameter. Use this line to declare the constant:
Private (or Public) Const WM_CLOSE=&H10
For WM_CLOSE message, wParam and lParam has to be set to 0. So the call to close the form1 would look like this:
Dim rc As Long ' temp variable, no real meaning in this example
rc=SendMessage(form1.hwnd, WM_CLOSE, 0, 0)
That's it! You closed the form! There are a lot of messages You can send and each with it's own wParam and lParam.
Let's look at another example. Imagine You want to set the caption of the command button using SendMessage. To do this, You need different constant as wMsg parameter: WM_SETTEXT=&HC . As wParam, pass 0, and as lParam, pass the variable holding the caption string:
Dim rc As Long
Instead of Command1.hwnd You can use form1.hwnd and other control names.
SendMessage is a great function
to know. In the near future, I will provide You with more message
constants so You could fully explore the power of SendMessage. Good Luck
experimenting, and be careful - save You work before You run Your API
Made By Laimonas Simutis. 2001. firstname.lastname@example.org