Custom Hotkey for Winamp

Source: Internet
Author: User
Tags bool

Objective:

I like to set the Winamp in the tray area, but the Winamp does not provide hot keys to exhale, and I used to use the hotkey Oicq, so every time I want to change the song to use the mouse click always feel uncomfortable.

So germination of the idea of a hot key to it, the basic idea is to register a system-level hot key of course, the hot key can not be directly registered on the Winamp, so I registered a hotkey in a dialog box, and then through the Winamp handle will be Winamp display, and is displayed to the forefront. And the dialog is minimized when it is hidden, so that it does not occupy the taskbar, but also let people feel that the hot key is Winamp their own, the dialog box also with a hotkey to exhale.

Sample program Run effect diagram

Specific steps:

First create a dialog project, add an edit control to make it easier for users to add their favorite hotkeys, and the default in the example program is "CTRL + a key."

M_wap is a Winamp hotkey.

M_dlg is a dialog hotkey.

Use:: RegisterHotKey for registration

BOOL RegisterHotKey(
 HWND hWnd,     // 接收hotkey窗口
 int id,      // hotkey的id 范围是0x0000到0xBFFF
 UINT fsModifiers, // 可以是MOD_ALT MOD_CTRL MOD_WIN
 UINT vk      // 虚拟键值,就是m_Wap,m_Dlg的值
);

void CXXXDlg::OnOk()
{
  // TODO: Add your control notification handler code here
  UpdateData(TRUE);
  m_Wap.MakeUpper();//字母转化成大写
  m_Dlg.MakeUpper();
  if((!::RegisterHotKey(this->m_hWnd,0Xa002,MOD_CONTROL,(UINT)m_Wap[0]))
    &&(!::RegisterHotKey(this->m_hWnd,0Xa001,MOD_CONTROL,(UINT)m_Dlg[0])))

    AfxMessageBox("*^_^* 热键已经注册了 *^_^*");

}

Responding in PreTranslateMessage

BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
  // TODO: Add your specialized code here and/or call the base class
  if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa002)
  {
        //中文版
    HWND handle=FindWindowEx(NULL,NULL,NULL,"Winamp 播放清单编辑器");
        //英文版
    HWND handle2=FindWindowEx(NULL,NULL,NULL,"Winamp Playlist Editor");
    if(handle)
    {
      ::ShowWindow(handle,SW_SHOWNORMAL);
      ::SetForegroundWindow(handle);
    }
    if(handle2)
    {
      ::ShowWindow(handle2,SW_SHOWNORMAL);
        ::SetForegroundWindow(handle2);
    }
  }
  if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa001)
  {
    ::ShowWindow(this->m_hWnd,SW_SHOWNORMAL);
    ::SetForegroundWindow(this->m_hWnd);
  }
  return CDialog::PreTranslateMessage(pMsg);
}

At the end of the program, naturally write off the hotkey.

void CXXXDlg::OnClose()
{
  // TODO: Add your message handler code here and/or call default
  UnregisterHotKey(this->m_hWnd,0Xa001);
  UnregisterHotKey(this->m_hWnd,0Xa002);
  CDialog::OnClose();
}

The specific routines are visible in the source code provided in this article (win2k,vc6.0 Debugging Pass)

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.