線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1648
推到 Plurk!
推到 Facebook!

為何 WM_PAINT 不能重畫

尚未結案
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-25 09:04:10 IP:139.223.xxx.xxx 未訂閱
我寫了以下的程式,發覺有 WM_PAINT 事件後,視窗會被清除,不會自動重畫,請問為何位如此呢?那該如何解決,謝謝各位的指導.  
 
#include //*.cpp #pragma hdrstop #include "Unit1.h" //-------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { endpoints=0; pendown=0; StartX=0; StartY=0; CurX=0; CurY=0; EndX=0; EndY=0; theta=0; wflag=0; pMode=R2_BLACK; hCurrentPen=this->Canvas->Pen; hRedPen=CreatePen(PS_SOLID,1,RGB(255,0,0)); hGreenPen=CreatePen(PS_SOLID,1,RGB(0,255,0)); hBluePen=CreatePen(PS_SOLID,1,RGB(0,0,255)); maxX=GetSystemMetrics(SM_CXSCREEN); maxY=GetSystemMetrics(SM_CYSCREEN); hdc=GetDC(this->Handle); memdc=CreateCompatibleDC(hdc); hbit=CreateCompatibleBitmap(hdc,maxX,maxY); SelectObject(memdc,hbit); SelectObject(memdc,hCurrentBrush); PatBlt(memdc,0,0,maxX,maxY,PATCOPY); SelectObject(memdc,hCurrentPen); ReleaseDC(this->Handle,hdc); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(Button==mbRight){ endpoints=1; StartX=X; StartY=Y; CurX=X; CurY=Y; eX=StartX; eY=StartY; } else if(Button==mbLeft){ pendown=1; StartX=X; StartY=Y; CurX=X; CurY=Y; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(Button==mbRight){ endpoints=0; EndX=X; EndY=Y; } else if(Button==mbLeft){ pendown=0; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { Label1->Caption="(X:" IntToStr(X) "," "Y:" IntToStr(Y) ")"; if(pendown){ hdc=GetDC(this->Handle); SelectObject(hdc,hCurrentPen); MoveToEx(memdc,StartX,StartY,NULL); MoveToEx(hdc,StartX,StartY,NULL); LineTo(memdc,X,Y); LineTo(hdc,X,Y); StartX=X; StartY=Y; ReleaseDC(this->Handle,hdc); } if(endpoints){ hdc=GetDC(this->Handle); hOldPen=(HPEN)SelectObject(hdc,hRedPen); pMode=SetROP2(hdc,R2_NOTXORPEN); hOldBrush=(HBRUSH)SelectObject(hdc,GetStockObject(HOLLOW_BRUSH)); Rectangle(hdc,StartX,StartY,eX,eY); Rectangle(hdc,StartX,StartY,X,Y); SelectObject(hdc,hOldBrush); SelectObject(hdc,hOldPen); SetROP2(hdc,pMode); eX=X; eY=Y; ReleaseDC(this->Handle,hdc); } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { int i; static int j=0; if(wflag){ hdc=BeginPaint(this->Handle,&paintstruct); i=SetGraphicsMode(hdc,GM_ADVANCED); rect=(RECT)GetClientRect(); tf.eM11=5;//(float)cos(theta*3.1416/180); tf.eM12=5;//(float)sin(theta*3.1416/180); tf.eM21=0;//(float)-sin(theta*3.1416/180); tf.eM22=0;//(float)cos(theta*3.1416/180); tf.eDx=(float)rect.right/2; tf.eDy=(float)rect.bottom/2; i=SetWorldTransform(hdc,&tf); i=BitBlt(hdc,-rect.right/2,-rect.bottom/2,rect.right,rect.bottom,memdc,0,0,SRCCOPY); EndPaint(this->Handle,&paintstruct); j ; Label2->Caption="repaint:" IntToStr(j); } wflag=0; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { theta-=30; wflag=1; InvalidateRect(this->Handle,NULL,0); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { theta =30; wflag=1; InvalidateRect(this->Handle,NULL,1); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { wflag=1; InvalidateRect(this->Handle,NULL,1); } //-------------------------------------------------------------------- //--------------------------------------------------------------------//*.h #ifndef Unit1H #define Unit1H //-------------------------------------------------------------------- #include #include #include #include <Forms.hpp> #include #include <math.h> //-------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TLabel *Label1; TButton *Button1; TButton *Button2; TButton *Button3; TLabel *Label2; void __fastcall FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y); void __fastcall FormPaint(TObject *Sender); void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); void __fastcall Button3Click(TObject *Sender); private: // User declarations int StartX,StartY,CurX,CurY,EndX,EndY,eX,eY; int pendown,endpoints; int pMode,theta,wflag; int maxX,maxY; HDC hdc,memdc; HPEN hCurrentPen,hOldPen; HPEN hRedPen,hGreenPen,hBluePen; HBRUSH hOldBrush,hCurrentBrush; HBITMAP hbit; XFORM tf; RECT rect; PAINTSTRUCT paintstruct; public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-25 18:30:17 IP:218.160.xxx.xxx 未訂閱
void __fastcall TForm1::FormPaint(TObject *Sender)
{
rect=(RECT)GetClientRect();
StretchBlt(Canvas->Handle,0,0,rect.right,rect.bottom,memdc,0,0,rect.right,rect.bottom,SRCCOPY);
}
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-29 10:15:17 IP:139.223.xxx.xxx 未訂閱
不好意思,我已經試出來了,謝謝brook你的回應, 我發現原來OnPaint裡的程式原來是要寫在WM_PPAINT 就可以了.... 謝謝各位大大
系統時間:2024-11-23 18:51:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!