Just now I do approx., about what you asked.
In my app something another situation, but methods, which I used could be useful to solve a discussion question.
To demonstrate this technique I modified my hook sample (which doesn't exist in real app).
Could be problems exactly with this code, but looking to living app, can say that all questions have a decision.
If you will start under 9x, probably (I didn't test) you will need to add SetParent CaptWnd, 0 before exit (as I remember living app).
So, DLL:
Code:
#Compile Dll "Hook.Dll" #Register None #Dim All #Include "Win32Api.Inc" $TrayWndNm = "Any unique name" %NotifyId = %WM_USER + 401 Global hHook As Long, hInstDLL As Long Function LibMain(ByVal hInstance As Long, ByVal fwdReason As Long, _ ByVal lpvReserved As Long) Export As Long Select Case fwdReason Case %DLL_PROCESS_ATTACH: hInstDLL = hInstance: LibMain = 1 Case %DLL_PROCESS_DETACH: LibMain = 1 End Select End Function Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) Export As Long Static hDlg As Long, NotFirstTime As Long Function = CallNextHookEx(ByVal hHook, ByVal nCode, ByVal wParam, ByVal lParam) If hDlg = 0 Then hDlg = FindWindow("", $TrayWndNm) If IsWindow(hDlg) = %False Then FreeLibrary hInstDll ElseIf (nCode = %HCBT_ACTIVATE) And (wParam <> hDlg) Then If IsFalse(NotFirstTime) Then NotFirstTime = %True Local pt As POINTAPI, hRgn As Long, rcW As RECT, rcC As RECT GetWindowRect wParam, rcW GetClientRect wParam, rcC ClientToScreen wParam, pt pt.x = pt.x - rcW.nLeft pt.y = pt.y - rcW.nTop hRgn = CreateRectRgn(pt.x, pt.y, pt.x + rcC.nRight, pt.y + rcC.nBottom) SetWindowRgn wParam, hRgn, %True PostMessage hDlg, %NotifyId, wParam, 0 End If End If End Function Function SetHookWindow Alias "SetHookWindow" (hWnd As Long) Export As Long hHook = SetWindowsHookEx (%WH_CBT, CodePtr(HookProc), ByVal hInstDLL, ByVal 0) End Function Function UnHookWindow Alias "UnHookWindow" Export As Long UnhookWindowsHookEx hHook End Function
Code:
#Compile Exe #Dim All #Register None #Include "Win32Api.Inc" $TrayWndNm = "Any unique name" %NotifyId = %WM_USER + 401 Declare Function SetHookWindow Lib "Hook.Dll" Alias "SetHookWindow" (hWnd As Long) As Long Declare Function UnHookWindow Lib "Hook.Dll" Alias "UnHookWindow" As Long CallBack Function DlgProc Static CaptWnd As Long Select Case CbMsg Case %WM_INITDIALOG SetHookWindow CbHndl Dim i As Long i = Shell ("notepad.exe", 1) Case %WM_SYSCOMMAND If CbWparam = %SC_CLOSE Then DestroyWindow CaptWnd Case %NotifyId CaptWnd = CbWparam UnHookWindow SetParent CaptWnd, CbHndl ShowWindow CbHndl, %SW_SHOW Function = 1: Exit Function End Select End Function Function PbMain Local hDlg As Long Dialog New 0, $TrayWndNm, , , 200, 200, _ %WS_CAPTION Or %WS_SYSMENU Or %WS_THICKFRAME Or %WS_CLIPCHILDREN Or %WS_CLIPSIBLINGS Or _ %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX, %WS_EX_TOPMOST To hdlg ShowWindow hDlg, %SW_MAXIMIZE Dialog Show Modal hDlg Call DlgProc End Function
E-MAIL: [email protected]
Leave a comment: