Library tutorials & articles

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&

Comments

  1. 27 Jun 2005 at 08:24
    Is ther any one who has been worked on organiation chart in vb.net
  2. 20 Sep 2004 at 12:43

    Dude i have got a software which does all the thing u told but its for sale just 1.2$ or 50Rs
    if u wish u can mail me humanprocessor@yahoo.co.in

  3. 07 Apr 2004 at 13:07

    I wanted to use sendmessage in VB.net
    with following declaration
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
       Public Shared Function SendMessage( _
           ByVal handle As IntPtr, _
           ByVal message As Integer, _
           ByVal wParam As IntPtr, _
           ByVal lParam As String _
      &nbsp As Integer
    end function
    But I am not getting the required text but I am getting windows text.
    Actually I am trying to get user typed URL from the address bar of IE.
    But the functions returns IE windows text
    Could any one suggest me how to solve this problem

  4. 16 Sep 2002 at 07:21
    Hi,
    I want to store all the keystrokes from diiferent windows programs. Like i am typing in word, writing code in VB, editing a Txt file or filling information on web as i am doiing now.....I want to get all the keystrokes....stored in a file.
    Please reply me....
  5. 01 Jan 1999 at 00:00

    This thread is for discussions of Sending Messages.

Leave a comment

Sign in or Join us (it's free).

James Crowley 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 audience ...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback