用Visual C++实现屏幕抓程序(12)
CMenu pop;
pop.LoadMenu(MAKEINTRESOURCE(IDR_MENU1));
CMenu*pMenu=pop.GetSubMenu(0);
pMenu->SetDefaultItem(ID_EXITICON);
CPoint pt;
GetCursorPos(&pt);
int id=pMenu->TrackPopupMenu(TPM_RIGHTALIGN|TPM_NONOTIFY|
TPM_RETURNCMD|TPM_LEFTBUTTON,pt.x,pt.y,this);
if(id==ID_EXITICON)
DeleteIcon();
else if(id==ID_EXIT)
OnCancel();
return FALSE;
}
LRESULT res= CDialog::WindowProc(message, wParam, lParam);
if(message==WM_SYSCOMMAND&&wParam==SC_MINIMIZE)
AddIcon();
return res;
}
void CCaptureDlg::AddIcon()
{
NOTIFYICONDATA data;
data.cbSize=sizeof(NOTIFYICONDATA);
CString tip;
tip.LoadString(IDS_ICONTIP);
data.hIcon=GetIcon(0);
data.hWnd=GetSafeHwnd();
strcpy(data.szTip,tip);
data.uCallbackMessage=IDM_SHELL;
data.uFlags=NIF_ICON|NIF_MESSAGE |NIF_TIP ;
data.uID=98;
Shell_NotifyIcon(NIM_ADD,&data);
ShowWindow(SW_HIDE);
bTray=TRUE;
}
void CCaptureDlg::DeleteIcon()
{
NOTIFYICONDATA data;
data.cbSize=sizeof(NOTIFYICONDATA);
data.hWnd=GetSafeHwnd();
data.uID=98;
Shell_NotifyIcon(NIM_DELETE,&data);
ShowWindow(SW_SHOW);
SetForegroundWindow();
ShowWindow(SW_SHOWNORMAL);
bTray=FALSE;
}
void CCaptureDlg::OnChange()
{
RegisterHotkey();
}
BOOL CCaptureDlg::RegisterHotkey()
{
UpdateData();
UCHAR mask=0;
UCHAR key=0;
if(m_bControl)
mask|=4;
if(m_bAlt)
mask|=2;
if(m_bShift)
mask|=1;
key=Key_Table[m_Key.GetCurSel()];
if(bRegistered){
DeleteHotkey(GetSafeHwnd(),cKey,cMask);
bRegistered=FALSE;
}
cMask=mask;
cKey=key;
bRegistered=AddHotkey(GetSafeHwnd(),cKey,cMask);
return bRegistered;
}
四、小结
本实例通过一个钩子DLL实现了屏幕抓图的功能,它有一个缺陷,那就是只能保存整个屏幕图像,不过读者朋友可以在此基础上,实现屏幕任意区域的抓图功能,具体方法不再赘述,实现起来很容易的了,呵呵。
- 上一篇:VC++中实现以复杂线条为基础的图形绘图
- 下一篇:通过例程分析状态条用法