A.A.Z. писал(а):GSerg, когда переведешь, скажи, через что ты получил то, что переводишь на VB!
Option Explicit
Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function GetDlgItem Lib "user32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Sub SetLastError Lib "kernel32.dll" (ByVal dwErrCode As Long)
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_WNDPROC As Long = -4
Private Const WH_CALLWNDPROCRET As Long = 12
Private Type InternalInfo
hWndTray As Long
hHook As Long
End Type
Private Type CWPRETSTRUCT
lResult As Long
lParam As Long
wParam As Long
message As Long
hWnd As Long
End Type
Private v413578 As InternalInfo
Private v4146BC As Long, v4146B0 As Long, v4146B4 As Long, v4146AC As Long, v4144B4 As Long, v4146C0 As Long, v4146B8 As Long
'v413578 - указатель на структуру InternalInfo. Я убрал один уровень косвенности.
'v4144B4 - то, что даётся хуку в качестве hModule
'v4146B0 - hWnd Shell_TrayWnd
'v4146B4 - ThreadID часиков
'v4146AC - hWnd часиков
'v4146B8 - hWnd окна TChameleonClock
'v4146BC - old clock callback address
'v4146C0 - old tray callback address
' 4129F8 - hook callback address (-> addressof CallWndProcRet)
' 4126E8 - new clock callback address (-> addressof ClockCallback)
' 412384 - new tray callback address (-> addressof TrayCallback)
Public Function SetHook() As Long
v4146AC = GetClock
v4146B0 = FindWindow("Shell_TrayWnd", vbNullString)
If v4146AC Then v4146B4 = GetWindowThreadProcessId(v4146B0, ByVal 0&)
v413578.hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, &H4129F8, v4144B4, v4146B4) '<- !!!
SetHook = v413578.hHook
End Function
Private Function CallWndProcRet(ByVal ncode As Long, ByVal wParam As Long, lParam As CWPRETSTRUCT) As Long
If ncode < 0 Then
'CallWndProcRet = CallNextHookEx(inf.hHook, ncode, wParam, lParam)
'Они почему-то возвращают 0...
'Это против рекомендаций мелкософта, но я менять не стал.
CallNextHookEx inf.hHook, ncode, wParam, lParam
CallWndProcRet = 0
Else
If v413578.hWndTray = 0 Then
CallWndProcRet = 0
Else
If v4146BC <> 0 Then 'если уже поставили сабклассинг, то выходим
CallWndProcRet = 0
Else
Select Case lParam.lResult 'Какого фига они сравнивают hWnd c lResult???
Case v4146B0, v4146AC
v4146AC = GetClock
v4146B0 = FindWindow("Shell_TrayWnd", vbNullString)
SetLastError 0
v4146BC = GetWindowLong(v4146AC, GWL_WNDPROC)
SetWindowLong v4146AC, GWL_WNDPROC, &H4126E8 '<- !!!
v4146C0 = GetWindowLong(v4146B0, GWL_WNDPROC)
SetWindowLong v4146B0, GWL_WNDPROC, &H412384 '<- !!!
v4146B8 = FindWindow("TChameleonClock", vbNullString) 'да, на дельфи писан...
End Select
CallWndProcRet = 0
End If
End If
End If
End Function
Private Function ClockCallback(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
End Function
Private Function TrayCallback(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
End Function
Private Function GetClock() As Long
If v4146B0 Then GetClock = GetDlgItem(GetDlgItem(v4146B0, &H12F&), &H12F&)
End Function
GSerg писал(а):Хотя день рожденья де-факто начался...
GSerg писал(а):Хотя день рожденья де-факто начался...
Здорово, поздравляю! А у меня 12го былGSerg писал(а):Хотя день рожденья де-факто начался...
Private hInst As Long, hHook As Long, prevproc As Long, hw As Long
Public Function DllMain(ByVal hInstDll As Long, ByVal fdwReason As Long, ByVal lpvReserved As Long) As Long
'TODO:
'Поместите здесь код инициализации библиотеки.
Select Case fdwReason
Case DLL_PROCESS_ATTACH
'
DllMain = 1
Case DLL_PROCESS_DETACH
'
Case DLL_THREAD_ATTACH
'
Case DLL_THREAD_DETACH
'
End Select
hInst = hInstDll
End Function
Private Function SetHook() As Long
If hHook = 0 Then
hw = GetDlgItem(GetDlgItem(FindWindow("Shell_TrayWnd", vbNullString), &H12F&), &H12F&)
If hw Then
hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, AddressOf CallWndProcRet, hInst, GetWindowThreadProcessId(hw, ByVal 0&))
If hHook Then SetHook = 1
End If
End If
End Function
Private Function RemoveHook() As Long
If prevproc Then SetWindowLong hw, GWL_WNDPROC, prevproc
If hHook Then UnhookWindowsHookEx hHook
End Function
Public Function ClockCallback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_USER_PLUS_100 Then ClockCallback = &H300060 Else ClockCallback = CallWindowProc(prevproc, hw, uMsg, wParam, lParam)
End Function
Public Function CallWndProcRet(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode >= 0 Then
If prevproc = 0 Then
hw = GetDlgItem(GetDlgItem(FindWindow("Shell_TrayWnd", vbNullString), &H12F&), &H12F&)
prevproc = SetWindowLong(hw, GWL_WNDPROC, AddressOf ClockCallback)
End If
End If
CallWndProcRet = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
library Project1;
uses windows;
const WM_USER_PLUS_100:cardinal=$464;
var prevproc:pointer; hh:HHOOK;
function ClockCallback(hW:HWND; uMsg:cardinal; wPar:WPARAM; lPar:LPARAM):integer;stdcall;
begin
if umsg=WM_USER_PLUS_100 then result:=$00300060 else result:=callwindowproc(prevproc,hw,umsg,wpar,lpar);
end;
function HookCallback(nCode,wParam,lParam:integer):integer;stdcall;
begin
if ncode>=0 then begin
if prevproc=nil then prevproc:=pointer(setwindowlong(getdlgitem(getdlgitem(findwindow('Shell_TrayWnd', nil),$12f),$12f),gwl_wndproc,integer(@ClockCallback)));
end;
result:=CallNextHookEx(hh, nCode, wparam,lparam);
end;
function SetHook:integer;stdcall;
begin
hh:=SetWindowsHookEx(WH_CALLWNDPROCRET,@HookCallback,hInstance,GetWindowThreadProcessId(getdlgitem(getdlgitem(findwindow('Shell_TrayWnd', nil),$12f),$12f),nil));
result:=integer(hh);
end;
exports SetHook;
begin
end.
Сейчас этот форум просматривают: AhrefsBot, Yandex-бот и гости: 11