I'm writing a SFML test application with MFC. The following code runs inside an infinite loop in another thread started by AfxBeginThread() function. (Because I want to use SFML like it's in a pure WinAPI application
)
// SFML Window and View were initialized using CView's HWND
// Use SFML to draw
sf::Color back(255, 255, 0); // a yellow background
_psfwnd->clear(back);
_psfwnd->display();
// Then use MFC GDI functions to draw
CWnd* pwnd;
pwnd = CWnd::FromHandle(_psfwnd->getSystemHandle()); // It seems that the HWND is valid
CPaintDC dc(pwnd);
CRect r(10, 10, 100, 100);
CBrush b(0xFF000000);
dc.FillRect(&r, &b); // draw a black rectangle
The result is a white background with a black rectangle. It seems that SFML draws nothing but MFC does.
Same code above. Now I put it into a MFC command handler (so the above code draws one frame when I click a button once).
This time the window background is yellow and MFC black rectangle is gone.
Now I am quite confused. I have two questions:
Why SFML doesn't draw the first time? It's because of threading, or initialization?
Why MFC doesn't draw when SFML does?