看到有些朋友在找Delphi的MU窗口化代码 现在把它提供给大家 希望共同进步 ^_^
也希望有研究MU的朋友可以加我QQ:80848088 加时注名:MU Delphi 谢谢!
=========================================================================unit Hook;interfaceuses Windows, Messages, Dialogs, Sysutils;var
bs:longint;
OldHook: HHOOK;
WinFind: Integer;
MuProcId: Cardinal;
OldProc: FARPROC;
Style: Longint;
swl: longint;function SetHook():bool;export;
function HookProc(iCode:Integer;wParam:WPARAM;lParam:LPARAM):
LRESULT; stdcall;
function UnHook:bool;export;
function WinMu(hwnd:HWND):bool;export;
function MyProc(Hwnd,Msg,wParam,lParam:longint):integer; stdcall;
implementation//安装HOOK
function SetHook():bool;export;
begin
result:=false;
hInstance:=hInstance;WinFind:=findwindow(nil,'mu');
MuProcId := GetWindowThreadProcessId(WinFind,nil);
OldHook := SetWindowsHookEx(WH_Keyboard,HookProc,HInstance,0);
if longint(oldhook)=0 then
showmessage ('安装钩子失败!');
//unhook();
exit;
result := OldHook<>0;
end;//HOOK回调函数
function HookProc(iCode:Integer;wParam:WPARAM;lParam:LPARAM):
LRESULT; stdcall;
begin
winfind:=findwindow(nil,'mu');
WinMu(winfind);
if iCode < 0 then
CallNextHookEx(OldHook, iCode, wParam, lParam);
end;//卸载HOOK
function UnHook:bool;export;
begin
UnhookWindowshookEx(OldHook);
OldHook:=0;
exit;
end;//窗口化MU
function WinMu(hwnd:HWND):bool;export;
begin
if bs=1 then
exit;
style:=getwindowlong(hwnd,GWL_STYLE);
style:=WS_CAPTION;
setwindowlong(hwnd,GWL_STYLE,style);showwindow(hwnd,SW_SHOWNORMAL);oldproc:=FARPROC(getwindowlong(hwnd,GWL_WNDPROC));
setwindowlong(hwnd,GWL_WNDPROC,longint(@MyProc));
bs:=1;
end;//子类处理
function MyProc(Hwnd,Msg,wParam,lParam:longint):LRESULT; stdcall;
begin
case Msg of
WM_ACTIVATEAPP:result:=0;
WM_ACTIVATE:result:=0;
end;
CallWindowProc(hWnd,Msg,wParam,lParam);
end;
end.
=========================================================================

解决方案 »

  1.   

    好像CallWindowProc有5个参数呀,在Delphi7中不能通过调试
      

  2.   

    我也不会,但找到点资料,大家看看能不能改得更好
    Unit
    Windows.PasSyntax
    CallWindowProc(
    lpPrevWndFunc: TFNWndProc; {a pointer to the previous window procedure}
    hWnd: HWND; {a handle to a window}
    Msg: UINT; {the identifier of the message to send}
    wParam: WPARAM; {a 32 bit message specific value}
    lParam: LPARAM {a 32 bit message specific value}
    ): LRESULT; {returns a message specific return value}Description
    This function passes the specified message and its associated parameters to the window procedure pointed to by the lpPrevWndFunc parameter. An application must use this function in the window procedure of a subclassed window to pass any unhandled messages to the previous window procedure.Parameters
    lpPrevWndFunc: A pointer to the previous window procedure of the subclassed window. This value is returned from the SetClassLong or SetWindowLong functions when a window is subclassed, or by calling the GetClassLong or GetWindowLong functions with the appropriate index value to retrieve a pointer to the window procedure.hWnd: A handle to the window associated with the window procedure pointed to by the lpPrevWndFunc parameter.Msg: The message identifier to send to the window procedure.wParam: A 32 bit value dependent on the message being sent.lParam: A 32 bit value dependent on the message being sent.Return Value
    The value returned from this function specifies the result of the message processing and is dependent on the message sent.The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
    ----------------------------------
    下面是例子:
    This application sends a message:{Whoops! The BroadcastSystemMessage function is linked in incorrectly, so
     we must explicitly link in the correct function}
    function BroadcastSystemMessage; external user32 name 'BroadcastSystemMessage';procedure TForm1.Button1Click(Sender: TObject);
    var
      Recipients: DWORD;  // holds the recipient flags
    begin
      {set the recipients to all applications}  Recipients := BSM_APPLICATIONS;  {send the user defined message to all applications on the system by
       posting it to their message queues}
      BroadcastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE, @Recipients,
                             UserMessage, 0, 0);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      {register a user defined message}
      UserMessage := RegisterWindowMessage('CallWindowProc Test Message');end;and this application receives the message:{the prototype for the new window procedure}
      function NewWindowProc(TheWindow: HWND; Msg: Integer; wParam: WPARAM;
                             lParam: LPARAM): Longint; stdcall;var
      Form1: TForm1;
      UserMessage: UINT;         // holds a user defined message identifier
      OldWindowProc: TFNWndProc; // holds a pointer to the previous window procedure
    implementationfunction NewWindowProc(TheWindow: HWND; Msg: Integer; wParam: WPARAM; lParam: LPARAM): Longint;
    var
      iLoop: Integer;         // a general loop counter
    begin
      {if the user defined message has been received...}
      if Msg=UserMessage then
      begin
        {...turn on some user interface elements}
        Form1.ProgressBar1.Visible := TRUE;
        Form1.Label2.Visible := TRUE;    Form1.Repaint;    {animate the progress bar for a short period of time}
        for iLoop := 0 to 100 do
        begin
          Form1.ProgressBar1.Position := iLoop;
          Sleep(10);
        end;    {turn off the user interface elements}
        Form1.ProgressBar1.Visible := FALSE;
        Form1.Label2.Visible := FALSE;    {the message was handled, so return a one}
        Result := 1;
      end
      else    {any other message must be passed to the previous window procedure}
        Result := CallWindowProc(OldWindowProc, TheWindow, Msg, wParam, lParam);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      {register a user defined message}
      UserMessage := RegisterWindowMessage('CallWindowProc Test Message');  {subclass this window.  replace the window procedure with one of
       ours.  this window procedure will receive messages before the   previous one, allowing us to intercept and process any message
       before the rest of the application ever sees it.}
      OldWindowProc := TFNWndProc(SetWindowLong(Form1.Handle, GWL_WNDPROC,
                                  Longint(@NewWindowProc)));
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      {reset the window procedure to the previous one}
      SetWindowLong(Form1.Handle, GWL_WNDPROC, Longint(OldWindowProc));
    end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
      

  3.   

    现在还有用吗?0.97D下面,注入一个DLL,它就出错,不把NP去掉,窗口化是一辈子都不会成功的
      

  4.   

    ~~~我已经把NP给弄掉了~~~~需要的加我QQ
    359408897   -->    老刀
    顺便教教我DELPHI~~~嘎嘎~~~~~~
      

  5.   

    那篇有点小问题
    过几天我贴个98D通过的代码
    还是Delphi版   谢谢