CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

关于热键使用的问题?

楼主game_sage(游圣)2002-03-11 13:52:17 在 C++ Builder / 基础类 提问

如何才能注册了一个热键(如Ctrl+z),以后只要我的程序在运行,不管在干什么,只要一按热键,   就会弹出一个我的程序窗口 问题点数:40、回复次数:4Top

1 楼kingcaiyao(aking)回复于 2002-03-11 14:12:22 得分 40

use   API   function:  
   
  RegisterHotKey()  
  UnregisterHotKey()  
   
  please   see   SDK   help  
  Top

2 楼kingcaiyao(aking)回复于 2002-03-11 14:14:00 得分 0

you   may   write   RegisterHotKey()   in   WinMain   Function,so   you   may   use   shortcut(ctrl+z)   in   your   applicationTop

3 楼game_sage(游圣)回复于 2002-03-12 15:37:04 得分 0

这位大哥,可不可以写的详细一些呀??Top

4 楼kingcaiyao(aking)回复于 2002-03-12 15:49:44 得分 0

我在VC下写过一段代码,C++   BUILDER是一样的,我给你作参考.  
   
  #include   "stdafx.h"  
  #include   "HotKey.h"  
  #include   "HotKeyDlg.h"  
   
  #ifdef   _DEBUG  
  #define   new   DEBUG_NEW  
  #undef   THIS_FILE  
  static   char   THIS_FILE[]   =   __FILE__;  
  #endif  
  #define   VK_D   68  
   
  /////////////////////////////////////////////////////////////////////////////  
  //   CAboutDlg   dialog   used   for   App   About  
   
  class   CAboutDlg   :   public   CDialog  
  {  
  public:  
  CAboutDlg();  
   
  //   Dialog   Data  
  //{{AFX_DATA(CAboutDlg)  
  enum   {   IDD   =   IDD_ABOUTBOX   };  
  //}}AFX_DATA  
   
  //   ClassWizard   generated   virtual   function   overrides  
  //{{AFX_VIRTUAL(CAboutDlg)  
  protected:  
  virtual   void   DoDataExchange(CDataExchange*   pDX);         //   DDX/DDV   support  
  //}}AFX_VIRTUAL  
   
  //   Implementation  
  protected:  
  //{{AFX_MSG(CAboutDlg)  
   
  //}}AFX_MSG  
  DECLARE_MESSAGE_MAP()  
  };  
   
  CAboutDlg::CAboutDlg()   :   CDialog(CAboutDlg::IDD)  
  {  
  //{{AFX_DATA_INIT(CAboutDlg)  
  //}}AFX_DATA_INIT  
  }  
   
  void   CAboutDlg::DoDataExchange(CDataExchange*   pDX)  
  {  
  CDialog::DoDataExchange(pDX);  
  //{{AFX_DATA_MAP(CAboutDlg)  
  //}}AFX_DATA_MAP  
  }  
   
  BEGIN_MESSAGE_MAP(CAboutDlg,   CDialog)  
  //{{AFX_MSG_MAP(CAboutDlg)  
   
  //   No   message   handlers  
  //}}AFX_MSG_MAP  
  END_MESSAGE_MAP()  
   
  /////////////////////////////////////////////////////////////////////////////  
  //   CHotKeyDlg   dialog  
   
  CHotKeyDlg::CHotKeyDlg(CWnd*   pParent   /*=NULL*/)  
  :   CDialog(CHotKeyDlg::IDD,   pParent)  
  {  
  //{{AFX_DATA_INIT(CHotKeyDlg)  
  //   NOTE:   the   ClassWizard   will   add   member   initialization   here  
  //}}AFX_DATA_INIT  
  //   Note   that   LoadIcon   does   not   require   a   subsequent   DestroyIcon   in   Win32  
  m_hIcon   =   AfxGetApp()->LoadIcon(IDR_MAINFRAME);  
  }  
   
  void   CHotKeyDlg::DoDataExchange(CDataExchange*   pDX)  
  {  
  CDialog::DoDataExchange(pDX);  
  //{{AFX_DATA_MAP(CHotKeyDlg)  
  //   NOTE:   the   ClassWizard   will   add   DDX   and   DDV   calls   here  
  //}}AFX_DATA_MAP  
  }  
   
  BEGIN_MESSAGE_MAP(CHotKeyDlg,   CDialog)  
  //{{AFX_MSG_MAP(CHotKeyDlg)  
  ON_WM_SYSCOMMAND()  
  ON_WM_PAINT()  
  ON_WM_QUERYDRAGICON()  
  ON_BN_CLICKED(IDC_BUTTON1,   OnButton1)  
  ON_MESSAGE(WM_HOTKEY,OnHotKey)  
  //}}AFX_MSG_MAP  
  END_MESSAGE_MAP()  
   
  /////////////////////////////////////////////////////////////////////////////  
  //   CHotKeyDlg   message   handlers  
   
  BOOL   CHotKeyDlg::OnInitDialog()  
  {  
  CDialog::OnInitDialog();  
  if(!RegisterHotKey(GetSafeHwnd(),m_HotKeyID,MOD_ALT,VK_D))  
  {  
  AfxMessageBox("Register   hotkey   fail!!!");  
   
  }  
   
  //   Add   "About..."   menu   item   to   system   menu.  
   
  //   IDM_ABOUTBOX   must   be   in   the   system   command   range.  
  ASSERT((IDM_ABOUTBOX   &   0xFFF0)   ==   IDM_ABOUTBOX);  
  ASSERT(IDM_ABOUTBOX   <   0xF000);  
   
  CMenu*   pSysMenu   =   GetSystemMenu(FALSE);  
  if   (pSysMenu   !=   NULL)  
  {  
  CString   strAboutMenu;  
  strAboutMenu.LoadString(IDS_ABOUTBOX);  
  if   (!strAboutMenu.IsEmpty())  
  {  
  pSysMenu->AppendMenu(MF_SEPARATOR);  
  pSysMenu->AppendMenu(MF_STRING,   IDM_ABOUTBOX,   strAboutMenu);  
  }  
  }  
   
  //   Set   the   icon   for   this   dialog.     The   framework   does   this   automatically  
  //     when   the   application's   main   window   is   not   a   dialog  
  SetIcon(m_hIcon,   TRUE); //   Set   big   icon  
  SetIcon(m_hIcon,   FALSE); //   Set   small   icon  
   
  //   TODO:   Add   extra   initialization   here  
   
  return   TRUE;     //   return   TRUE     unless   you   set   the   focus   to   a   control  
  }  
   
  void   CHotKeyDlg::OnSysCommand(UINT   nID,   LPARAM   lParam)  
  {  
  if(nID==61458)  
  {  
   
  nID=0;  
  }  
  else  
  {  
  CDialog::OnSysCommand(nID,lParam);  
  }  
   
  }  
   
  //   If   you   add   a   minimize   button   to   your   dialog,   you   will   need   the   code   below  
  //     to   draw   the   icon.     For   MFC   applications   using   the   document/view   model,  
  //     this   is   automatically   done   for   you   by   the   framework.  
   
  void   CHotKeyDlg::OnPaint()    
  {  
  if   (IsIconic())  
  {  
  CPaintDC   dc(this);   //   device   context   for   painting  
   
  SendMessage(WM_ICONERASEBKGND,   (WPARAM)   dc.GetSafeHdc(),   0);  
   
  //   Center   icon   in   client   rectangle  
  int   cxIcon   =   GetSystemMetrics(SM_CXICON);  
  int   cyIcon   =   GetSystemMetrics(SM_CYICON);  
  CRect   rect;  
  GetClientRect(&rect);  
  int   x   =   (rect.Width()   -   cxIcon   +   1)   /   2;  
  int   y   =   (rect.Height()   -   cyIcon   +   1)   /   2;  
   
  //   Draw   the   icon  
  dc.DrawIcon(x,   y,   m_hIcon);  
  }  
  else  
  {  
  CDialog::OnPaint();  
  }  
  }  
   
  //   The   system   calls   this   to   obtain   the   cursor   to   display   while   the   user   drags  
  //     the   minimized   window.  
  HCURSOR   CHotKeyDlg::OnQueryDragIcon()  
  {  
  return   (HCURSOR)   m_hIcon;  
  }  
   
  void   CHotKeyDlg::OnButton1()    
  {  
   
  UnregisterHotKey(GetSafeHwnd(),m_HotKeyID);  
  EndDialog(IDOK);  
   
  //   TODO:   Add   your   control   notification   handler   code   here  
   
  }  
  //-----------------------------------------------------------------------------------  
   
  LONG   CHotKeyDlg::OnHotKey(WPARAM   wParam,LPARAM   lParam)  
  {  
  UINT   idHotKey=(UINT)wParam;  
  if(idHotKey==m_HotKeyID)  
  {  
  WinExec("c:\\pwin98\\calc.exe",SW_MAXIMIZE);  
  }  
  return   0;  
   
  }  
  Top

相关问题

  • 在DELPHI程序里使用热键
  • VB.NET中如何使用热键?
  • 怎样在delphi中使用系统热键?
  • 如何定义,使用一个全局热键(在键盘上)
  • 请教:如何使用键盘钩子屏蔽系统热键?
  • PCANYWHERE远程控制下,热键不能使用怎么办
  • 关于注册热键热键和使用键盘钩子的问题,有劳各位出个主意?
  • 怎样在窗口中使用热键ctrl+alt+del调用另一个窗体,屏蔽所有系统热键
  • 热键
  • 热键

关键词

  • virtual
  • 热键
  • caboutdlg
  • nid
  • dialog
  • icon
  • afx
  • lparam
  • applications
  • include

得分解答快速导航

  • 帖主:game_sage
  • kingcaiyao

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo