#ifndef mainH
#define mainH
#include <Classes.hpp>
#include <ExtCtrls.hpp>
#include <Clipbrd.hpp>// 手加
//---------------------------------------------------------------------------
bool PasteFileFromClip(LPCSTR pcDesDir);
class Tmain_ : public TForm
{
__published:
TTimer *Timer1;
void __fastcall Timer1Timer(TObject *Sender);
private:
void theFormToClip();
void desktopToClip();
void clipToBMPFile(AnsiString FileString);
public:
__fastcall Tmain_(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE Tmain_ *main_;
//---------------------------------------------------------------------------
#endif
#include <vcl.h>
#pragma hdrstop
#include "main.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
Tmain_ *main_;
//---------------------------------------------------------------------------
__fastcall Tmain_::Tmain_(TComponent* Owner): TForm(Owner)
{
Timer1->Interval=5000;
this->Position=poScreenCenter;
}
//---------------------------------------------------------------------------
void Tmain_::theFormToClip()
{
/*
typedef struct tagINPUT
{
DWORD type;
union
{
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
}
*/
tagINPUT * input=new tagINPUT[2];
input[0].type=INPUT_KEYBOARD;
input[1].type=INPUT_KEYBOARD;
input[0].ki.wVk=VK_SNAPSHOT;
input[1].ki.wVk=VK_SNAPSHOT;
input[0].ki.wScan=1;
input[1].ki.wScan=1;
input[0].ki.dwFlags=0;
input[1].ki.dwFlags=KEYEVENTF_KEYUP;
input[0].ki.time=GetTickCount();
input[1].ki.time=GetTickCount();
SendInput(2,input,sizeof(INPUT));
delete [] input;
}
//---------------------------------------------------------------------------
void Tmain_::desktopToClip()
{
keybd_event(VK_SNAPSHOT, 0, 0 ,0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP,0);
}
//---------------------------------------------------------------------------
void Tmain_::clipToBMPFile(AnsiString FileString)
{
Graphics::TBitmap *bmp = new Graphics::TBitmap();
TClipboard *pClipboard = new TClipboard();//#include <Clipbrd.hpp>
bmp->Assign(pClipboard);
bmp->SaveToFile(FileString+".bmp");
delete pClipboard;
delete bmp;bmp=0;
}
//---------------------------------------------------------------------------
void __fastcall Tmain_::Timer1Timer(TObject *Sender)
{
Timer1->Enabled=false;
theFormToClip();
GUID zheGUID;
CreateGUID(zheGUID);
AnsiString FileString=GUIDToString(zheGUID);
clipToBMPFile(FileString);
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------