2013-08-08 6 views
0

TForm 구성 요소 (테두리, 캡션 ..)에서 마우스 단추를 클릭하는 동안 OpenGL 애니메이션이 중지됩니다. 마우스 버튼을 놓 자마자 애니메이션이 계속 진행됩니다.VCL 구성 요소 (WM_PAINT)로 애니메이션

// Drawing Scene 
void TMainForm::DrawGLScene() 
{ 
    glClearColor(1,1,1,1); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    DrawFigure(); 
    SwapBuffers(hDC); 
} 

// Catching WM_PAINT 
LRESULT CALLBACK NewWindowProcPanel3D(HWND hWnd, UINT msg, WPARAM w, LPARAM l) 
{ 
    switch (msg) 
    { 
     case WM_ERASEBKGND : 
     { 
      return 1; 
     } 
     case WM_PAINT : 
     { 
      MainForm->DrawGLScene(); 
     } 
     default: return CallWindowProc((FARPROC)MainForm->OldWindowProcPanel3D, 
      hWnd, msg, w, l); 
    } 
    return 0; 
} 

// Creating OldWindowProcPanel3D - 
void __fastcall TMainForm::FormCreate(TObject *Sender) 
{ 
    OldWindowProcPanel3D = (WNDPROC)SetWindowLong(Panel3D->Handle, 
     GWL_WNDPROC, (long)NewWindowProcPanel3D); 
} 

// --------- *.h : 
class TMainForm : public TForm 
{ 
    private: 
     HDC hDC; 
    public: 
     WNDPROC OldWindowProcPanel3D; 
} 

// Generation event WM_PAINT 
void TMainForm::UpdateScene() 
{ 
    InvalidateRect(Panel3D->Handle, NULL, false); 
} 

// Animation code (turn on 'animation' if RadioButton is chosen) 
void __fastcall TMainForm::RadioGroupClick(TObject *Sender) 
{ 
    if (RadioGroup->ItemIndex == 0) 
     animation = false; 
    else if (RadioGroup->ItemIndex == 1) 
     animation = true; 
    if (animation) 
    { 
     while (animation) 
     { 
      Application->ProcessMessages(); 
      UpdateScene(); 
     } 
    } 
} 

양식의 크기, 유용한 링크를 변경하는 동안 애니메이션을 중단하지 않으려면 어떻게해야합니까?

답변

0

주 메시지 루프가 차단되고 창을 끌거나 크기를 조정하는 동안 보조 메시지 루프가 실행되기 때문입니다. 메뉴가 활성 상태이거나 모달 대화 상자가 표시 될 때도 똑같은 일이 발생합니다. Windows가 작동하는 방식과 관련하여 수행 할 수있는 작업은 없습니다. Panel3D is a TPanel과 or similar VCL control, you should subclass its WindowProc property instead of SetWindowsLong() , since the 경우 TWinControl :: Handle` 속성을 가정 BTW

은 지속되지 않습니다.

그리고 Application->ProcessMessages()의 사용을 제거해야합니다. 절대로 필요하지 않는 한 직접 전화하지 마십시오.

대신을 시도해보십시오

class TMainForm : public TForm 
{ 
private: 
    HDC hDC; 
    bool animation; 
    TWndMethod OldWindowProcPanel3D; 
    void DrawGLScene(); 
    void __fastcall NewWindowProcPanel3D(TMessage &Message); 
public: 
    __fastcall TMainForm(TComponent *Owner); 
}; 

// Creating OldWindowProcPanel3D - 
__fastcall TMainForm::TMainForm(TComponent *Owner) 
    : TForm(Owner) 
{ 
    OldWindowProcPanel3D = Panel3D->WindowProc; 
    Panel3D->WindowProc = &NewWindowProcPanel3D; 
} 

// Drawing Scene 
void TMainForm::DrawGLScene() 
{ 
    glClearColor(1,1,1,1); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    DrawFigure(); 
    SwapBuffers(hDC); 
} 

// Catching WM_PAINT 
void __fastcall TMainForm::NewWindowProcPanel3D(TMessage &Message) 
{ 
    switch (Message.Msg) 
    { 
     case WM_ERASEBKGND : 
     { 
      Message.Result = 1; 
      break; 
     } 

     case WM_PAINT : 
     { 
      DrawGLScene(); 
      if (animation) 
       UpdateScene(); 
      break; 
     } 

     default: 
     { 
      OldWindowProcPanel3D(Message); 
      break; 
     } 
    } 
} 

// Generation event WM_PAINT 
void TMainForm::UpdateScene() 
{ 
    Panel3D->Invalidate(); 
} 

// Animation code (turn on 'animation' if RadioButton is chosen) 
void __fastcall TMainForm::RadioGroupClick(TObject *Sender) 
{ 
    if (RadioGroup->ItemIndex == 0) 
     animation = false; 
    else if (RadioGroup->ItemIndex == 1) 
     animation = true; 

    if (animation) 
     UpdateScene(); 
}