I am trying to create a rendering loop inside a C++/CLI library for a .NET Windows Form application but the PeekMessage never get any messages. So my render loop is infinite and the form appear frozen.
I have tried several way of doing it but here is my last try.
To start the rendering loop :
Application::Idle += gcnew EventHandler(this, &TECore::AppIdleHandler);
Code that handle it :
void TECore::AppIdleHandler(Object^ object, EventArgs^ e)
{
while (IsAppIdle())
RenderLoopCallBack();
}
bool TECore::IsAppIdle()
{
LPMSG msg = {};
return !PeekMessage(msg, (HWND)_targetForm->Handle.ToInt32(), 0, 0, 0);
}
So if I am not doing anything wrong, I am constantly checking for message from my windows handle (also have tried with NULL) otherwise I do render stuff. But the window is frozen because I never get any message, IsAppIdle always return true. I can't focus the windows, resize it or anything..
Thank a lot for help.
EDIT 1 : It's working if I do Application::DoEvent() in each frame. But what's the performance drawback ?
EDIT 2 :
I am now pretty sure that my PeekMessage don't get any message because the RenderLoop is in the class library and not directly in the WindowForm. PeekMessage work fine directly in the form code. Is that a normal behaviors ? Maybe C# when loading a CLI assembly automaticly load it on another thread ? So my PeekMessage is looking on the wrong thread ?