?? copyscreendlg.cpp
字號:
// CopyScreenDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CopyScreen.h"
#include "CopyScreenDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCopyScreenDlg dialog
CCopyScreenDlg::CCopyScreenDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCopyScreenDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCopyScreenDlg)
// 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 CCopyScreenDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCopyScreenDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCopyScreenDlg, CDialog)
//{{AFX_MSG_MAP(CCopyScreenDlg)
ON_BN_CLICKED(IDC_BTNSNAP, OnBtnsnap)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CCopyScreenDlg message handlers
BOOL CCopyScreenDlg::OnInitDialog()
{
// m_bFullScreen = FALSE;
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
/*
函數名稱:拷貝屏幕
入口參數:(無)
出口參數:nWidth : 存儲屏幕寬度
nHeight : 存儲屏幕高度
返 回 值:存儲屏幕位圖
*/
HBITMAP CopyScreenToBitmap(int &nWidth,int &nHeight)
{
// 屏幕和內存設備描述表
HDC hScrDC, hMemDC;
// 位圖句柄
HBITMAP hBitmap, hOldBitmap;
// 屏幕分辨率
int xScrn, yScrn;
//為屏幕創建設備描述表
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
//為屏幕設備描述表創建兼容的內存設備描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 獲得屏幕分辨率
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//存儲屏幕的長寬
nWidth = xScrn;
nHeight = yScrn;
// 創建一個與屏幕設備描述表兼容的位圖
hBitmap = CreateCompatibleBitmap(hScrDC, xScrn, yScrn);
// 把新位圖選到內存設備描述表中
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
// 把屏幕設備描述表拷貝到內存設備描述表中
BitBlt(hMemDC, 0, 0, xScrn,yScrn,hScrDC, 0, 0, SRCCOPY);
//得到屏幕位圖的句柄
hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
//清除
DeleteDC(hScrDC);
DeleteDC(hMemDC);
// 返回位圖句柄
return hBitmap;
}
void CCopyScreenDlg::OnBtnsnap()
{
HBITMAP bmp;
int nWidth,nHeight;
//抓取屏幕
bmp = CopyScreenToBitmap(nWidth,nHeight);
//將抓取的屏幕壓縮顯示到窗體上
CDC *pDC = new CClientDC(this);
CDC srcDC;
CRect rect;
this->GetClientRect(&rect);
rect.DeflateRect(0,20);
//繪制顯示區域矩形
CPen pen;
pen.CreatePen(PS_SOLID,2,RGB(0,255,255));
pDC->SelectObject(&pen);
pDC->Rectangle(rect);
//顯示屏幕
srcDC.CreateCompatibleDC(pDC);
srcDC.SelectObject(bmp);
pDC->StretchBlt(rect.left+2,rect.top+2,rect.right - rect.left - 4 ,rect.bottom - rect.top - 4,&srcDC,0,0,nWidth,nHeight,SRCCOPY);
DeleteObject(bmp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -