Windows擷取畫面的按鈕SrtScr雖然方便,可惜沒有加入游標的功能
幸好現在有很多相當方便的工具可以達到
之前小王子也分享過利用BCB設計畫面擷取的程式,而且透過GetCursorInfo API指令將游標加入
可惜加入游標的方法只能用在全螢幕擷取,一旦要擷取特定視窗就沒轍了
不過今天小王子終於克服這個問題,同樣的分享程式碼給大家
擷取畫面的方法還真不少,下面的方法是監控剪貼簿,當然同樣是擷取全螢幕
只不過,擷取完後,會取得上層視窗的位置及大小,對應到剛剛擷取的畫面,就可取得想要的視窗啦
語法:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
/*******************************************************************************************************************+
| CF_TEXT Text with a CR-LF combination at the end of each line. A null character identifies the end of the text. |
| CF_BITMAP A Windows bitmap graphic. |
| CF_METAFILEPICT A Windows metafile graphic. |
| CF_PICTURE An object of type TPicture. |
| CF_COMPONENT Any persistent object. |
+*******************************************************************************************************************/
if(GetTickCount()-bt >= 60000) {
Timer1->Enabled=false;
ShowWindow(Application->Handle,SW_RESTORE);
ShowWindow(Handle,SW_RESTORE);
}
p1=p;
::GetCursorPos(&p);
if((p.x==p1.x)&&(p.y==p1.y)){
if(GetTickCount()-bt >= 180000) { //3分鐘內沒移動滑鼠
Close();
}
}
if(Clipboard()->HasFormat(CF_BITMAP)) {
bt=GetTickCount();
Graphics::TBitmap *PictBmp=new Graphics::TBitmap;
Graphics::TBitmap *TempBmp=new Graphics::TBitmap;
TempBmp->Assign(Clipboard());
if(CheckBox1->Checked){
CURSORINFO ci;
ci.cbSize=sizeof(CURSORINFO);
GetCursorInfo(&ci);
POINT pt;
GetCursorPos(&pt);
DrawIcon(TempBmp->Canvas->Handle, pt.x, pt.y, ci.hCursor);
}
if(CheckBox5->Checked){
HWND Wnd;
Wnd=::GetForegroundWindow();
TRect R;
GetWindowRect(Wnd, &R);
// Caption=Format("(%d,%d)-(%d,%d) %dx%d",OPENARRAY(TVarRec,((int)R.left,(int)R.top,(int)R.right,(int)R.bottom,(int)(R.right - R.left),(int)(R.bottom - R.top))));
PictBmp->Width=R.right - R.left;
PictBmp->Height=R.bottom - R.top;
BitBlt(PictBmp->Canvas->Handle, 0, 0, R.right, R.bottom, TempBmp->Canvas->Handle, R.left, R.top, SRCCOPY);
} else PictBmp->Assign(TempBmp);
if(CheckBox3->Checked){
Clipboard()->Assign(PictBmp);
} else {
int i=ComboBox1->Text.ToInt();
if(!DirectoryExists(Edit1->Text)) ::CreateDirectory(Edit1->Text.c_str(),NULL);
if(!CheckBox4->Checked) while (FileExists(Edit1->Text+"Picture ("+i+").bmp")) i++;
PictBmp->SaveToFile(Edit1->Text+"Picture ("+i+").bmp");
UpDown1->Position=++i;
delete TempBmp;
delete PictBmp;
}
Clipboard()->Clear();
}
}
//---------------------------------------------------------------------------