首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

【100分】请(大侠)写系统热键弹出对话框解决办法

2013-01-05 
【100分】请(大侠)写系统热键弹出对话框代码注明如下:没有装RzTrayIcon,用系统自带的托盘类1)create事件如下

【100分】请(大侠)写系统热键弹出对话框

代码注明如下:
没有装RzTrayIcon,用系统自带的托盘类
1)create事件如下:
procedure TFrmKey.FormCreate(Sender: TObject);
begin
  //初始化功能键列表 F1---F12
  ComboBox1.Clear;
  ComboBox1.Items.Add('请选择功能热键');
  ComboBox1.Items.Add('F1');
  ComboBox1.Items.Add('F2');
  ComboBox1.Items.Add('F3');
  ComboBox1.Items.Add('F4');
  ComboBox1.Items.Add('F5');
  ComboBox1.Items.Add('F6');
  ComboBox1.Items.Add('F7');
  ComboBox1.Items.Add('F8');
  ComboBox1.Items.Add('F9');
  ComboBox1.Items.Add('F10');
  ComboBox1.Items.Add('F11');
  ComboBox1.Items.Add('F12');
  ComboBox1.ItemIndex:=0; //定义到F1上

  self.Position:=poDesktopCenter; //窗体 居中显示
end;
2)Bitbtn1 按扭  注册热键  事件如下:
procedure TFrmKey.BitBtn1Click(Sender: TObject);
begin
  _HotKey:=GlobalAddAtom('HotKey')-$C000;

  case ComboBox1.ItemIndex of
    1:
     begin
      Label1.Caption:='键盘输入检测快捷键  热键为:F1 ';
      RegisterHotKey(Handle,_HotKey,0,vk_F1);   {取出用户设定的热键,把vk_F2变一下即可}
      doNotifyIconData('add');
     end;
    2:
     begin
      Label1.Caption:='键盘输入检测快捷键  热键为:F2 ';
      RegisterHotKey(Handle,_HotKey,0,vk_F2);   {取出用户设定的热键,把vk_F2变一下即可}
      doNotifyIconData('add');
     end;
    3:
     begin
      Label1.Caption:='键盘输入检测快捷键  热键为:F3 ';
      RegisterHotKey(Handle,_HotKey,0,vk_F3);   {取出用户设定的热键,把vk_F2变一下即可}
      doNotifyIconData('add');
     end;
    4:
     begin
      Label1.Caption:='键盘输入检测快捷键  热键为:F4 ';
      RegisterHotKey(Handle,_HotKey,0,vk_F4);   {取出用户设定的热键,把vk_F2变一下即可}
      doNotifyIconData('add');
     end;
    5:
     begin


      RegisterHotKey(Handle,_HotKey,0,vk_F5);   {取出用户设定的热键,把vk_F2变一下即可}
      Label1.Caption:='键盘输入检测快捷键  热键为:F5 ';
      doNotifyIconData('add');
     end;
    6:
     begin
      Label1.Caption:='键盘输入检测快捷键  热键为:F6 ';
      RegisterHotKey(Handle,_HotKey,0,vk_F6);   {取出用户设定的热键,把vk_F2变一下即可}
      doNotifyIconData('add');
     end;
     //省略 6个,你们可知如何书写吗.............

  end;

end; 
3)Bitbtn2 注消热键 代码如下:
  UnRegisterHotKey(handle,_HotKey);//注消热键
4)修改事件
procedure TFrmKey.HotKey(var Msg:Tmessage);
begin
 { if ((Msg.LParamHi=vk_F1) or (Msg.LParamHi=vk_F2) or (Msg.LParamHi=vk_F3) or (Msg.LParamHi=vk_F4) or
      (Msg.LParamHi=vk_F5) or (Msg.LParamHi=vk_F6) or (Msg.LParamHi=vk_F7) or (Msg.LParamHi=vk_F8) or
      (Msg.LParamHi=vk_F9) or (Msg.LParamHi=vk_F10) or (Msg.LParamHi=vk_F11) or (Msg.LParamHi=vk_F12))  then
  begin  }
    if self.Visible then
    begin
      doNotifyIconData('del');
      self.Visible:=false;
    end
   else
    begin
      doNotifyIconData('add');
      self.Visible:=true;
    end;
  //end;
end;
5)托盘事件如下:
procedure doNotifyIconData(aType: String);
var
  lpData: PNotifyIconData; //引用单元  uses ShellApi;
begin
  lpData := new(PNotifyIconDataA);
  lpData.cbSize := 88;
  lpData.Wnd := FrmKey.Handle;
  lpData.hIcon := Application.Icon.Handle;
  lpData.uID :=0;
  lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
  if (aType = 'add') then
    Shell_NotifyIcon(NIM_ADD, lpData)
  else if (aType = 'del') then
    Shell_NotifyIcon(NIM_DELETE, lpData);
  dispose(lpData);
end;
[解决办法]
解决了,跟一个!

热点排行