查看單個文章
舊 2019-04-29, 08:09 PM   #1
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:42 | 在線時長:1983小時 | 升級還需:38小時級別:42 | 在線時長:1983小時 | 升級還需:38小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 2943
精華: 0
現金: 14755 金幣
資產: 2678385 金幣
預設 "畫面擷取"革命性的發展

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();
  }    
}
//---------------------------------------------------------------------------
__________________
『唸金母心咒:嗡。金母。悉地。吽。』
持此咒者,可免一切瘟疫,一切瘟神抱頭四散。

魔術就是欣賞神奇的效果
如果魔術的秘密被破解了
那魔術就失去欣賞的價值
魔術王子 目前線上  
送花文章: 1523, 收花文章: 1552 篇, 收花: 3891 次
回覆時引用此帖
有 5 位會員向 魔術王子 送花:
a471 (2019-04-30),johnss (2019-05-08),mini (2019-04-29),ppp0600 (2019-04-30),runonetime (2019-04-30)
感謝您發表一篇好文章