📄 clipboard.cpp
字号:
// ClipBoard.cpp : implementation file
//
#include "stdafx.h"
#include "linjunjuan.h"
#include "ClipBoard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClipBoard dialog
CClipBoard::CClipBoard(CWnd* pParent /*=NULL*/)
: CDialog(CClipBoard::IDD, pParent)
{
Clipnum=0;
//{{AFX_DATA_INIT(CClipBoard)
m_whichone = 0;
//}}AFX_DATA_INIT
}
void CClipBoard::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClipBoard)
DDX_Text(pDX, IDC_EDIT1, m_whichone);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClipBoard, CDialog)
//{{AFX_MSG_MAP(CClipBoard)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClipBoard message handlers
void CClipBoard::InitDIBData()
{
if (m_palDIB != NULL)
{
delete m_palDIB;
m_palDIB = NULL;
}
if (m_hDIB == NULL)
{
return;
}
// Set up document size
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_hDIB);
if (::DIBWidth(lpDIB) > INT_MAX ||::DIBHeight(lpDIB) > INT_MAX)
{
::GlobalUnlock((HGLOBAL) m_hDIB);
::GlobalFree((HGLOBAL) m_hDIB);
m_hDIB = NULL;
CString strMsg;
strMsg = "IDS_DIB_TOO_BIG";
// MessageBox(NULL, strMsg, NULL, MB_ICONINFORMATION | MB_OK);
return;
}
// m_sizeDoc = CSize((int) ::DIBWidth(lpDIB), (int) ::DIBHeight(lpDIB));
::GlobalUnlock((HGLOBAL) m_hDIB);
// Create copy of palette
m_palDIB = new CPalette;
if (m_palDIB == NULL)
{
// we must be really low on memory
::GlobalFree((HGLOBAL) m_hDIB);
m_hDIB = NULL;
return;
}
if (::CreateDIBPalette(m_hDIB, m_palDIB) == NULL)
{
// DIB may not have a palette
delete m_palDIB;
m_palDIB = NULL;
return;
}
}
void change(long *x,long *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
void CClipBoard::CopyToClipbox(Picture input,POINT Beg,POINT End)
{
int No;
No=Clipnum%6;
if(Clipbox[No].p!=NULL)
dspace_2d(Clipbox[No].p,Clipbox[No].row,Clipbox[No].col);
End.x=min(input.col,max(0,End.x));
End.y=min(input.row,max(0,End.y));
Clipbox[No].row=abs(Beg.y-End.y)-1;
Clipbox[No].col=abs(Beg.x-End.x)-1;
Clipbox[No].p=fspace_2d(Clipbox[No].row,Clipbox[No].col);
if (Clipbox[No].p==NULL)
{
AfxMessageBox("剪贴板错误!");
return ;
}
if (End.y<Beg.y)
change (&End.y,&Beg.y);
if (End.x<Beg.x)
change (&End.x,&Beg.x);
for (int i=Beg.y+1;i<End.y;i++)
for (int j=Beg.x+1;j<End.x;j++)
{
Clipbox[No].p[i-Beg.y-1][j-Beg.x-1]=input.p[i][j];
}
Clipnum++;
// Invalidate();
}
Picture CClipBoard::CopyToTemplate()
{
Picture output;
m_whichone=Clipnum%6-1;
if (DoModal()==IDOK)
{
output.row=Clipbox[m_whichone].row;
output.col=Clipbox[m_whichone].col;
output.p=fspace_2d(output.row,output.col);
if (output.p==NULL)
{
AfxMessageBox("粘贴错误!");
return output;
}
for (int i=0;i<output.row;i++)
for (int j=0;j<output.col;j++)
output.p[i][j]=Clipbox[m_whichone].p[i][j];
}
return output;
}
void CClipBoard::OnPaint()
{
CPaintDC dc(this);
if (Clipnum==0)
return;
int No;
if (Clipnum<=6)
No=Clipnum;
else
No=6;
for (int i=0;i<No;i++)
{
CWnd* pwnd =GetDlgItem(IDC_CLIPBOX1+i);
CDC *pControlDC =pwnd->GetDC();
pwnd->GetClientRect(&rect);
pwnd->Invalidate();
pwnd->UpdateWindow();
if ((m_hDIB=ChangeToHDIB(Clipbox[i]))==NULL)
{
AfxMessageBox("不能显示!");
return ;
}
InitDIBData();
rectdest.left=rectdib.left=rect.left;
rectdest.top=rectdib.top=rect.top;
rectdib.right=Clipbox[i].col;
rectdib.bottom=Clipbox[i].row;
rectdest.bottom=rect.bottom;
rectdest.right=rect.right;
PaintDIB(pControlDC->m_hDC,&rectdest,m_hDIB,&rectdib,m_palDIB);
pwnd->ReleaseDC(pControlDC);
}
}
void CClipBoard::OnOK()
{
UpdateData(TRUE);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -