Results 1 to 22 of 22

Thread: VB API Tutorial - Standard windows messages

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    VB API Tutorial - Standard windows messages

    Windows has a large number of predefined windows messages which are sent to a window when a given event occurs. You can intercept these messages by subclassing the window and take actions accordingly. This allows you to alter or extend the way that a standard VB window (or control) behaves.

    The currently defined set of windows messages is:

    VB Code:
    1. Public Enum WindowMessages
    2.     WM_ACTIVATE = &H6
    3.     WM_ACTIVATEAPP = &H1C
    4.     WM_ASKCBFORMATNAME = &H30C
    5.     WM_CANCELJOURNAL = &H4B
    6.     WM_CANCELMODE = &H1F
    7.     WM_CAPTURECHANGED = &H1F
    8.     WM_CAPTURECHANGED_R = &H215
    9.     WM_CHANGECBCHAIN = &H30D
    10.     WM_CHAR = &H102
    11.     WM_CHARTOITEM = &H2F
    12.     WM_CHILDACTIVATE = &H22
    13.     WM_CHOOSEFONT_GETLOGFONT = &H401
    14.     WM_CHOOSEFONT_SETFLAGS = (&H400 + 102)
    15.     WM_CHOOSEFONT_SETLOGFONT = (&H400 + 101)
    16.     WM_CLEAR = &H303
    17.     WM_CLOSE = &H10
    18.     WM_COMMAND = &H111
    19.     WM_COMPACTING = &H41
    20.     WM_COMPAREITEM = &H39
    21.     WM_CONTEXTMENU = &H7B
    22.     WM_CONVERTREQUESTEX = &H108
    23.     WM_COPY = &H301
    24.     WM_COPYDATA = &H4A
    25.     WM_CREATE = &H1
    26.     WM_CTLCOLORBTN = &H135
    27.     WM_CTLCOLORDLG = &H136
    28.     WM_CTLCOLOREDIT = &H133
    29.     WM_CTLCOLORLISTBOX = &H134
    30.     WM_CTLCOLORMSGBOX = &H132
    31.     WM_CTLCOLORSCROLLBAR = &H137
    32.     WM_CTLCOLORSTATIC = &H138
    33.     WM_CUT = &H300
    34.     WM_DDE_ACK = (&H3E0 + 4)
    35.     WM_DDE_ADVISE = (&H3E0 + 2)
    36.     WM_DDE_DATA = (&H3E0 + 5)
    37.     WM_DDE_EXECUTE = (&H3E0 + 8)
    38.     WM_DDE_FIRST = &H3E0
    39.     WM_DDE_INITIATE = &H3E0
    40.     WM_DDE_LAST = (&H3E0 + 8)
    41.     WM_DDE_POKE = (&H3E0 + 7)
    42.     WM_DDE_REQUEST = (&H3E0 + 6)
    43.     WM_DDE_TERMINATE = (&H3E0 + 1)
    44.     WM_DDE_UNADVISE = (&H3E0 + 3)
    45.     WM_DEADCHAR = &H103
    46.     WM_DELETEITEM = &H2D
    47.     WM_DESTROY = &H2
    48.     WM_DESTROYCLIPBOARD = &H307
    49.     WM_DEVICECHANGE = &H219
    50.     WM_DEVMODECHANGE = &H1B
    51.     WM_DRAWCLIPBOARD = &H308
    52.     WM_DRAWITEM = &H2B
    53.     WM_DROPFILES = &H233
    54.     WM_ENABLE = &HA
    55.     WM_ENDSESSION = &H16
    56.     WM_ENTERIDLE = &H121
    57.     WM_ENTERSIZEMOVE = &H231
    58.     WM_ENTERMENULOOP = &H211
    59.     WM_ERASEBKGND = &H14
    60.     WM_EXITMENULOOP = &H212
    61.     WM_EXITSIZEMOVE = &H232
    62.     WM_FONTCHANGE = &H1D
    63.     WM_GETDLGCODE = &H87
    64.     WM_GETFONT = &H31
    65.     WM_GETHOTKEY = &H33
    66.     WM_GETMINMAXINFO = &H24
    67.     WM_GETTEXT = &HD
    68.     WM_GETTEXTLENGTH = &HE
    69.     WM_HELP = &H53
    70.     WM_HOTKEY = &H312
    71.     WM_HSCROLL = &H114
    72.     WM_HSCROLLCLIPBOARD = &H30E
    73.     WM_ICONERASEBKGND = &H27
    74.     WM_IME_CHAR = &H286
    75.     WM_IME_COMPOSITION = &H10F
    76.     WM_IME_COMPOSITIONFULL = &H284
    77.     WM_IME_CONTROL = &H283
    78.     WM_IME_ENDCOMPOSITION = &H10E
    79.     WM_IME_KEYDOWN = &H290
    80.     WM_IME_KEYLAST = &H10F
    81.     WM_IME_KEYUP = &H291
    82.     WM_IME_NOTIFY = &H282
    83.     WM_IME_SELECT = &H285
    84.     WM_IME_SETCONTEXT = &H281
    85.     WM_IME_STARTCOMPOSITION = &H10D
    86.     WM_INITDIALOG = &H110
    87.     WM_INITMENU = &H116
    88.     WM_INITMENUPOPUP = &H117
    89.     WM_INPUTLANGCHANGEREQUEST = &H50
    90.     WM_INPUTLANGCHANGE = &H51
    91.     WM_KEYDOWN = &H100
    92.     WM_KEYUP = &H101
    93.     WM_KILLFOCUS = &H8
    94.     WM_LBUTTONDBLCLK = &H203
    95.     WM_LBUTTONDOWN = &H201
    96.     WM_LBUTTONUP = &H202
    97.     WM_MBUTTONDBLCLK = &H209
    98.     WM_MBUTTONDOWN = &H207
    99.     WM_MBUTTONUP = &H208
    100.     WM_MDIACTIVATE = &H222
    101.     WM_MDICASCADE = &H227
    102.     WM_MDICREATE = &H220
    103.     WM_MDIDESTROY = &H221
    104.     WM_MDIGETACTIVE = &H229
    105.     WM_MDIICONARRANGE = &H228
    106.     WM_MDIMAXIMIZE = &H225
    107.     WM_MDINEXT = &H224
    108.     WM_MDIREFRESHMENU = &H234
    109.     WM_MDIRESTORE = &H223
    110.     WM_MDISETMENU = &H230
    111.     WM_MDITILE = &H226
    112.     WM_MEASUREITEM = &H2C
    113.     WM_MENUCHAR = &H120
    114.     WM_MENUSELECT = &H11F
    115.     WM_MENURBUTTONUP = &H122
    116.     WM_MENUDRAG = &H123
    117.     WM_MENUGETOBJECT = &H124
    118.     WM_MENUCOMMAND = &H126
    119.     WM_MOUSEACTIVATE = &H21
    120.     WM_MOUSEHOVER = &H2A1
    121.     WM_MOUSELEAVE = &H2A3
    122.     WM_MOUSEMOVE = &H200
    123.     WM_MOUSEWHEEL = &H20A
    124.     WM_MOVE = &H3
    125.     WM_MOVING = &H216
    126.     WM_NCACTIVATE = &H86
    127.     WM_NCCALCSIZE = &H83
    128.     WM_NCCREATE = &H81
    129.     WM_NCDESTROY = &H82
    130.     WM_NCHITTEST = &H84
    131.     WM_NCLBUTTONDBLCLK = &HA3
    132.     WM_NCLBUTTONDOWN = &HA1
    133.     WM_NCLBUTTONUP = &HA2
    134.     WM_NCMBUTTONDBLCLK = &HA9
    135.     WM_NCMBUTTONDOWN = &HA7
    136.     WM_NCMBUTTONUP = &HA8
    137.     WM_NCMOUSEMOVE = &HA0
    138.     WM_NCPAINT = &H85
    139.     WM_NCRBUTTONDBLCLK = &HA6
    140.     WM_NCRBUTTONDOWN = &HA4
    141.     WM_NCRBUTTONUP = &HA5
    142.     WM_NEXTDLGCTL = &H28
    143.     WM_NEXTMENU = &H213
    144.     WM_NULL = &H0
    145.     WM_PAINT = &HF
    146.     WM_PAINTCLIPBOARD = &H309
    147.     WM_PAINTICON = &H26
    148.     WM_PALETTECHANGED = &H311
    149.     WM_PALETTEISCHANGING = &H310
    150.     WM_PARENTNOTIFY = &H210
    151.     WM_PASTE = &H302
    152.     WM_PENWINFIRST = &H380
    153.     WM_PENWINLAST = &H38F
    154.     WM_POWER = &H48
    155.     WM_POWERBROADCAST = &H218
    156.     WM_PRINT = &H317
    157.     WM_PRINTCLIENT = &H318
    158.     WM_PSD_ENVSTAMPRECT = (&H400 + 5)
    159.     WM_PSD_FULLPAGERECT = (&H400 + 1)
    160.     WM_PSD_GREEKTEXTRECT = (&H400 + 4)
    161.     WM_PSD_MARGINRECT = (&H400 + 3)
    162.     WM_PSD_MINMARGINRECT = (&H400 + 2)
    163.     WM_PSD_PAGESETUPDLG = (&H400)
    164.     WM_PSD_YAFULLPAGERECT = (&H400 + 6)
    165.     WM_QUERYDRAGICON = &H37
    166.     WM_QUERYENDSESSION = &H11
    167.     WM_QUERYNEWPALETTE = &H30F
    168.     WM_QUERYOPEN = &H13
    169.     WM_QUEUESYNC = &H23
    170.     WM_QUIT = &H12
    171.     WM_RBUTTONDBLCLK = &H206
    172.     WM_RBUTTONDOWN = &H204
    173.     WM_RBUTTONUP = &H205
    174.     WM_RENDERALLFORMATS = &H306
    175.     WM_RENDERFORMAT = &H305
    176.     WM_SETCURSOR = &H20
    177.     WM_SETFOCUS = &H7
    178.     WM_SETFONT = &H30
    179.     WM_SETHOTKEY = &H32
    180.     WM_SETREDRAW = &HB
    181.     WM_SETTEXT = &HC
    182.     WM_SETTINGCHANGE = &H1A
    183.     WM_SHOWWINDOW = &H18
    184.     WM_SIZE = &H5
    185.     WM_SIZING = &H214
    186.     WM_SIZECLIPBOARD = &H30B
    187.     WM_SPOOLERSTATUS = &H2A
    188.     WM_SYSCHAR = &H106
    189.     WM_SYSCOLORCHANGE = &H15
    190.     WM_SYSCOMMAND = &H112
    191.     WM_SYSDEADCHAR = &H107
    192.     WM_SYSKEYDOWN = &H104
    193.     WM_SYSKEYUP = &H105
    194.     WM_TIMECHANGE = &H1E
    195.     WM_TIMER = &H113
    196.     WM_UNDO = &H304
    197.     WM_USER = &H400
    198.     WM_VKEYTOITEM = &H2E
    199.     WM_VSCROLL = &H115
    200.     WM_VSCROLLCLIPBOARD = &H30A
    201.     WM_WINDOWPOSCHANGED = &H47
    202.     WM_WINDOWPOSCHANGING = &H46
    203.     WM_WININICHANGE = &H1A
    204.     WM_APPCOMMAND = &H319
    205. End Enum

    As well as the message there are two parameters called wParam and lParam which give you additional information about the event that occured.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_ACTIVATEAPP

    WM_ACTIVATEAPP

    This message is sent to the top level window of an application when that application gains or loses the focus. i.e. when the user ALT+TAB switches to/from it or clicks on the application in the task bar etc.

    wParam - This is non-zero if your application is gaining the focus, and zero if it is losing the focus.

    lParam - This is the thread handle of the other application. If your application gains the focus this is the thread handle of the application that lost the focus and if your application loses the focus this is the thread handle of the application that will get the focus next.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_CAPTURECHANGED

    WM_CAPTURECHANGED
    This message is sent to a window when it gains of loses the mouse capture, either as a result of the user or by the SetCapture API call.

    wParam - This parameter is ignored

    lParam - The window handle of the window which is gaining the focus.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_CHAR

    WM_CHAR
    This message is posted to a window when a keyboard key is pressed (other than ALT) and the window has the input focus.

    wParam - This is the virtual key number which corresponds to the vbKey constants like vbKeyA if key "A" was pressed.

    lParam - This holds additional information about the key press.
    Bits 0-15 is the repetition count (when a key is held down)
    Bits 16-23 is the scan code of the key - this is dependednt on the actual keyboard hardware
    Bit 29 is set if the ALT key is down
    Bit 30 is set if the key was already down i.e. the event is due to a key repetition
    Bit 31 is set if the ke is being pressed, i.e. opposite to bit 30

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_COMPACTING

    WM_COMPACTING
    This message is sent to all top level windows when the operating system is running low on memory and is compacting the memory.

    wParam - The amount of time spent compacting : the higher this number is the more trouble windows is having freeing up memory

    lParam - Unused (set to zero)

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MOVE

    WM_MOVE
    This message is sent to a window when it has been moved.
    (Why this isn't part of the standard VB form events is beyond me...)

    wParam - Unused, set to zero

    lParam The upper 16 bits (HIWORD) hold the vertical (y) position of the window after the move, and the lower 16 bits (LOWORD) holds the horizontal(x) position of the window after the move.

    You can use this message to be notified whenever a user moves a form.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_NCLBUTTONDOWN etc...

    WM_NCLBUTTONDOWN , WM_NCMBUTTONDOWN , WM_NCRBUTTONDOWN , WM_NCLBUTTONUP etc.
    WM_NCLBUTTONDOWN , WM_NCMBUTTONDOWN , WM_NCRBUTTONDOWN
    The mouse button (left, middle or right respectively) was pressed down while the pointer was over the non-client area of the subclassed window.

    WM_NCLBUTTONUP , WM_NCMBUTTONUP , WM_NCRBUTTONUP
    The mouse button (left, middle or right respectively) was released while the pointer was over the non-client area of the subclassed window.

    WM_NCMOUSEMOVE
    The mouse moved over the non client area of the form

    wParam - The bit of the non client area which the mouse event occured over. This can be one of:

    VB Code:
    1. Public Enum enHitTestResult
    2.     HTBORDER = 18
    3.     HTBOTTOM = 15
    4.     HTBOTTOMLEFT = 16
    5.     HTBOTTOMRIGHT = 17
    6.     HTCAPTION = 2
    7.     HTCLIENT = 1
    8.     HTERROR = (-2)
    9.     HTGROWBOX = 4
    10.     HTHSCROLL = 6
    11.     HTLEFT = 10
    12.     HTMAXBUTTON = 9
    13.     HTMENU = 5
    14.     HTMINBUTTON = 8
    15.     HTNOWHERE = 0
    16.     HTRIGHT = 11
    17.     HTSYSMENU = 3
    18.     HTTOP = 12
    19.     HTTOPLEFT = 13
    20.     HTTOPRIGHT = 14
    21.     HTVSCROLL = 7
    22.     HTTRANSPARENT = (-1)
    23.     HTOBJECT = 19
    24.     HTCLOSE = 20
    25.     HTHELP = 21
    26. End Enum

    lParam - The lower 16 bits are an unsigned integer representing the x position of the mouse pointer when the event occured and the upper 16 bits are an unsigned integer representing the y position of the pointer.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MINMAXSIZE

    WM_GETMINMAXINFO
    Whenever a window is going from being minimised to maximised or restored this message is sent to the window to allow it to specify the size of the window resulting from the operation.

    wParam - Unused

    lParam - Pointer to a MINMAXINFO structure defined thus:


    VB Code:
    1. Private Type POINTAPI
    2.     x As Long
    3.     y As Long
    4. End Type
    5.  
    6. Private Type MINMAXINFO
    7.     ptReserved As POINTAPI
    8.     ptMaxSize As POINTAPI
    9.     ptMaxPosition As POINTAPI
    10.     ptMinTrackSize As POINTAPI
    11.     ptMaxTrackSize As POINTAPI
    12. End Type

    You can use the API call RtlMoveMemory to copy this structure to or from this pointer e.g.:

    VB Code:
    1. Private Declare Sub CopyMemoryMinMaxInfo Lib "kernel32" _
    2.            Alias "RtlMoveMemory" (Destination As MINMAXINFO, _
    3.                        ByVal Source As Long, ByVal Length As Long)
    4. Private Declare Sub CopyMinMaxToMemoryInfo Lib "kernel32" _
    5.                 Alias "RtlMoveMemory" (ByVal Destination As Long,  _
    6.                        Source As MINMAXINFO, ByVal Length As Long)

    Thus to make the maximised size of a window to be 300 x 200 you could process this message thus:

    VB Code:
    1. '..snippet from message handler loop
    2. Case WM_GETMINMAXINFO
    3.     Dim mmInfo As MINMAXINFO
    4.     Call CopyMemoryMinMaxInfo(mmInfo, lParam, Len(mmInfo)
    5.     With mmInfo.ptMaxSize
    6.          .x = 300
    7.          .y = 200
    8.     End With
    9.     Call CopyMinMaxToMemoryInfo(lParam, mmInfo, Len(mmInfo))
    10. '...

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_SIZING

    WM_SIZING
    WM_SIZING is sent to a sizeable window (i.e. a form with borderstyle set to Sizeable) when the user is resizing it.
    Intercepting this message allows you to control the resizing process without flickering as the message is sent before the form is drawn at it's new size.

    wParam - Indicates which edge is being used to resize the window. This value is one of:
    • WMSZ_LEFT = 1 The sizing is from the left hand frame border
    • WMSZ_RIGHT = 2 The sizing is from the right hand frame border
    • WMSZ_TOP = 3 The sizing is from the top frame border
    • WMSZ_TOPLEFT = 4 The sizing is from the top left corner
    • WMSZ_TOPRIGHT = 5 The sizing is from the top right corner
    • WMSZ_BOTTOM = 6 The sizing is from the bottom frame border
    • WMSZ_BOTTOMLEFT = 7 The sizing is from the bottom left corner
    • WMSZ_BOTTOMRIGHT = 8 'The sizing is from the bottom right corner



    [b]lParam is a pointer to the rectangle that describes the size of the window after the sizing has taken place. If you alter the values of this rectangle the sizing will go to that size instead.

    e.g. to prevent the width of the window exceeding 100 pixels:-

    VB Code:
    1. Private Type RECT
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7.  
    8. Private Declare Sub CopyMemoryRect Lib "kernel32" Alias "RtlMoveMemory" (Destination As RECT,  _
    9.       ByVal Source As Long, ByVal Length As Long)
    10. Private Declare Sub CopyMemoryFromRect Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, _
    11.        Source As RECT, ByVal Length As Long)
    12.  
    13. '.....
    14. If msg = WM_SIZING Then
    15.    Dim rcSize As RECT
    16.    Call CopyMemoryRect(rcSize, lParam, Len(rcSize))
    17.    If rcSize.Right - rcSize.Left > 100 Then
    18.       rcSize.Right = rcSize.Left + 100
    19.    End If
    20.    Call CopyMemoryFromRect(lParam, rcSize, Len(rcSize))
    21. End If
    22. '.....

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MOVING

    WM_MOVING
    WM_MOVING is sent to a window when the user is moving it by dragging it.
    Intercepting this message allows you to control the resizing process without flickering as the message is sent before the form is drawn at it's new size.

    lParam is a pointer to the rectangle that describes the position of the window after the move has taken place. If you alter the values of this rectangle the window will move to that position instead.

    e.g. to prevent the being moved left of the middle of the screen:-

    VB Code:
    1. Private Type RECT
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7.  
    8. Private Declare Sub CopyMemoryRect Lib "kernel32" Alias "RtlMoveMemory" (Destination As RECT,  _
    9.       ByVal Source As Long, ByVal Length As Long)
    10. Private Declare Sub CopyMemoryFromRect Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, _
    11.        Source As RECT, ByVal Length As Long)
    12.  
    13. '.....
    14. If msg = WM_MOVING Then
    15.    Dim rcMove As RECT
    16.    Call CopyMemoryRect(rcMove , lParam, Len(rcMove ))
    17.    If rcMove  < (Screen.Width / 2 ) / Screen.TwipsperPixelX Then
    18.       rcMove.Left = (Screen.Width / 2 ) / Screen.TwipsperPixelX
    19.    End If
    20.    Call CopyMemoryFromRect(lParam, rcMove , Len(rcMove ))
    21. End If
    22. '.....

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MOUSEHOVER

    WM_MOUSEHOVER

    WM_MOUSEHOVER is sent to a window that has been registered as a mouse tracking window if the pointer hovers over that window for a system defined time period.

    wParam - The combination of mouse key flags which show which buttons were pressed down:
    • MK_LBUTTON &H1 indicates that the left mouse button is pressed
    • MK_RBUTTON &H2 indicates that the right mouse button is pressed
    • MK_SHIFT &H4 indicates that the Shift key is pressed
    • MK_CONTROL &H8 indicates that the Control key is pressed
    • MK_MBUTTON &H10 idicates that the middle mouse button is pressed
    • MK_XBUTTON1 &H20 indicates that the first XButton is pressed
    • MK_XBUTTON2 &H40 indicates that the second XButton is pressed



    lParam - The lower 16 bits are an unsigned integer representing the x position of the mouse pointer when the event occured and the upper 16 bits are an unsigned integer representing the y position of the pointer.

    Notes - To tell Windows that you wish to be informed about the MouseHover event you need to fill in a TRACKMOUSEEVENT structure and call the TrackMouseEvent API call.

    VB Code:
    1. Public Enum TrackMouseEventFlags
    2.      TME_HOVER = &H1
    3.      TME_LEAVE = &H2
    4.      TME_NONCLIENT = &H10
    5.      TME_QUERY = &H40000000
    6.      TME_CANCEL = &H80000000
    7. End Enum
    8.  
    9. Private Type TRACKMOUSESTRUCT
    10.     cbSize As Long
    11.     dwFlags As TrackMouseEventFlags '\\ TrackMouseEvents
    12.     hwndTrack As Long '\\ Target window
    13.     dwHoverTime As Long '\\ Mouse hover timeout in milliseconds
    14. End Type
    15. Private Declare Function TrackMouseEvent Lib "user32" (lpTrackMouseStruct As TRACKMOUSESTRUCT) As Long

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MOUSELEAVE

    WM_MOUSELEAVE
    WM_MOUSELEAVE is sent to a window that has been registered as a mouse tracking window if the pointer leaves that window.

    wParam - NOT USED

    lParam - NOT USED

    Notes - To tell Windows that you wish to be informed about the MouseHover event you need to fill in a TRACKMOUSEEVENT structure and call the TrackMouseEvent API call.

    VB Code:
    1. Public Enum TrackMouseEventFlags
    2.      TME_HOVER = &H1
    3.      TME_LEAVE = &H2
    4.      TME_NONCLIENT = &H10
    5.      TME_QUERY = &H40000000
    6.      TME_CANCEL = &H80000000
    7. End Enum
    8.  
    9. Private Type TRACKMOUSESTRUCT
    10.     cbSize As Long
    11.     dwFlags As TrackMouseEventFlags '\\ TrackMouseEvents
    12.     hwndTrack As Long '\\ Target window
    13.     dwHoverTime As Long '\\ Mouse hover timeout in milliseconds
    14. End Type
    15. Private Declare Function TrackMouseEvent Lib "user32" (lpTrackMouseStruct As TRACKMOUSESTRUCT) As Long

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_CTLCOLORBUTTON

    WM_CTLCOLORBTN
    WM_CTLCOLORBTN - is sent to a perent window (such as a form or panel control) when a button control on that form is going to be drawn to allow the parent to supply a different brush to colour it with.

    wParam - A handle to the Device Context of the button control that is going to be drawn

    lParam - The window handle of the button control that is going to be drawn.

    Notes In order to paint the button using a different brush you pass the logical brush handle back as the return value from your window proc and do not pass the message on to the standard window procedure.
    For example, to paint the button with a hatched red background:

    VB Code:
    1. Public Enum BrushStyles
    2.     BS_SOLID = 0
    3.     BS_NULL = 1
    4.     BS_HATCHED = 2
    5.     BS_PATTERN = 3
    6.     BS_INDEXED = 4
    7.     BS_DIBPATTERN = 5
    8.     BS_DIBPATTERNPT = 6
    9.     BS_PATTERN8X8 = 7
    10.     BS_DIBPATTERN8X8 = 8
    11.     BS_MONOPATTERN = 9
    12. End Enum
    13.  
    14. Public Enum HatchStyles
    15.      HS_HORIZONTAL = 0 '/* ----- */
    16.      HS_VERTICAL = 1 '/* ||||| */
    17.      HS_FDIAGONAL = 2 '/* \\\\\ */
    18.      HS_BDIAGONAL = 3 '/* ///// */
    19.      HS_CROSS = 4 '/* +++++ */
    20.      HS_DIAGCROSS = 5 '/* xxxxx */
    21. End Enum
    22.  
    23. Private Type LogBrush
    24.     lbStyle As BrushStyles
    25.     lbColor As Long
    26.     lbHatch As HatchStyles
    27. End Type
    28.  
    29. Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LogBrush) As Long
    30.  
    31. Dim hMyButtonBrush As Long

    And at form load use:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim brush As LogBrush
    4.  
    5. With brush
    6.    .lbStyle = BS_HATCHED
    7.    .lbColor = vbRed
    8.    .lbHatch = HS_DIAGCROSS
    9. End With
    10.  
    11. hMyButtonBrush = CreateBrushIndirect(brush)

    and in the subclass procedure...

    VB Code:
    1. '......
    2. If msg = WM_CTLCOLORBUTTON Then
    3.     WndProc = hMyButtonBrush
    4.     Exit Function
    5. Else
    6.     WndProc = CallWindowProc(lpOldProc, wMsg, wParam, lParam)
    7. End If

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WMCTLCOLORSCROLL etc.

    WM_CTLCOLOREDIT , WM_CTLCOLORLISTBOX , WM_CTLCOLORSCROLLBAR , WM_CTLCOLORSTATIC
    WM_CTLCOLOREDIT , WM_CTLCOLORLISTBOX , WM_CTLCOLORSCROLLBAR , WM_CTLCOLORSTATIC - Same as WM_CTLCOLORBUTTON except for textbox, listbox, scrollbar and static controls respectively.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_MOUSEWHEEL

    WM_MOUSEWHEEL - This message is sent to the window that has the input capture when the user moves the mouse wheel up or down.

    wParam - The upper 16 bits hold the amount of rotation (negative being downwards, positive up) and the lower 16 bits hold the mouse key flags:

    • MK_LBUTTON &H1 indicates that the left mouse button is pressed
    • MK_RBUTTON &H2 indicates that the right mouse button is pressed
    • MK_SHIFT &H4 indicates that the Shift key is pressed
    • MK_CONTROL &H8 indicates that the Control key is pressed
    • MK_MBUTTON &H10 idicates that the middle mouse button is pressed
    • MK_XBUTTON1 &H20 indicates that the first XButton is pressed
    • MK_XBUTTON2 &H40 indicates that the second XButton is pressed



    lParam - The lower 16 bits represents the x position of the mouse pointer when the wheel moved and the upper 16 bits represent the y position.

  16. #16
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596
    this is really good!!
    congrats!
    you are getting a 5 rating from me!
    but aren't you going to continue it?
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    I'm only working on those messages that VB does not convert into a native VB method at the moment. Each message is documented on MSDN but this is still going to take some time...

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    WM_HSCROLL and WM_VSCROLL

    WM_HSCROLL and WM_VSCROLL are sent to a window when the intrinsic scrollbars of that window are moved. Although VB forms do not have a property that coresponds to showing the intrinsic scrollbars you can simulate this by adding the window styles WS_HSCROLL and WH_VSCROLL to the window.

    wParam: The LOWORD specifies the scroll type, and the HIWORD specifies the value of the scrollbar position after the scroll is effected.
    VB Code:
    1. Public Enum enScrollMessages
    2.     SB_ENDSCROLL = 8
    3.     SB_TOP = 6
    4.     SB_LINELEFT = 0
    5.     SB_LINERIGHT = 1
    6.     SB_LINEDOWN = 1
    7.     SB_LINEUP = 0
    8.     SB_PAGEDOWN = 3
    9.     SB_PAGELEFT = 2
    10.     SB_PAGERIGHT = 3
    11.     SB_PAGEUP = 2
    12.     SB_RIGHT = 7
    13.     SB_LEFT = 6
    14.     SB_THUMBPOSITION = 4
    15.     SB_THUMBTRACK = 5
    16. End Enum

    lParam: If the message is sent to a parent window from a scroll control then this holds the window handle of the scrollbar control that sent the message

  19. #19
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694
    great very good!

  20. #20
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Wooahh! better save this page as a complete HTML file, cant take all this in yet. Its good to see that you are bothered to take the time and effort to post so much information like this.

    THANKS!

    5 Starts from me

  21. #21
    Member
    Join Date
    Jun 2005
    Posts
    61

    Re: WM_CHAR

    Quote Originally Posted by Merrion
    WM_CHAR
    This message is posted to a window when a keyboard key is pressed (other than ALT) and the window has the input focus.

    wParam - This is the virtual key number which corresponds to the vbKey constants like vbKeyA if key "A" was pressed.

    lParam - This holds additional information about the key press.
    Bits 0-15 is the repetition count (when a key is held down)
    Bits 16-23 is the scan code of the key - this is dependednt on the actual keyboard hardware
    Bit 29 is set if the ALT key is down
    Bit 30 is set if the key was already down i.e. the event is due to a key repetition
    Bit 31 is set if the ke is being pressed, i.e. opposite to bit 30
    How would I set the ALT key and other bits?

  22. #22
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: VB API Tutorial - Standard windows messages

    Quote Originally Posted by Madboy
    Wooahh! better save this page as a complete HTML file, cant take all this in yet. Its good to see that you are bothered to take the time and effort to post so much information like this.

    THANKS!

    5 Starts from me
    I don't usually do 'me too' posts, but me too. This is definitely going into my documentation directory as a .doc file.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width