Here is the code sample, I am not including the CDialog in its full minimal form because it will take too much space, but I can create a minimalistic project and uploaded for anyone who wants to test it.
CDialog:
This is the defined _SFML variable
SFML_CL _SFML
This is the pseudo code of the main CDialog class
BOOL CClassTestsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
FIRSTRESIZE = true;
HWND hWND = GetSafeHwnd();
_SFML.Initialize(hWND);
return TRUE;
}
void CClassTestsDlg::OnSize(UINT nType, int cx, int cy){
if(FIRSTRESIZE){
SetWindowPos(&CWnd::wndTopMost , 0, 0, 500, 500 ,SWP_SHOWWINDOW|SWP_NOZORDER );
FIRSTRESIZE = false;
}
CDialog::OnSize(nType, cx, cy);
}
void CClassTestDlg::ChangeSize()
{
SetWindowPos(&CWnd::wndTopMost ,0,0,700,700,SWP_SHOWWINDOW|SWP_NOZORDER);
}
SFML_CL:
#pragma once
#include <SFML/Graphics.hpp>
class SFML_CL
{
public:
SFML_CL(void);
virtual ~SFML_CL(void);
void Initialize(HWND hWnd);
void Render();
protected:
HWND hWND;
sf::RenderWindow *ttl2D;
sf::Font font;
COLORREF ColorBG;
};
SFML_CL::SFML_CL(void)
{
ttl2D = NULL;
ColorBG = RGB(90,90,90);
}
SFML_CL::~SFML_CL(void)
{
delete ttl2D;
}
void SFML_CL::Initialize(HWND hWnd)
{
hWND = hWnd;
sf::ContextSettings ws;
ws.antialiasingLevel = 8;
ttl2D = new sf::RenderWindow( hWND,ws );
ttl2D->setVerticalSyncEnabled(true);
font.loadFromFile("res/Arial.otf");
}
void SFML_CL::Render()
{
sf::Color color(GetRValue(ColorBG ),GetGValue(ColorBG ),GetBValue(ColorBG ),255);
ttl2D->clear(color);
sf::Text text;
text.setCharacterSize(13);
text.setColor(sf::Color::White);
text.setPosition(20,80);
CRect rect;
GetClientRect(hWND,rect);
CString fp;
fp.Format("%d (%d : %d %d %d %d)",ttl2D->getSize().x,ttl2D->getSize().y,rect.left,rect.top,rect.Width(),rect.Height());
text.setString(fp.GetBuffer());
fp.ReleaseBuffer();
text.setPosition(20,150);
ttl2D->draw(text);
ttl2D->display();
}
This will result in a constant values for ttl2D->getSize().x and ttl2D->getSize().y, but the rect coordinates will be updated accordingly