如题,我在
form1.Create中注册快捷键
begin
  atomShift:=globaladdatom('hot key Shift');
  RegisterHotKey(handle,atomShift,0,vk_Shift);
end;
工作都挺正常的。
但是我现在程序没有窗体,我只能在一个类中写:
constructor TMyClass.Create;
begin
  atomShift:=globaladdatom('hot key Shift');
  RegisterHotKey(handle{没有handle啊,参数我输入什么?},atomShift,0,vk_Shift);
end;RegisterHotKey的第一个参数就不能用handle了。
我尝试用Application.handle,但是快捷键就是呼不出来。
我发现form1.handle和Application.handle取值并不相同。那我参数应该怎么写才对呢?
请各位帮忙,多谢了!

解决方案 »

  1.   

    type
      TMyClass = class
      private
        FHandle: THandle;
        FAtomShift: TATOM;
        procedure WndMethod(var Message: TMessage);
      public
        constructor Create;
        destructor Destory;
      end;implementationconstructor TMyClass.Create;
    begin
      FHandle := AllocateHWnd(WndMethod);
      FAtomShift := GlobalAddAtom('hot key Shift');
      RegisterHotKey(FHandle, FAtomShift, MOD_SHIFT, 0);
    end;destructor TMyClass.Destory;
    begin
      GlobalDeleteAtom(FAtomShift);
      DeallocateHwnd(FHandle);
    end;procedure TMyClass.WndMethod(var Message: TMessage);
    begin
      if Message.Msg = WM_HOTKEY then
      begin
        if Message.WParam = FAtomShift then
        begin
          ShowMessage('ok');
        end;
      end;
    end;