Yeath 请进(急!急)(100分)

  • 主题发起人 主题发起人 大梦
  • 开始时间 开始时间

大梦

Unregistered / Unconfirmed
GUEST, unregistred user!
有win键按下时,弹出自己的窗口,屏蔽“开始菜单”。


1、钩子加载时正常。但无法卸载,关闭程序可卸载。
2、定义的消息不发送。
3、钩子处理(DLL)函数中加
MyMsg:=RegisterWindowMessage(GST_MESSAGE);
if MyMsg<>0 then
showmessage('成功')
else
showmessage('失败');
理应有按键就 showmessage('成功') 或 showmessage('失败'); 可是无反应。


 
代码贴在你原来 的贴子上了,看看吧!
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure WndProc(var Message: TMessage); override;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
var
wm_sock:integer;
hHandle:HWND;

function LowLevelKeyboardProc(nCode:integer;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;
type
KBDLLHOOKSTRUCT=record
vkCode:DWORD;
scanCode:DWORD;
flags:DWORD;
time:DWord;
dwExtraInfo:dword;
end;
var
fFlag:BOOL;
p:^KBDLLHOOKSTRUCT;
begin
result:=0;
fFlag := false;
p:=Pointer(LPARAM);
if (ncode=HC_ACTION) then
begin
case wparam of
WM_KEYDOWN,
WM_SYSKEYDOWN,
WM_KEYUP,
WM_SYSKEYUP:
fFlag :=(p.vkCode = VK_Lwin) or (p.vkCode = VK_Rwin)or (p.vkCode = VK_apps);
end;
end;
if fFlag = true then
begin
PostMessage(hHandle,WM_SOCK,0,0);
Result:=1;
end;
if ncode <> 0 then
Result := CallNextHookEX(0,ncode,wparam,lparam);
end;

function KeyBoardHook(nCode:integer;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;
begin

Result := CallNextHookEx(0,nCode,WParam,LParam);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
WH_KEYBOARD_LL=13;
begin
wm_sock := 0;
wm_sock := RegisterWindowMessage('wm_sock');
// showmessage(inttostr(wm_sock));
hHandle := Self.Handle;

setwindowshookexw(WH_KEYBOARD_LL,LowLevelKeyboardProc,hinstance,0);
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
if Message.Msg=WM_SOCK then
begin
showmessage('用户按下win键');
end;
inherited;
end;

end.
这是程序,自己看看吧,我是做成EXE的,成功运行.
 
结了吧!
 
to 大梦:
你做成dll当然不行了,触发不是事件。
 
先加分吧。上次对不住了。谢谢你们教我很多东西。
 
你直接在捕获到win按键后创建你的Form。
if fFlag = true then
begin
PostMessage(hHandle,WM_SOCK,0,0);
Result:=1;
end;
把上面的代码改成
  
if fFlag = true then
begin
    with tform2.create(application) do
begin
show;
end;
Result:=1;
end;

 
后退
顶部