📄 keysounddlg.cpp
字号:
// KeySoundDlg.cpp : implementation file
//
#include "stdafx.h"
#include "KeySound.h"
#include "KeySoundDlg.h"
#include "mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 最小化窗口的参数
#define WM_NC 1001
#define IDC_NC 1002
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CWBButton m_ABOUTQUIT;
//}}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 void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}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)
DDX_Control(pDX, IDOK, m_ABOUTQUIT);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_DRAWITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeySoundDlg dialog
CKeySoundDlg::CKeySoundDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKeySoundDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CKeySoundDlg)
// 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 CKeySoundDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeySoundDlg)
DDX_Control(pDX, IDC_ABOUT, m_ABOUT);
DDX_Control(pDX, ID_OK, m_OK);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKeySoundDlg, CDialog)
//{{AFX_MSG_MAP(CKeySoundDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_OK, OnOk)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
ON_COMMAND(ID_MENU_QUIT, OnMenuQuit)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_NC,OnNc) //有这句才能响应鼠标消息
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeySoundDlg message handlers
BOOL CKeySoundDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//阻止程序反复驻留内存
CreateMutex(NULL, FALSE, "KeySound");
if(GetLastError()==ERROR_ALREADY_EXISTS)
OnOK();
// 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
//读取DLL
static HINSTANCE hinstDLL;
typedef BOOL (CALLBACK *inshook)();
inshook instkbhook;
if(hinstDLL=LoadLibrary((LPCTSTR)"hodll.dll"))
{
instkbhook=(inshook)GetProcAddress(hinstDLL, "installhook");
instkbhook();
}
//设置系统菜单
CMenu *pMenu=GetSystemMenu(FALSE);
pMenu->EnableMenuItem(SC_RESTORE ,MF_BYCOMMAND | MF_GRAYED);
pMenu->EnableMenuItem(SC_SIZE ,MF_BYCOMMAND | MF_GRAYED);
pMenu->EnableMenuItem(SC_MAXIMIZE ,MF_BYCOMMAND | MF_GRAYED);
//位图按钮
m_OK.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_ABOUT.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
return TRUE; // return TRUE unless you set the focus to a control
}
void CKeySoundDlg::OnMini()
{
NOTIFYICONDATA nc;
nc.cbSize=sizeof(NOTIFYICONDATA);
nc.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
nc.hWnd=m_hWnd;
lstrcpy(nc.szTip,"KeySound");
nc.uCallbackMessage=WM_NC;
nc.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID=IDC_NC;
Shell_NotifyIcon(NIM_ADD,&nc);
ShowWindow(false);
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | WS_EX_TOPMOST);
}
void CKeySoundDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
CDialog::OnSysCommand(nID, lParam);
if(nID == SC_MINIMIZE) //如果鼠标点击最小化按钮
{
OnMini();
}
}
// 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 CKeySoundDlg::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 CKeySoundDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CKeySoundDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg -> message == WM_KEYDOWN)
{
if(pMsg -> wParam == VK_ESCAPE)
return TRUE;
if(pMsg -> wParam == VK_RETURN)
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CKeySoundDlg::OnOk()
{
//OnOK();
OnMini();
}
void CKeySoundDlg::OnAbout()
{
CAboutDlg dlg;
dlg.DoModal();
}
void CAboutDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
m_ABOUTQUIT.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
BOOL CKeySoundDlg::DestroyWindow()
{
NOTIFYICONDATA nc;
nc.cbSize=sizeof(NOTIFYICONDATA);
nc.hWnd=m_hWnd;
nc.uCallbackMessage=WM_NC;
nc.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID=IDC_NC;
Shell_NotifyIcon(NIM_DELETE,&nc);
return CDialog::DestroyWindow();
}
void CKeySoundDlg::OnNc(WPARAM wParam,LPARAM IParam)
{
if(IParam==WM_LBUTTONDOWN)
{
ShowWindow(SW_SHOWNORMAL);
NOTIFYICONDATA nc;
nc.cbSize=sizeof(NOTIFYICONDATA);
nc.hWnd=m_hWnd;
nc.uCallbackMessage=WM_NC;
nc.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID=IDC_NC;
Shell_NotifyIcon(NIM_DELETE,&nc);
::SetWindowPos(GetSafeHwnd(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
if(IParam==WM_RBUTTONDOWN)
{
CMenu* menu;
menu = new CMenu();
menu->LoadMenu(IDR_MENU1);
CMenu* pPopup=menu->GetSubMenu(0);
::SetMenuDefaultItem(pPopup->m_hMenu,0,TRUE); //设置粗体字
CPoint Point;
GetCursorPos(&Point);
pPopup->TrackPopupMenu(TPM_LEFTALIGN,Point.x,Point.y,AfxGetMainWnd(),NULL);
}
}
void CKeySoundDlg::OnMenuQuit()
{
OnOK();
}
void CKeySoundDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDialog::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -