问题是在 TForm 组件(边框、标题 ..)上单击任何鼠标按钮时 OpenGL 动画停止。只要松开鼠标按钮,动画就会继续。
// 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();
}
}
}
在更改表单大小时如何不停止动画,任何有用的链接?