Sending Messages

Setting Properties

Using Messaging, you can also set properties of controls. One of these is the redraw properties. For example, when you add lots of items to a listbox, or move the position of a cursor around a text box before restoring it to its previous position you will see lots of flickering. This is because the control is redrawing every time you add an item, or change the selection. Using messaging, you can change a property to stop this. Two are listed below

Const WM_SETFOCUS = &H7
Const WM_SETREDRAW = &HB

Using the constants above, you normally use the following syntax:

SendMessage(ControlName.hWnd, Constant, TRUE_OR_FALSE, 0& )

Where ControlName is the name of the control, Constant is one of the constants above, and TRUE_OR_FALSE is either True or False. The following example will stop Text1 from redrawing (ie the control being updated).

SendMessage(Text1.hWnd, WM_SETREDRAW, False, 0& )

To allow it to redraw, simply change False to True. Sometimes, if the control things it does not need to redraw, you need to force it to redraw:

Text1.Refresh

The following example will stop Text1 from ever getting the focus. You will receive the GotFocus event once, and then never again, until you call the SendMessage procedure and change False to True

SendMessage Text1.hwnd, WM_SETFOCUS, False, 0&

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++ : Where friends have access to your private members.” - Gavin Russell Baker