Results 1 to 9 of 9

Thread: Move the Event???

  1. #1
    spetnik
    Guest
    I am taking a control and, via the SetParent() function, I am placing it on the desktop. Now, how can I assign an event to that control (once it moves, its no longer responds to events)?

  2. #2
    Megatron
    Guest
    You mean block/filter out events??

  3. #3
    Tygur
    Guest
    Can I see the code you are using to put the control onto the desktop? I just tried putting a textbox onto the desktop and the events still work fine.

  4. #4
    spetnik
    Guest
    Code:
    Call SetParent (Command1.hWnd, GetDesktopWindow)
    i think i wanna use SetWindowLong, but im unsure of the correct params.

  5. #5
    Tygur
    Guest
    You don't want to use SetWindowLong to set the window's parent. SetParent is the right API to use.

    Try this:
    SetParent Command1.hwnd, FindWindow("Progman", vbNullString)

    This is the declare for the FindWindow API:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


    The only problem is it may not work right when someone has some alternate shell installed..

  6. #6
    spetnik
    Guest
    No, u dont understand. I realize that i should use setparent. My concern was whether I would need to use SetWindowLong to subclass the command button's event with an event in my project.

  7. #7
    Megatron
    Guest
    Add to a Module
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    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
    Const GWL_WNDPROC = (-4)
    Private Const WM_LBUTTONUP = &H202
    
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If wMsg = WM_LBUTTONUP Then MsgBox "PresseD"
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Add to a Form with 2 CommandButtons.
    Code:
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private Sub Command1_Click()
        SetParent Command2.hwnd, GetDesktopWindow
    End Sub
    
    Private Sub Form_Load()
        SubClassWnd Command2.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd Command2.hwnd
    End Sub

  8. #8
    Tygur
    Guest
    Oh, ok.
    Try my code. If you still don't get the events, you can try Megatron's code to subclass. I don't think you need to subclass the control, though.

    And if you have trouble getting the events, I doubt subclassing will help. But I could be wrong..

  9. #9
    spetnik
    Guest
    THANK YOU Megatron! IT WORKED!!!!!!!!!

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