Results 1 to 8 of 8

Thread: Get the message

  1. #1

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467

    Get the message

    hi everybody
    i am using following piece of code to catch the messages. Now
    MSDN says that you can only use the low word of the message
    parameter of the MSG structure. I know this is very much possible
    by using LOWORD in windows programming with C, but how can i read the low word of message from VB?
    VB Code:
    1. Private Sub getMessage()
    2. Dim MS As MSG
    3. Do While 1
    4.     DoEvents
    5.     PeekMessage MS, Me.hWnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE
    6.     Select Case MS.message
    7.        
    8.         'This is where i need help
    9.  
    10.     End Select
    11. Loop
    12. End Sub

    Please help me.
    Thanks in advance.

  2. #2

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Nobody?

  3. #3
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    Try:
    VB Code:
    1. Private Function HiWord(lParam As Long) As Long
    2.     HiWord = lParam \ &H10000 And &HFFFF&
    3. End Function
    4. Private Function LoWord(lParam As Long) As Long
    5.     LoWord = lParam And &HFFFF&
    6. End Function
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I think that you're going to find that this method very unreliable. Your program might process the message before your routine has a chance to handle it.
    Please rate my post.

  5. #5

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    This means even if i create a callback function for my app., i cannot gurantee its performance. I cant assure that it will
    process each and every message it is supposed to handle. Isn't
    it?
    Any suggestions?

  6. #6
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by abhid
    This means even if i create a callback function for my app., i cannot gurantee its performance. I cant assure that it will
    process each and every message it is supposed to handle. Isn't
    it?
    Pretty Much


    Any suggestions?
    Subclass your form.
    Please rate my post.

  7. #7

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by Shawn N
    [B Subclass your form. [/B]
    hmm...
    I have used subclassing technique only once in VB. can you show
    me?
    Any links or tutorials?

  8. #8
    Megatron
    Guest
    Here's a basic skeleton:

    Add to a Module
    VB Code:
    1. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    3. Public Const GWL_WNDPROC = (-4)
    4. Public WinProcOld As Long
    5.  
    6. Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    7.    
    8.     If wMsg = WM_MYMESSAGE Then
    9.  
    10.     End If
    11.    
    12.     WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    13. End Function
    14.  
    15. Sub SubClassWnd(hwnd As Long)
    16.     WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc)
    17. End Sub
    18.  
    19. Sub UnSubclassWnd(hwnd As Long)
    20.     SetWindowLong hwnd, GWL_WNDPROC, WinProcOld&
    21.     WinProcOld& = 0
    22. End Sub

    Add to your Form
    VB Code:
    1. Private Sub Form_Load()
    2.     SubClassWnd Me.hwnd
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     UnSubclassWnd Me.hwnd
    7. End Sub

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