Thema: Delphi WndProc der Windows Uhr

Einzelnen Beitrag anzeigen

core

Registriert seit: 26. Dez 2003
Ort: Wadgassen
29 Beiträge
 
#1

WndProc der Windows Uhr

  Alt 6. Jun 2007, 19:36
Hallo,

hab mir den Quellcode zu TClockLight angeschaut.
Nun wollte ich das WndProc der Uhr folgendermaßen ableiten:

Delphi-Quellcode:
library ClockHook;

var
  g_hhook: THandle;
  hwndTaskbar, hwndTray, g_hwndClock: hwnd;
  idThread: dword;

  g_bInitClock: boolean = false;

  g_oldWndProc, g_hInst: THandle;


procedure RefreshRebar(myHwnd: hwnd);
var
  hhwnd: hwnd;
begin
  if myHwnd > 0 then
  begin
    InvalidateRect(myHwnd, nil, TRUE);
    hhwnd := GetWindow(myHwnd, GW_CHILD);
    while hhwnd > 0 do
    begin
      InvalidateRect(hhwnd, nil, TRUE);
      hhwnd := GetWindow(hhwnd, GW_HWNDNEXT);
    end;
  end;
end;

procedure RefreshTaskbar(myHwnd: hwnd);
var
  hwndTaskbar, hwndRebar, hwndTray, hwndStartButton: hwnd;
begin
  hwndTray := GetParent(myHwnd);
  hwndTaskbar := GetParent(hwndTray);
  hwndRebar := FindWindowEx(hwndTaskbar, 0, 'ReBarWindow32', nil);
  hwndStartButton := FindWindowEx(hwndTaskbar, 0, 'Button', nil);

  InvalidateRect(hwndStartButton, nil, TRUE);
  InvalidateRect(hwndTray, nil, TRUE);
  PostMessage(hwndTray, WM_SIZE, SIZE_RESTORED, 0);

  RefreshRebar(hwndRebar);
  PostMessage(hwndRebar, WM_SIZE, SIZE_RESTORED, 0);
  InvalidateRect(hwndTaskbar, nil, TRUE);
  PostMessage(hwndTaskbar, WM_SIZE, SIZE_RESTORED, 0);
end;

function WndProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam): lresult; stdcall;
begin
  case uMsg of
    WM_LBUTTONDOWN: MessageBoxA(0, 'Left mouse button', 'Test', 0);
  end;

  result := CallWindowProc(@g_oldWndProc, hWnd, uMsg, wParam, lParam);
end;

procedure InitClock(myHwnd: hwnd);
begin
  if g_bInitClock then exit;
  g_bInitClock := true;

  g_oldWndProc := GetWindowLong(myHwnd, GWL_WNDPROC);
  SetWindowLong(myHwnd, GWL_WNDPROC, LongInt(@WndProc));
  RefreshTaskbar(myHwnd);
end;

function CallWndProc(ncode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
  pcwps: PCWPSTRUCT;
begin
  pcwps := PCWPSTRUCT(lParam);

  if (ncode = HC_ACTION) then
  begin
    if (not g_bInitClock) and (pcwps.hwnd = g_hwndClock) then
      InitClock(pcwps.hwnd);
  end;

  result := CallNextHookEx(g_hhook, ncode, wParam, lParam);
end;

function StartHook(): boolean; stdcall;
begin
  g_hInst := GetModuleHandle('ClockHook.dll');

  hwndTaskbar := FindWindow('Shell_TrayWnd', nil);
  hwndTray := FindWindowEx(hwndTaskbar, 0, 'TrayNotifyWnd', nil);
  g_hwndClock := FindWindowEx(hwndTray, 0, 'TrayClockWClass', nil);
  idThread := GetWindowThreadProcessId(hwndTaskbar, nil);
  
  g_hhook := SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, g_hInst, idThread);
  
  PostMessage(hwndTaskbar, WM_SIZE, SIZE_RESTORED, 0);
  
  result := true;
end;

function StopHook(): boolean; stdcall;
begin
  SetWindowLong(killhwnd, GWL_WNDPROC, g_oldWndProc);
  g_oldWndProc := 0;
  RefreshTaskbar(killhwnd);

  result := UnhookWindowsHookEx(g_hhook);
  g_hhook := 0;
end;

exports
  StartHook,
  StopHook;
          
begin
end.
Leider muss ein Fehler in der "CallWndProc" Funktion vorhanden sein!?
"pcwps.hwnd = g_hwndClock" führt nicht zum Erfolg. Das Hwnd der Uhr wird nicht wieder gefunden...
Wo ist mein Fehler. Habe schon einiges probiert und mir den Originalen C-Quellcode etliche male angeschaut, kann aber nichts finden

Vielleicht findet ja einer von euch den Fehler ...

mfg
  Mit Zitat antworten Zitat