NgThanhTung
07-08-2001, 07:17 PM
Hi,
Please gime examples of using the API function SetParent.
Thanks,
Tung
Please gime examples of using the API function SetParent.
Thanks,
Tung
How to use SetParent?NgThanhTung 07-08-2001, 07:17 PM Hi, Please gime examples of using the API function SetParent. Thanks, Tung JDT 07-09-2001, 04:04 PM Here is an example that I copied out of the API guide. You can get the API Guide at <A HREF = "www.AllApi.Net">AllApi.Net</A> <pre><font color=blue>Option Explicit</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> FindWindow <font color=blue>Lib</font color=blue> "user32" _ <font color=blue>Alias</font color=blue> "FindWindowA" ( _ <font color=blue>ByVal</font color=blue> lpClassName <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, _ <font color=blue>ByVal</font color=blue> lpWindowName <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> GetParent <font color=blue>Lib</font color=blue> "user32" (<font color=blue>ByVal</font color=blue> hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> SetParent <font color=blue>Lib</font color=blue> "user32" ( _ <font color=blue>ByVal</font color=blue> hWndChild <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, <font color=blue>ByVal</font color=blue> hWndNewParent <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> GetWindowThreadProcessId <font color=blue>Lib</font color=blue> "user32" ( _ <font color=blue>ByVal</font color=blue> hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, lpdwProcessId <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> GetWindow <font color=blue>Lib</font color=blue> "user32" ( _ <font color=blue>ByVal</font color=blue> hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, <font color=blue>ByVal</font color=blue> wCmd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> LockWindowUpdate <font color=blue>Lib</font color=blue> "user32" ( _ <font color=blue>ByVal</font color=blue> hwndLock <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> GetDesktopWindow <font color=blue>Lib</font color=blue> "user32" () <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> DestroyWindow <font color=blue>Lib</font color=blue> "user32" (<font color=blue>ByVal</font color=blue> hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> TerminateProcess <font color=blue>Lib</font color=blue> "kernel32" ( _ <font color=blue>ByVal</font color=blue> hProcess <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, <font color=blue>ByVal</font color=blue> uExitCode <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> GetCurrentProcess <font color=blue>Lib</font color=blue> "kernel32" () <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Declare</font color=blue> <font color=blue>Function</font color=blue> Putfocus <font color=blue>Lib</font color=blue> "user32" _ <font color=blue>Alias</font color=blue> "SetFocus" (<font color=blue>ByVal</font color=blue> hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Const</font color=blue> GW_HWNDNEXT = 2 <font color=blue>Dim</font color=blue> mWnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Function</font color=blue> InstanceToWnd(<font color=blue>ByVal</font color=blue> target_pid <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>) <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=blue>Dim</font color=blue> test_hwnd <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, test_pid <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>, test_thread_id <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=green>'Find the first window</font color=green> test_hwnd = FindWindow(<font color=blue>ByVal</font color=blue> 0&, <font color=blue>ByVal</font color=blue> 0&) <font color=blue>Do</font color=blue> <font color=blue>While</font color=blue> test_hwnd <> 0 <font color=green>'Check if the window isn't a child</font color=green> <font color=blue>If</font color=blue> GetParent(test_hwnd) = 0 <font color=blue>Then</font color=blue> <font color=green>'Get the window's thread</font color=green> test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) <font color=blue>If</font color=blue> test_pid = target_pid <font color=blue>Then</font color=blue> InstanceToWnd = test_hwnd <font color=blue>Exit</font color=blue> <font color=blue>Do</font color=blue> <font color=blue>End</font color=blue> <font color=blue>If</font color=blue> <font color=blue>End</font color=blue> <font color=blue>If</font color=blue> <font color=green>'retrieve the next window</font color=green> test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT) <font color=blue>Loop</font color=blue> <font color=blue>End</font color=blue> <font color=blue>Function</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Sub</font color=blue> Form_Load() <font color=green>'KPD-Team 1999</font color=green> <font color=green>'URL: http://www.allapi.net/</font color=green> <font color=green>'E-Mail: KPDTeam@Allapi.net</font color=green> <font color=blue>Dim</font color=blue> Pid <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue> <font color=green>'Lock the window update</font color=green> LockWindowUpdate GetDesktopWindow <font color=green>'Execute notepad.Exe</font color=green> Pid = Shell("c:\windows\notepad.exe", vbNormalFocus) <font color=blue>If</font color=blue> Pid = 0 <font color=blue>Then</font color=blue> MsgBox "Error starting the app" <font color=green>'retrieve the handle of the window</font color=green> mWnd = InstanceToWnd(Pid) <font color=green>'Set the notepad's parent</font color=green> SetParent mWnd, Me.hwnd <font color=green>'Put the focus on notepad</font color=green> Putfocus mWnd <font color=green>'Unlock windowupdate</font color=green> LockWindowUpdate <font color=blue>False</font color=blue> <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue> <font color=blue>Private</font color=blue> <font color=blue>Sub</font color=blue> Form_Unload(Cancel <font color=blue>As</font color=blue> <font color=blue>Integer</font color=blue>) <font color=green>'Unload notepad</font color=green> DestroyWindow mWnd <font color=green>'End this program</font color=green> TerminateProcess GetCurrentProcess, 0 <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue> </pre> JDT |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum