Einzelnen Beitrag anzeigen

Benutzerbild von DataCool
DataCool

Registriert seit: 10. Feb 2003
Ort: Lingen
909 Beiträge
 
Delphi 10.3 Rio
 
#3

Re: Form-/Frame Create abfangen

  Alt 7. Mai 2009, 09:44
Hi,

ich möchte in der eigenen Anwendung mitbekommen, wann andere Forms oder Frames erzeugt(Created) werden.

Ich habe das ganze jetzt per Hook (WH_CALLWNDPROC) realisieren können.

Delphi-Quellcode:
function WndProcCallback(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
   cwps: TCWPStruct;
   tmpControl : TControl;
   tmpCustomForm : TCustomForm;
   tmpCustomFrame : TCustomFrame;
   sTmp : String;
begin
   case nCode < HC_ACTION of
      True:
         begin
            Result := CallNextHookEx(FWndProcHook, nCode, wParam, lParam);
         end;
      else begin
         CopyMemory(@cwps, Pointer(lParam), SizeOf(CWPSTRUCT));
         case cwps.message of
            WM_CREATE :
               begin
                  sTmp := 'WM_CREATE WP: '+inttostr(cwps.wParam)+' LP: '+inttostr(cwps.LParam)+' hwnd: '+inttostr(cwps.hwnd);
                  tmpControl := FindControl(cwps.hwnd);
                  if Assigned(tmpControl) then begin
                     sTmp := sTmp + tmpControl.ClassName;
                     if tmpControl is TCustomForm then begin
                        tmpCustomForm := TCustomForm(tmpControl);
                        frmMain.mem_Output.Lines.Insert(0,'Create of form: "'+tmpCustomForm.Name+'"');
                     end;
                     if tmpControl is TCustomFrame then begin
                        tmpCustomFrame := TCustomFrame(tmpControl);
                        frmMain.mem_Output.Lines.Insert(0,'Create of frame: "'+tmpCustomFrame.Name+'"');
                     end;
                  end
                  else
                     sTmp := sTmp + 'Control to hwnd: '+inttostr(cwps.hwnd)+' not found';
                  frmMain.mem_Output.lines.Insert(0,sTmp);
               end;
            end;               
         end;
      end;

      Result := CallNextHookEx(fWndProcHook, nCode, wParam, lParam);
         
   end;

end;
Aber eigentlich hätte es doch über die WndProc der Main-Form gehen müssen, oder nicht ?

Gruß Data
Der Horizont vieler Menschen ist ein Kreis mit Radius Null, und das nennen sie ihren Standpunkt.
  Mit Zitat antworten Zitat