C++ 抓屏程序
要找个C++ 抓屏程序,需要源码。
追问:不是C++ bluder
要找个C++ 抓屏程序,需要源码。
追问:不是C++ bluder
答案:一个类似于QQ截屏的BCB代码:TSnapScrForm *SnapScrForm;
//---------------------------------------------------------------------------
__fastcall TSnapScrForm::TSnapScrForm(TComponent* Owner)
: TForm(Owner)
{
DoubleBuffered=true;
MouseDown=false;
HasRect=false;
RectOK=false;
Width=Screen->Width;
Height=Screen->Height;imgScreen->Width=Screen->Width;
imgScreen-> Height=Screen->Height;
HDC hdc = GetDC(0);
BitBlt(imgScreen->Canvas->Handle, 0, 0,
imgScreen->Width, imgScreen->Height,
hdc,
0,
0,
SRCCOPY);}
//---------------------------------------------------------------------------void __fastcall TSnapScrForm::FormKeyPress(TObject *Sender, char &Key)
{
switch(Key){
case VK_ESCAPE:
Close();
case VK_RETURN:
pb1DblClick(pb1);
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::pb1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(!HasRect){
SnaRect.Right=X;
SnaRect.Bottom=Y;
SnaRect.Left=X;
SnaRect.Top=Y;
}else
OldRect=SnaRect;
MouseDown=true;
MouseDownXY.x=X;
MouseDownXY.y=Y;
pb1->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::TestMouse(int x,int y){
if(y>=SnaRect.Top-2&&y<=SnaRect.Bottom+2
&&x>=SnaRect.Left-2&&x<=SnaRect.Right+2
){
if(y<=SnaRect.Top+2){//上边线
if(x<=SnaRect.Left+2)MousePosition=onLeftTop;
else
if(x>=SnaRect.Right-2)MousePosition=onRightTop;
else MousePosition=onTop;
}
else
if(y>=SnaRect.Bottom-2){//下边线
if(x<=SnaRect.Left+2)MousePosition=onLeftBottom;
else
if(x>=SnaRect.Right-2)MousePosition=onRightBottom;
else MousePosition=onBottom;
}
else{//中间
if(x<=SnaRect.Left+2)MousePosition=onLeft;
else
if(x>=SnaRect.Right-2)MousePosition=onRight;
else MousePosition=onCenter;
}
}else
MousePosition=onNone;
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::pb1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if(MouseDown){
if(!RectOK){
HasRect=true;
SnaRect.Right=X;
SnaRect.Bottom=Y;
}else{//move or scale
X=(X-MouseDownXY.x);
Y=(Y-MouseDownXY.y);
switch(MousePosition){
case onLeftTop :SnaRect.Top=OldRect.Top+Y;
case onLeft :SnaRect.Left=OldRect.Left+X;break;
case onRightBottom:SnaRect.Bottom=OldRect.Bottom+Y;
case onRight :SnaRect.Right=OldRect.Right+X;break;
case onRightTop :SnaRect.Right=OldRect.Right+X;
case onTop :SnaRect.Top=OldRect.Top+Y;break;
case onLeftBottom :SnaRect.Left=OldRect.Left+X;
case onBottom :SnaRect.Bottom=OldRect.Bottom+Y;break;
case onCenter :SnaRect.Left=OldRect.Left+X;
SnaRect.Right=OldRect.Right+X;
SnaRect.Top=OldRect.Top+Y;
SnaRect.Bottom=OldRect.Bottom+Y;break;
}
}
}
else{
if(RectOK){
TestMouse(X,Y);
switch(MousePosition){//根据鼠标位置,确定鼠标形状
case onLeft :
case onRight :pb1->Cursor=crSizeWE;break;
case onTop :
case onBottom :
pb1->Cursor=crSizeNS;break;
case onLeftTop :
case onRightBottom:pb1->Cursor=crSizeNWSE;break;
case onRightTop :
case onLeftBottom:pb1->Cursor=crSizeNESW;break;
case onCenter :pb1->Cursor=crSizeAll;break;
case onNone :pb1->Cursor=crDefault;break;}
}
}
pb1->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::pb1Paint(TObject *Sender)
{
BitBlt(pb1->Canvas->Handle, 0, 0,
Width, Height,
imgScreen->Canvas->Handle,
0,
0,
SRCCOPY);
if(HasRect){
pb1->Canvas->Pen->Color=clBlue;
pb1->Canvas->DrawFocusRect(SnaRect);
pb1->Canvas->Pen->Color=clBlue;
pb1->Canvas->Brush->Style=bsClear;
pb1->Canvas->Rectangle(SnaRect.Left-3,SnaRect.Bottom-3,SnaRect.Left+3,SnaRect.Bottom+3);
pb1->Canvas->Rectangle(SnaRect.Right-3,SnaRect.Bottom-3,SnaRect.Right+3,SnaRect.Bottom+3);
pb1->Canvas->Rectangle(SnaRect.Left-3,SnaRect.Top-3,SnaRect.Left+3,SnaRect.Top+3);
pb1->Canvas->Rectangle(SnaRect.Right-3,SnaRect.Top-3,SnaRect.Right+3,SnaRect.Top+3);
}
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::pb1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
MouseDown=false;
if(HasRect){
RectOK=true;
if(SnaRect.Left>SnaRect.Right||SnaRect.Top>SnaRect.Bottom){
if(SnaRect.Left>SnaRect.Right){
X=SnaRect.Left;
SnaRect.Left=SnaRect.Right;
SnaRect.Right=X;
}
if(SnaRect.Top>SnaRect.Bottom){
Y=SnaRect.Top;
SnaRect.Top=SnaRect.Bottom;
SnaRect.Bottom=Y;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TSnapScrForm::pb1DblClick(TObject *Sender)
{
if(HasRect&&SnaRect.Width()&&SnaRect.Height()){
Graphics::TBitmap *bmp=new Graphics::TBitmap();
try{
bmp->Width=SnaRect.Width();
bmp->Height=SnaRect.Height();
bmp->Canvas->CopyRect(TRect(0,0,SnaRect.Width(),SnaRect.Height()), imgScreen->Canvas,SnaRect);
Clipboard()->Assign(bmp);
TJPEGImage *jpg = new TJPEGImage();
try
{
jpg->PixelFormat = jf24Bit;
jpg->Assign(bmp);
AnsiString TempJpeg=SnapeBufPath+AnsiString(double(Now()))+".jpg";
jpg->SaveToFile(TempJpeg);
ICQForm->InsertQQFace(ICQForm->redtSay,TempJpeg);
}
__finally
{
delete jpg;
}
}
__finally{delete bmp; Close();}}
}
//---------------------------------------------------------------------------void __fastcall TSnapScrForm::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==VK_DELETE){
MouseDown=false;
HasRect=false;
RectOK=false;
pb1->Cursor=crCross;
pb1->Repaint();
}}
上一个:关于Visual C++的问题
下一个:C++有什么用