|
한꼬맹이 님이 쓰신 글 :
: 조경달 님이 쓰신 글 :
: : 백그라운드에서 계속해서 화면을 캡춰하는 놈인데
: : 잘 돌다가도 마우스를 마구 움직이면 시스템시소스가 없다나요...
: : 아무리 보아도 로직에러는 없습니다.
: :
: : 고수님들의 도움을 기다립니다.
: :
: :
: :
: : //---------------------------------------------------------------------------
: :
: : #include <vcl.h>
: : #include <jpeg.hpp>
: :
: : #pragma hdrstop
: :
: : #include "cap.h"
: : //---------------------------------------------------------------------------
: : #pragma package(smart_init)
: : #pragma resource "*.dfm"
: : TForm1 *Form1;
: : class TCaptureThread : public TThread
: : {
: : public:
: : void __fastcall Execute(void);
: : __fastcall TCaptureThread(void):TThread(true)
: : {};
: : };
: :
: : //---------------------------------------------------------------------------
: : __fastcall TForm1::TForm1(TComponent* Owner)
: : : TForm(Owner)
: : {
: : }
: :
: : void __fastcall TCaptureThread::Execute(void)
: : {
: : int status;
: : TRect rect,rect2,FullRect;
: : int lx,ly,sx,sy,dif;
: : TMemoryStream *tms=new TMemoryStream;
: : static int initialized =false;
: : Graphics::TBitmap *Bitmap;
: :
: : Bitmap= new Graphics::TBitmap;
: :
: : HDC dc = GetDC(0);
: : Graphics::TCanvas *ScreenCanvas = new Graphics::TCanvas;
: : ScreenCanvas->Handle=dc;
: :
: : TJPEGImage *jp = new TJPEGImage();
: :
: :
: : while(1){
: : Bitmap->Height=Screen->Height;
: : Bitmap->Width=Screen->Width;
: : Form1->Memo1->Lines->Add("!");
: : rect = Rect(0,0,Screen->Width,Screen->Height);
: :
: : sx=sy=0;
: : lx=Screen->Width;
: : ly=Screen->Height;
: :
: : rect = Rect(0,0,lx-sx,ly-sy);
: : rect2 = Rect(sx,sy,lx,ly);
: : Bitmap->Canvas->CopyRect(rect,ScreenCanvas,rect2);
: : ////////////////////////////////////////////
: : /////PART SCREEN Update
: : tms->Position=0;
: : jp->Assign(Bitmap);
: : jp->SaveToStream(tms);
: : // DataSize = tms->Position;
: :
: : }//while
: : Form1->Memo1->Lines->Add("Cap thread end!");
: : delete Bitmap;
: : delete ScreenCanvas;
: : delete jp;
: :
: : ReleaseDC(NULL,dc);
: :
: : }
: :
: : //---------------------------------------------------------------------------
: :
: :
: : void __fastcall TForm1::FormCreate(TObject *Sender)
: : {
: : TCaptureThread * captureThread = new TCaptureThread;
: : captureThread->Priority = tpNormal; // set the priority lower than normal
: : captureThread->Resume(); // now run the thread
: : }
: : //---------------------------------------------------------------------------
: :
:
: 안녕하십니까?
:
: 한꼬맹이 입니다.
:
: 제가 한방에 여러개의 답변을 쓰다보니 게을러서 코드는 작성 못해드리고 문제점만
:
: 지적해드리자면 위의 코드는 멀티쓰레드로 돌아가기에 안전한 코드가 아닙니다.
:
: 먼저 TCaptureThread * captureThread = new TCaptureThread(true); 고치시고
:
: Execute()부분에서 VCL에 접근하는 코드를 사용할려면 Synchronize()를 이용하셔야
:
: 합니다. 그리고 Canvas에 접근하려면
:
: Canvas->Lock();
: //Canvas접근 내용
: Canvas->UnLock();
:
: 처럼 해주시고요...
:
: 이정도만 하면 멀티쓰레드에서 안전할겁니다.
:
: 그럼 참고하시길....
|