史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
註冊帳號 論壇說明 標記討論區已讀

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2014-06-14, 11:33 PM   #1
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:37 | 在線時長:1530小時 | 升級還需:66小時級別:37 | 在線時長:1530小時 | 升級還需:66小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 2203
精華: 0
現金: 11345 金幣
資產: 2674855 金幣
預設 程式 - [使用版本C++ Builder 6]螢幕擷取

[螢幕擷取]程式碼:
程式有幾項特點,1.可使用F7熱鍵擷取,2.使用熱鍵擷取可以加入游標3.儲存剪貼簿的圖或將圖檔匯入剪貼簿
沒有執行畫面,下面是表單項目
引用:
object PopupMenu1: TPopupMenu
AutoHotkeys = maManual
Left = 56
Top = 72
object N1: TMenuItem
Caption = '擷取螢幕...'
OnClick = N1Click
end
object N4: TMenuItem
AutoCheck = True
Caption = '存入檔案'
end
object N2: TMenuItem
Caption = '-'
end
object N5: TMenuItem
AutoCheck = True
Caption = '熱鍵(F7)...'
OnClick = N5Click
end
object N6: TMenuItem
Caption = '熱鍵選項'
object N12: TMenuItem
AutoCheck = True
Caption = '加入游標'
Checked = True
end
object N13: TMenuItem
AutoCheck = True
Caption = '存入檔案'
Checked = True
end
object N14: TMenuItem
AutoCheck = True
Caption = '有工作列'
Checked = True
end
end
object N7: TMenuItem
Caption = '-'
end
object N8: TMenuItem
Caption = '剪貼簿'
object N10: TMenuItem
Caption = '匯出...'
OnClick = N10Click
end
object N11: TMenuItem
Caption = '匯入...'
OnClick = N11Click
end
end
object N9: TMenuItem
Caption = '-'
end
object N3: TMenuItem
Caption = '結束'
OnClick = N3Click
end
end
再來是程式碼:
引用:
作者: Unit1.cpp
//---------------------------------------------------------------------------

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

#include "Unit1.h"
#include "jpeg.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
RECT rec;
HWND hwnd;
hwnd=::FindWindow("Shell_TrayWnd",NULL);
::GetWindowRect(hwnd,&rec);
Top=rec.top-Height;
Left=rec.right-Width;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(N5->Checked) ::UnregisterHotKey(Handle,MYWM_ID);
DelIcon();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
AddIcon();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
Graphics::TBitmap *ImageBmp=new Graphics::TBitmap;
DWORD bt;
bt=GetTickCount();
do {
Application->ProcessMessages();
} while (GetTickCount()-bt<1000);
HDC ScrDC;
TRect R;
RECT r;
HWND hwnd;
hwnd=::FindWindow("Shell_TrayWnd",NULL);
::GetWindowRect(hwnd,&r);
HWND Wnd=GetDesktopWindow();
ScrDC=GetWindowDC(Wnd);
GetWindowRect(Wnd, &R);
ImageBmp->Width = R.right;
ImageBmp->Height = R.bottom;
BitBlt(ImageBmp->Canvas->Handle, 0, 0, R.right, R.bottom, ScrDC, 0, 0, SRCCOPY);
ReleaseDC(Wnd, ScrDC);
if(N4->Checked){
if (SavePictureDialog1->Execute()){
TJPEGImage *TheJPEG;
TheJPEG = new TJPEGImage;
TheJPEG->Assign(ImageBmp);
TheJPEG->SaveToFile(SavePictureDialog1->FileName);
delete TheJPEG;
}
} else Clipboard()->Assign(ImageBmp);
delete ImageBmp;
}
//---------------------------------------------------------------------------
void TForm1::AddIcon()
{
ezScrCap.cbSize=sizeof(NOTIFYICONDATA);
ezScrCap.hWnd=Handle;
ezScrCap.uID=(UINT)MYNOTIFYICONID;
ezScrCap.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
ezScrCap.uCallbackMessage=MYWM_NOTIFYICON;
ezScrCap.hIcon=LoadIcon(HInstance,"MAINICON");
strcpy(ezScrCap.szTip,this->Caption.c_str());
Shell_NotifyIcon(NIM_ADD,&ezScrCap);
ShowWindow(Application->Handle,SW_HIDE);
ShowWindow(Handle,SW_HIDE);
SetWindowText(Application->Handle,this->Caption.c_str());
}
//---------------------------------------------------------------------------

void TForm1:elIcon()
{
ezScrCap.cbSize=sizeof(NOTIFYICONDATA);
ezScrCap.hWnd=Handle;
ezScrCap.uID=(UINT)MYNOTIFYICONID;
ezScrCap.uFlags=0;
ezScrCap.uCallbackMessage=MYWM_NOTIFYICON;
ezScrCap.hIcon=0;
strcpy(ezScrCap.szTip,this->Caption.c_str());
Shell_NotifyIcon(NIM_DELETE,&ezScrCap);
ShowWindow(Application->Handle,SW_NORMAL);
ShowWindow(Handle,SW_NORMAL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TRAYCALLBACK(TMessage& Message)
{
POINT MousePos;
switch(Message.LParam)
{
case WM_LBUTTONDBLCLK:
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
if (GetCursorPos(&MousePos))
{
PopupMenu1->PopupComponent = Form1;
SetForegroundWindow(Handle);
PopupMenu1->Popup(MousePos.x, MousePos.y);
}
break;
default:
break;
}
TForm:ispatch(&Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N10Click(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(Clipboard()->HasFormat(CF_BITMAP)) {
if (SavePictureDialog1->Execute()){
TJPEGImage *TheJPEG;
TheJPEG = new TJPEGImage;
TheJPEG->Assign(Clipboard());
TheJPEG->SaveToFile(SavePictureDialog1->FileName);
delete TheJPEG;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N11Click(TObject *Sender)
{
TJPEGImage *TheJPEG;
if (OpenPictureDialog1->Execute()){
TheJPEG= new TJPEGImage;
TheJPEG->LoadFromFile(OpenPictureDialog1->FileName);
Clipboard()->Assign(TheJPEG);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N5Click(TObject *Sender)
{
if(N5->Checked)
::RegisterHotKey(Handle,MYWM_ID,NULL,VK_F7); //NULL, MOD_ALT, MOD_CONTROL, MOD_NOREPEAT, MOD_SHIFT, MOD_WIN
else
::UnregisterHotKey(Handle,MYWM_ID);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WMHotKey(TMessage& Message)
{
Graphics::TBitmap *ImageBmp=new Graphics::TBitmap;
// DWORD bt;
// bt=GetTickCount();
// do {
// Application->ProcessMessages();
// } while (GetTickCount()-bt<3000);
HDC ScrDC;
TRect R;
HWND Wnd=GetDesktopWindow();
ScrDC=GetWindowDC(Wnd);
GetWindowRect(Wnd, &R);
// MapWindowPoints(HWND_DESKTOP, Wnd, (PPOINT)&R, 2);
// OffsetRect(&R, -R.left, -R.top);
ImageBmp->Width = R.right;
if(N14->Checked){
ImageBmp->Height = R.bottom;
} else {
RECT r;
HWND hwnd;
hwnd=::FindWindow("Shell_TrayWnd",NULL);
::GetWindowRect(hwnd,&r);
ImageBmp->Height = r.top;
}
BitBlt(ImageBmp->Canvas->Handle, 0, 0, R.right, R.bottom, ScrDC, 0, 0, SRCCOPY);
if(N12->Checked) {
CURSORINFO ci;
ci.cbSize=sizeof(CURSORINFO);
GetCursorInfo(&ci);
POINT pt;
GetCursorPos(&pt);
DrawIcon(ImageBmp->Canvas->Handle, pt.x, pt.y, ci.hCursor);
}
ReleaseDC(Wnd, ScrDC);
if(N13->Checked){
if (SavePictureDialog1->Execute()){
TJPEGImage *TheJPEG;
TheJPEG = new TJPEGImage;
TheJPEG->Assign(ImageBmp);
TheJPEG->SaveToFile(SavePictureDialog1->FileName);
delete TheJPEG;
::ShellExecute(::GetDesktopWindow(), "Open", SavePictureDialog1->FileName.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
} else Clipboard()->Assign(ImageBmp);
delete ImageBmp;
TForm:ispatch(&Message);
}
//---------------------------------------------------------------------------
引用:
作者: Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
#define MYNOTIFYICONID WM_USER+10
#define MYWM_NOTIFYICON WM_USER+20
#define MYWM_ID WM_USER+30
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <ExtDlgs.hpp>
#include <Menus.hpp>
#include <ComCtrls.hpp>
#include <ToolWin.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPopupMenu *PopupMenu1;
TSavePictureDialog *SavePictureDialog1;
TMenuItem *N1;
TMenuItem *N2;
TMenuItem *N3;
TMenuItem *N4;
TMenuItem *N5;
TMenuItem *N6;
TMenuItem *N7;
TMenuItem *N8;
TMenuItem *N9;
TMenuItem *N10;
TMenuItem *N11;
TOpenPictureDialog *OpenPictureDialog1;
TMenuItem *N12;
TMenuItem *N13;
TMenuItem *N14;
void __fastcall FormCreate(TObject *Sender);
void __fastcall N3Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormActivate(TObject *Sender);
void __fastcall N1Click(TObject *Sender);
void __fastcall N10Click(TObject *Sender);
void __fastcall N11Click(TObject *Sender);
void __fastcall N5Click(TObject *Sender);
private: // User declarations
NOTIFYICONDATA ezScrCap;
void TForm1::AddIcon();
void TForm1:elIcon();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void virtual _fastcall TRAYCALLBACK(TMessage& Message);
void __fastcall WMHotKey(TMessage& Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MYWM_NOTIFYICON,TMessage,TRAYCALLBACK)
VCL_MESSAGE_HANDLER(WM_HOTKEY, TMessage, WMHotKey)
END_MESSAGE_MAP(TForm);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
引用:
作者: Unit1.dfm
object Form1: TForm1
Left = 763
Top = 435
Width = 235
Height = 322
Caption = 'ezScrCap'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnActivate = FormActivate
OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object PopupMenu1: TPopupMenu
AutoHotkeys = maManual
Left = 56
Top = 72
object N1: TMenuItem
Caption = #25847#21462#34722#24149'...'
OnClick = N1Click
end
object N4: TMenuItem
AutoCheck = True
Caption = #23384#20837#27284#26696
end
object N2: TMenuItem
Caption = '-'
end
object N5: TMenuItem
AutoCheck = True
Caption = #29105#37749'(F7)...'
OnClick = N5Click
end
object N6: TMenuItem
Caption = #29105#37749#36984#38917
object N12: TMenuItem
AutoCheck = True
Caption = #21152#20837#28216#27161
Checked = True
end
object N13: TMenuItem
AutoCheck = True
Caption = #23384#20837#27284#26696
Checked = True
end
object N14: TMenuItem
AutoCheck = True
Caption = #26377#24037#20316#21015
Checked = True
end
end
object N7: TMenuItem
Caption = '-'
end
object N8: TMenuItem
Caption = #21098#36028#31807
object N10: TMenuItem
Caption = #21295#20986'...'
OnClick = N10Click
end
object N11: TMenuItem
Caption = #21295#20837'...'
OnClick = N11Click
end
end
object N9: TMenuItem
Caption = '-'
end
object N3: TMenuItem
Caption = #32080#26463
OnClick = N3Click
end
end
object SavePictureDialog1: TSavePictureDialog
DefaultExt = '.jpg'
Filter = 'JPEG Image File (*.jpg)|*.jpg'
Left = 88
Top = 72
end
object OpenPictureDialog1: TOpenPictureDialog
DefaultExt = '.jpg'
Filter = 'JPEG Image File (*.jpg)|*.jpg'
Left = 120
Top = 72
end
end
__________________
魔術就是欣賞神奇的效果
如果魔術的秘密被破解了
那魔術就失去欣賞的價值
魔術王子 目前離線  
送花文章: 1169, 收花文章: 1297 篇, 收花: 3509 次
回覆時引用此帖
發文 回覆


主題工具
顯示模式

發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
Delphi/C builder 語系修改(瞞天過海) 丹楓 軟體中文化討論區 3 2005-02-06 11:59 PM
問Muiltimedia Builder的問題 ? jason522 一般電腦疑難討論區 5 2003-07-23 10:45 PM
請問Multimedia Builder的問題!!!? jason522 一般電腦疑難討論區 3 2003-06-30 06:20 PM
請問,誰有Screen Saver Builder v3.22的中文化 wilson1964 一般電腦疑難討論區 0 2003-05-09 03:16 AM
karaoke builder nicegood 一般電腦疑難討論區 0 2003-04-11 11:35 AM


所有時間均為台北時間。現在的時間是 09:31 PM


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


SEO by vBSEO 3.6.1