|
-
Apr 23rd, 2001, 10:39 AM
#1
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)?
-
Apr 23rd, 2001, 02:58 PM
#2
You mean block/filter out events??
-
Apr 23rd, 2001, 03:54 PM
#3
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.
-
Apr 24th, 2001, 10:03 AM
#4
Code:
Call SetParent (Command1.hWnd, GetDesktopWindow)
i think i wanna use SetWindowLong, but im unsure of the correct params.
-
Apr 24th, 2001, 02:52 PM
#5
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..
-
Apr 24th, 2001, 02:55 PM
#6
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.
-
Apr 24th, 2001, 03:07 PM
#7
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
-
Apr 24th, 2001, 03:16 PM
#8
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..
-
Apr 24th, 2001, 03:34 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|