史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   生活話題、日常閒聊、喇勒唬爛灌水區 (http://forum.slime.com.tw/f23.html)
-   -   "畫面擷取"革命性的發展 (http://forum.slime.com.tw/thread288901.html)

魔術王子 2019-04-29 08:09 PM

"畫面擷取"革命性的發展
 
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();
  }   
}
//---------------------------------------------------------------------------


魔術王子 2019-05-03 08:41 PM

https://drive.google.com/file/d/1mXt...ew?usp=sharing
分享一下程式
不過這是用BCB6.0設計的,新版BCB編譯可能會因為字元出錯,以後有機會再設計吧,有幾個地方說明一下
1.雙擊右下角圖示改變圖示開關監控
語法:

    case WM_LBUTTONDBLCLK:
      Timer1->Enabled=!Timer1->Enabled;
      if(Timer1->Enabled) {
        Clipboard()->Clear();
        ListView1->Tag=0;
        Clip2Bmp.hIcon=LoadIcon(HInstance,"Clip2Bmp1");
        strcpy(Clip2Bmp.szTip,"監控中");
      } else {
        Clip2Bmp.hIcon=LoadIcon(HInstance,"Clip2Bmp2");
        strcpy(Clip2Bmp.szTip,"閒置中");
      }
      Shell_NotifyIcon(NIM_MODIFY,&Clip2Bmp);
//      ShowWindow(Application->Handle,SW_RESTORE);
//      ShowWindow(Handle,SW_RESTORE);
      break;

2.右上角"關閉'按鈕
語法:

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  ShowWindow(Application->Handle,SW_HIDE);
  ShowWindow(Handle,SW_HIDE);
  CanClose=(Tag==1);
}
//---------------------------------------------------------------------------

3.還有SHBrowseForFolder使用
語法:

  String WorkDir;
  BROWSEINFO bi;
  char WDir[MAX_PATH];
  char FolderName[MAX_PATH];
  LPITEMIDLIST ItemID;
  memset(&bi, 0, sizeof(BROWSEINFO));
  memset(WDir, 0, MAX_PATH);
  bi.hwndOwner = Handle;
  bi.pszDisplayName = FolderName;
  bi.lpszTitle = "請選擇路徑";
  ItemID = SHBrowseForFolder(&bi);
  SHGetPathFromIDList(ItemID, WDir);
  WorkDir = String(WDir);
  if(WorkDir!="") StatusBar1->SimpleText=WorkDir+"\\";
  ScanFile();

注意藍字部分,才能使用SHBrowseForFolder
語法:

//---------------------------------------------------------------------------

#include <shlobj.h> //要放於 vcl.h 之前
#define NO_WIN32_LEAN_AND_MEAN

#include <vcl.h>
#include <Clipbrd.hpp>
#pragma hdrstop



所有時間均為台北時間。現在的時間是 01:39 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1