C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[6475] Re:(백그라운드 캡춰에서)구조요청!제발!
한꼬맹이 [] 2305 읽음    2001-03-30 20:15
조경달 님이 쓰신 글 :
: 백그라운드에서 계속해서 화면을 캡춰하는 놈인데
: 잘 돌다가도 마우스를 마구 움직이면 시스템시소스가 없다나요...
: 아무리 보아도 로직에러는 없습니다.
:
: 고수님들의 도움을 기다립니다.
:
:
:
: //---------------------------------------------------------------------------
:
: #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();

처럼 해주시고요...

이정도만 하면 멀티쓰레드에서 안전할겁니다.

그럼 참고하시길....

+ -

관련 글 리스트
6462 (백그라운드 캡춰에서)구조요청!제발! 조경달 2072 2001/03/30
6475     Re:(백그라운드 캡춰에서)구조요청!제발! 한꼬맹이 2305 2001/03/30
6488         마찬가지입니다. 다시 구조요청!!! 조경달 2199 2001/03/31
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.